func waitForMonitorDelete(networkingClient *gophercloud.ServiceClient, monitorID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { log.Printf("[DEBUG] Attempting to delete OpenStack LBaaSV2 Monitor %s", monitorID) monitor, err := monitors.Get(networkingClient, monitorID).Extract() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Monitor %s", monitorID) return monitor, "DELETED", nil } return monitor, "ACTIVE", err } log.Printf("[DEBUG] Openstack LBaaSV2 Monitor: %+v", monitor) err = monitors.Delete(networkingClient, monitorID).ExtractErr() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { 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 } log.Printf("[DEBUG] OpenStack LBaaSV2 Monitor %s still active.", monitorID) return monitor, "ACTIVE", nil } }
func TestDeleteHealthmonitor(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleHealthmonitorDeletionSuccessfully(t) res := monitors.Delete(fake.ServiceClient(), "5d4b5228-33b0-4e60-b225-9b727c1a20e7") th.AssertNoErr(t, res.Err) }
// DeleteMonitor will delete a specified monitor. A fatal error will occur if // the monitor could not be deleted. This works best when used as a deferred // function. func DeleteMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID, monitorID string) { t.Logf("Attempting to delete monitor %s", monitorID) if err := monitors.Delete(client, monitorID).ExtractErr(); err != nil { t.Fatalf("Unable to delete monitor: %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 monitor %s", monitorID) }