Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vpnaas: Delete service #769

Merged
merged 5 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestServiceCRUD(t *testing.T) {
if err != nil {
t.Fatalf("Unable to create service: %v", err)
}
defer DeleteService(t, client, service.ID)

tools.PrintResource(t, service)
}
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 @@ -30,3 +30,17 @@ func CreateService(t *testing.T, client *gophercloud.ServiceClient, routerID str

return service, nil
}

// DeleteService will delete a service 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 DeleteService(t *testing.T, client *gophercloud.ServiceClient, serviceID string) {
t.Logf("Attempting to delete service: %s", serviceID)

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

t.Logf("Service deleted: %s", serviceID)
}
8 changes: 8 additions & 0 deletions openstack/networking/v2/extensions/vpnaas/services/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ Example to Create a Service
panic(err)
}

Example to Delete a Service

serviceID := "38aee955-6283-4279-b091-8b9c828000ec"
err := policies.Delete(networkClient, serviceID).ExtractErr()
if err != nil {
panic(err)
}

*/
package services
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,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 VPN service based on its
// unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}
6 changes: 6 additions & 0 deletions openstack/networking/v2/extensions/vpnaas/services/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ func (r commonResult) Extract() (*Service, error) {
type CreateResult struct {
commonResult
}

// DeleteResult 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 @@ -75,3 +75,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/vpnservices/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 := services.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828")
th.AssertNoErr(t, res.Err)
}