Skip to content

Commit

Permalink
Vpnaas: Delete IPSec policy (#775)
Browse files Browse the repository at this point in the history
* Added delete unit test

* Added delete function and result

* Added comment to delete result

* Added documentation and acceptance tests
  • Loading branch information
simonre authored and jtopjian committed Feb 24, 2018
1 parent 44ab6a0 commit 47e78c6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestPolicyCRUD(t *testing.T) {
if err != nil {
t.Fatalf("Unable to create policy: %v", err)
}
defer DeleteIPSecPolicy(t, client, policy.ID)

tools.PrintResource(t, policy)
}
14 changes: 14 additions & 0 deletions acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ func CreateIPSecPolicy(t *testing.T, client *gophercloud.ServiceClient) (*ipsecp

return policy, nil
}

// DeleteIPSecPolicy will delete an IPSec policy with a specified ID. A fatal error will
// occur if the delete was not successful. This works best when used as a
// deferred function.
func DeleteIPSecPolicy(t *testing.T, client *gophercloud.ServiceClient, policyID string) {
t.Logf("Attempting to delete policy: %s", policyID)

err := ipsecpolicies.Delete(client, policyID).ExtractErr()
if err != nil {
t.Fatalf("Unable to delete policy %s: %v", policyID, err)
}

t.Logf("Deleted policy: %s", policyID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ Example to Create a Policy
if err != nil {
panic(err)
}
Example to Delete a Policy
err := ipsecpolicies.Delete(client, "5291b189-fd84-46e5-84bd-78f40c05d69c").ExtractErr()
if err != nil {
panic(err)
}
*/
package ipsecpolicies
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResul
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}

// Delete will permanently delete a particular IPSec policy based on its
// unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ func (r commonResult) Extract() (*Policy, error) {
type CreateResult struct {
commonResult
}

// CreateResult represents the result of a delete operation. Call its ExtractErr method
// to determine if the operation succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,17 @@ func TestCreate(t *testing.T) {
}
th.AssertDeepEquals(t, expected, *actual)
}

func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

th.Mux.HandleFunc("/v2.0/vpn/ipsecpolicies/5c561d9d-eaea-45f6-ae3e-08d1a7080828", 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 := ipsecpolicies.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828")
th.AssertNoErr(t, res.Err)
}

0 comments on commit 47e78c6

Please sign in to comment.