From 0253dbe51b189740ffe6384769924a7113380d79 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sun, 16 Oct 2016 02:57:41 +0000 Subject: [PATCH] provider/openstack: gophercloud migration: Accounting for 409 errors with LBaaSV2 --- .../resource_openstack_lb_listener_v2.go | 8 +++++++ .../resource_openstack_lb_loadbalancer_v2.go | 22 +++++++++++++------ .../resource_openstack_lb_member_v2.go | 8 +++++++ .../resource_openstack_lb_monitor_v2.go | 8 +++++++ .../resource_openstack_lb_pool_v2.go | 8 +++++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_lb_listener_v2.go b/builtin/providers/openstack/resource_openstack_lb_listener_v2.go index 8f5cb1086b..b7160c4f00 100644 --- a/builtin/providers/openstack/resource_openstack_lb_listener_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_listener_v2.go @@ -299,6 +299,14 @@ func waitForListenerDelete(networkingClient *gophercloud.ServiceClient, listener log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 listener %s", listenerID) return listener, "DELETED", nil } + + if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { + if errCode.Actual == 409 { + log.Printf("[DEBUG] OpenStack LBaaSV2 listener (%s) is still in use.", listenerID) + return listener, "ACTIVE", nil + } + } + return listener, "ACTIVE", err } diff --git a/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go b/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go index 0a756b0e72..0e2fb7dfc0 100644 --- a/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go @@ -138,7 +138,7 @@ func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error return CheckDeleted(d, err, "LoadBalancerV2") } - log.Printf("[DEBUG] Retrieved OpenStack LoadBalancerV2 %s: %+v", d.Id(), lb) + log.Printf("[DEBUG] Retrieved OpenStack LBaaSV2 LoadBalancer %s: %+v", d.Id(), lb) d.Set("name", lb.Name) d.Set("description", lb.Description) @@ -199,7 +199,7 @@ func resourceLoadBalancerV2Delete(d *schema.ResourceData, meta interface{}) erro _, err = stateConf.WaitForState() if err != nil { - return fmt.Errorf("Error deleting OpenStack LB Pool: %s", err) + return fmt.Errorf("Error deleting OpenStack LBaaSV2 LoadBalancer: %s", err) } d.SetId("") @@ -213,7 +213,7 @@ func waitForLoadBalancerActive(networkingClient *gophercloud.ServiceClient, lbID return nil, "", err } - log.Printf("[DEBUG] OpenStack LoadBalancer: %+v", lb) + log.Printf("[DEBUG] OpenStack LBaaSV2 LoadBalancer: %+v", lb) if lb.ProvisioningStatus == "ACTIVE" { return lb, "ACTIVE", nil } @@ -224,12 +224,12 @@ func waitForLoadBalancerActive(networkingClient *gophercloud.ServiceClient, lbID func waitForLoadBalancerDelete(networkingClient *gophercloud.ServiceClient, lbID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - log.Printf("[DEBUG] Attempting to delete OpenStack LoadBalancerV2 %s", lbID) + log.Printf("[DEBUG] Attempting to delete OpenStack LBaaSV2 LoadBalancer %s", lbID) lb, err := loadbalancers.Get(networkingClient, lbID).Extract() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { - log.Printf("[DEBUG] Successfully deleted OpenStack LoadBalancerV2 %s", lbID) + log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 LoadBalancer %s", lbID) return lb, "DELETED", nil } return lb, "ACTIVE", err @@ -239,13 +239,21 @@ func waitForLoadBalancerDelete(networkingClient *gophercloud.ServiceClient, lbID err = loadbalancers.Delete(networkingClient, lbID).ExtractErr() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { - log.Printf("[DEBUG] Successfully deleted OpenStack LoadBalancerV2 %s", lbID) + log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 LoadBalancer %s", lbID) return lb, "DELETED", nil } + + if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { + if errCode.Actual == 409 { + log.Printf("[DEBUG] OpenStack LBaaSV2 LoadBalancer (%s) is still in use.", lbID) + return lb, "ACTIVE", nil + } + } + return lb, "ACTIVE", err } - log.Printf("[DEBUG] OpenStack LoadBalancerV2 %s still active.", lbID) + log.Printf("[DEBUG] OpenStack LBaaSV2 LoadBalancer (%s) still active.", lbID) return lb, "ACTIVE", nil } } diff --git a/builtin/providers/openstack/resource_openstack_lb_member_v2.go b/builtin/providers/openstack/resource_openstack_lb_member_v2.go index a20f519d5f..83c1ac5d1c 100644 --- a/builtin/providers/openstack/resource_openstack_lb_member_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_member_v2.go @@ -257,6 +257,14 @@ func waitForMemberDelete(networkingClient *gophercloud.ServiceClient, poolID str log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Member %s", memberID) return member, "DELETED", nil } + + if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { + if errCode.Actual == 409 { + log.Printf("[DEBUG] OpenStack LBaaSV2 Member (%s) is still in use.", memberID) + return member, "ACTIVE", nil + } + } + return member, "ACTIVE", err } diff --git a/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go b/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go index eadac41bf2..59617fbcc0 100644 --- a/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go @@ -272,6 +272,14 @@ func waitForMonitorDelete(networkingClient *gophercloud.ServiceClient, monitorID log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Monitor %s", monitorID) return monitor, "DELETED", nil } + + if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { + if errCode.Actual == 409 { + log.Printf("[DEBUG] OpenStack LBaaSV2 Monitor (%s) is still in use.", monitorID) + return monitor, "ACTIVE", nil + } + } + return monitor, "ACTIVE", err } diff --git a/builtin/providers/openstack/resource_openstack_lb_pool_v2.go b/builtin/providers/openstack/resource_openstack_lb_pool_v2.go index 471987dcfc..3a297bfc99 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v2.go @@ -305,6 +305,14 @@ func waitForPoolDelete(networkingClient *gophercloud.ServiceClient, poolID strin log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Pool %s", poolID) return pool, "DELETED", nil } + + if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok { + if errCode.Actual == 409 { + log.Printf("[DEBUG] OpenStack LBaaSV2 Pool (%s) is still in use.", poolID) + return pool, "ACTIVE", nil + } + } + return pool, "ACTIVE", err }