Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions pkg/driver/executor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ import (
"fmt"
)

// NoValidHost is a part of the error message returned when there is no valid host in the zone to deploy a VM.
// Matches:
//
// "No valid host was found."
// "No valid host was found. There are not enough hosts available."
const NoValidHost = "No valid host was found"
const (
// NoValidHost is a part of the error message returned when there is no valid host in the zone to deploy a VM.
// Matches:
//
// "No valid host was found."
// "No valid host was found. There are not enough hosts available."
NoValidHost = "No valid host was found"

// FlavorNotFound is part of the error message returned when a flavor cannot be resolved.
// This string-matching fallback is needed because FlavorIDFromName (from executor.go deployServer)
// only wraps the typed ErrFlavorNotFound when the underlying gophercloud error is gophercloud.ErrResourceNotFound.
// If gophercloud returns any other error type, the typed-error path in mapErrorToCode will not match, and
// we fall back to inspecting the error message here so the failure is still classified as codes.ResourceExhausted.
FlavorNotFound = "error resolving flavor"
Comment thread
aaronfern marked this conversation as resolved.
)

var (
// ErrNotFound is returned when the requested resource could not be found.
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func mapErrorToCode(err error) codes.Code {

func mapErrorMessageToCode(err error) codes.Code {
errorMessage := err.Error()
if strings.Contains(errorMessage, executor.NoValidHost) {
if strings.Contains(errorMessage, executor.NoValidHost) || strings.Contains(errorMessage, executor.FlavorNotFound) {
Comment thread
viragvoros marked this conversation as resolved.
return codes.ResourceExhausted
}
return codes.Internal
Expand Down
7 changes: 7 additions & 0 deletions pkg/driver/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@ var _ = Describe("Utils", func() {
Expect(err2).To(HaveOccurred())
Expect(mapErrorToCode(err1)).To(Equal(codes.Internal))
})
It("should map error containing executor.FlavorNotFound to ResourceExhausted error code", func() {
err1 := fmt.Errorf("error: %s", executor.FlavorNotFound)
err2 := status.Error(mapErrorToCode(err1), err1.Error())
Expect(err1).To(HaveOccurred())
Expect(err2).To(HaveOccurred())
Expect(mapErrorToCode(err1)).To(Equal(codes.ResourceExhausted))
})
})
})
Loading