Check for ErrDefault500 when creating/deleting pool member (#12664)

If LBaaSV2 member creation/deletion is attempted while LB resource is
busy (for example it's in PENDING_UPDATE state), Neutron will return 500
error. Currently This being caught by type assertion to
ErrUnexpectedResponseCode, however error 500 has a dedicated type
ErrDefault500, which makes the current type assertion to miss it and
eventually the error slips out through the check. This patch
changes the type assertion to explicitly check for ErrDefault500.

Also similar check has been added when member is deleted.
This commit is contained in:
Karol Stępniewski 2017-03-14 03:45:43 -07:00 committed by Paul Stack
parent 1c7ea5a8af
commit 1fef190b68
1 changed files with 19 additions and 11 deletions

View File

@ -124,15 +124,20 @@ func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Attempting to create LBaaSV2 member")
member, err = pools.CreateMember(networkingClient, poolID, createOpts).Extract()
if err != nil {
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
if errCode.Actual == 409 || errCode.Actual == 500 {
switch errCode := err.(type) {
case gophercloud.ErrDefault500:
log.Printf("[DEBUG] OpenStack LBaaSV2 member is still creating.")
return resource.RetryableError(err)
case gophercloud.ErrUnexpectedResponseCode:
if errCode.Actual == 409 {
log.Printf("[DEBUG] OpenStack LBaaSV2 member is still creating.")
return resource.RetryableError(err)
}
}
return resource.NonRetryableError(err)
}
default:
return resource.NonRetryableError(err)
}
}
return nil
})
@ -271,19 +276,22 @@ func waitForMemberDelete(networkingClient *gophercloud.ServiceClient, poolID str
log.Printf("[DEBUG] Openstack LBaaSV2 Member: %+v", member)
err = pools.DeleteMember(networkingClient, poolID, memberID).ExtractErr()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
switch errCode := err.(type) {
case gophercloud.ErrDefault404:
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Member %s", memberID)
return member, "DELETED", nil
}
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
case gophercloud.ErrDefault500:
log.Printf("[DEBUG] OpenStack LBaaSV2 Member (%s) is still in use.", memberID)
return member, "PENDING_DELETE", nil
case gophercloud.ErrUnexpectedResponseCode:
if errCode.Actual == 409 {
log.Printf("[DEBUG] OpenStack LBaaSV2 Member (%s) is still in use.", memberID)
return member, "PENDING_DELETE", nil
}
}
return member, "ACTIVE", err
default:
return member, "ACTIVE", err
}
}
log.Printf("[DEBUG] OpenStack LBaaSV2 Member %s still active.", memberID)