func waitForSecGroupDelete(networkingClient *gophercloud.ServiceClient, secGroupId string) resource.StateRefreshFunc { return func() (interface{}, string, error) { log.Printf("[DEBUG] Attempting to delete OpenStack Security Group %s.\n", secGroupId) r, err := groups.Get(networkingClient, secGroupId).Extract() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { log.Printf("[DEBUG] Successfully deleted OpenStack Neutron Security Group %s", secGroupId) return r, "DELETED", nil } return r, "ACTIVE", err } err = groups.Delete(networkingClient, secGroupId).ExtractErr() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { log.Printf("[DEBUG] Successfully deleted OpenStack Neutron Security Group %s", secGroupId) return r, "DELETED", nil } return r, "ACTIVE", err } log.Printf("[DEBUG] OpenStack Neutron Security Group %s still active.\n", secGroupId) return r, "ACTIVE", nil } }
// DeleteSecurityGroup will delete a security group of a specified ID. // A fatal error will occur if the deletion failed. This works best as a // deferred function func DeleteSecurityGroup(t *testing.T, client *gophercloud.ServiceClient, secGroupID string) { t.Logf("Attempting to delete security group: %s", secGroupID) err := groups.Delete(client, secGroupID).ExtractErr() if err != nil { t.Fatalf("Unable to delete security group: %v", err) } }
func TestDelete(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/security-groups/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "DELETE") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) w.WriteHeader(http.StatusNoContent) }) res := groups.Delete(fake.ServiceClient(), "4ec89087-d057-4e2c-911f-60a3b47ee304") th.AssertNoErr(t, res.Err) }