func waitForPoolDelete(networkingClient *gophercloud.ServiceClient, poolID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { log.Printf("[DEBUG] Attempting to delete OpenStack LBaaSV2 Pool %s", poolID) pool, err := pools.Get(networkingClient, poolID).Extract() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Pool %s", poolID) return pool, "DELETED", nil } return pool, "ACTIVE", err } log.Printf("[DEBUG] Openstack LBaaSV2 Pool: %+v", pool) err = pools.Delete(networkingClient, poolID).ExtractErr() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { 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 } log.Printf("[DEBUG] OpenStack LBaaSV2 Pool %s still active.", poolID) return pool, "ACTIVE", nil } }
func TestDeletePool(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandlePoolDeletionSuccessfully(t) res := pools.Delete(fake.ServiceClient(), "c3741b06-df4d-4715-b142-276b6bce75ab") th.AssertNoErr(t, res.Err) }
// DeletePool will delete a specified pool. A fatal error will occur if the // pool could not be deleted. This works best when used as a deferred function. func DeletePool(t *testing.T, client *gophercloud.ServiceClient, lbID, poolID string) { t.Logf("Attempting to delete pool %s", poolID) if err := pools.Delete(client, poolID).ExtractErr(); err != nil { t.Fatalf("Unable to delete pool: %v", err) } if err := WaitForLoadBalancerState(client, lbID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { t.Fatalf("Timed out waiting for loadbalancer to become active") } t.Logf("Successfully deleted pool %s", poolID) }