builder/openstack: proper error extraction
This commit is contained in:
parent
7a46b80cfb
commit
46f518f21d
|
@ -36,20 +36,15 @@ type StateChangeConf struct {
|
||||||
func ServerStateRefreshFunc(
|
func ServerStateRefreshFunc(
|
||||||
client *gophercloud.ServiceClient, s *servers.Server) StateRefreshFunc {
|
client *gophercloud.ServiceClient, s *servers.Server) StateRefreshFunc {
|
||||||
return func() (interface{}, string, int, error) {
|
return func() (interface{}, string, int, error) {
|
||||||
var serverNew *servers.Server
|
serverNew, err := servers.Get(client, s.ID).Extract()
|
||||||
result := servers.Get(client, s.ID)
|
if err != nil {
|
||||||
err := result.Err
|
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||||
if err == nil {
|
|
||||||
serverNew, err = result.Extract()
|
|
||||||
}
|
|
||||||
if result.Err != nil {
|
|
||||||
errCode, ok := result.Err.(*gophercloud.UnexpectedResponseCodeError)
|
|
||||||
if ok && errCode.Actual == 404 {
|
if ok && errCode.Actual == 404 {
|
||||||
log.Printf("[INFO] 404 on ServerStateRefresh, returning DELETED")
|
log.Printf("[INFO] 404 on ServerStateRefresh, returning DELETED")
|
||||||
return nil, "DELETED", 0, nil
|
return nil, "DELETED", 0, nil
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[ERROR] Error on ServerStateRefresh: %s", result.Err)
|
log.Printf("[ERROR] Error on ServerStateRefresh: %s", err)
|
||||||
return nil, "", 0, result.Err
|
return nil, "", 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,13 +62,15 @@ func (s *stepCreateImage) Cleanup(multistep.StateBag) {
|
||||||
// WaitForImage waits for the given Image ID to become ready.
|
// WaitForImage waits for the given Image ID to become ready.
|
||||||
func WaitForImage(client *gophercloud.ServiceClient, imageId string) error {
|
func WaitForImage(client *gophercloud.ServiceClient, imageId string) error {
|
||||||
for {
|
for {
|
||||||
var image *images.Image
|
image, err := images.Get(client, imageId).Extract()
|
||||||
result := images.Get(client, imageId)
|
|
||||||
err := result.Err
|
|
||||||
if err == nil {
|
|
||||||
image, err = result.Extract()
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||||
|
if ok && errCode.Actual == 500 {
|
||||||
|
log.Printf("[ERROR] 500 error received, will ignore and retry: %s", err)
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue