Skip to content

Commit

Permalink
Check for ErrDefault500 when creating/deleting pool member (#12664)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kars7e authored and stack72 committed Mar 14, 2017
1 parent 1c7ea5a commit 1fef190
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions builtin/providers/openstack/resource_openstack_lb_member_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

default:
return resource.NonRetryableError(err)
}
return resource.NonRetryableError(err)
}

return nil
})

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1fef190

Please sign in to comment.