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 IPSec site connection #812

Merged
merged 1 commit into from
Mar 9, 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 @@ -24,17 +24,20 @@ func TestConnectionCRUD(t *testing.T) {
if err != nil {
t.Fatalf("Unable to create network: %v", err)
}
defer networks.DeleteNetwork(t, client, network.ID)

// Create Subnet
subnet, err := networks.CreateSubnet(t, client, network.ID)
if err != nil {
t.Fatalf("Unable to create subnet: %v", err)
}
defer networks.DeleteSubnet(t, client, subnet.ID)

router, err := layer3.CreateExternalRouter(t, client)
if err != nil {
t.Fatalf("Unable to create router: %v", err)
}
defer layer3.DeleteRouter(t, client, router.ID)

// Link router and subnet
aiOpts := routers.AddInterfaceOpts{
Expand All @@ -45,37 +48,49 @@ func TestConnectionCRUD(t *testing.T) {
if err != nil {
t.Fatalf("Failed to add interface to router: %v", err)
}
defer func() {
riOpts := routers.RemoveInterfaceOpts{
SubnetID: subnet.ID,
}
routers.RemoveInterface(client, router.ID, riOpts)
}()

// Create all needed resources for the connection
service, err := CreateService(t, client, router.ID)
if err != nil {
t.Fatalf("Unable to create service: %v", err)
}
defer DeleteService(t, client, service.ID)

ikepolicy, err := CreateIKEPolicy(t, client)
if err != nil {
t.Fatalf("Unable to create IKE policy: %v", err)
}
defer DeleteIKEPolicy(t, client, ikepolicy.ID)

ipsecpolicy, err := CreateIPSecPolicy(t, client)
if err != nil {
t.Fatalf("Unable to create IPSec Policy: %v", err)
}
defer DeleteIPSecPolicy(t, client, ipsecpolicy.ID)

peerEPGroup, err := CreateEndpointGroup(t, client)
if err != nil {
t.Fatalf("Unable to create Endpoint Group with CIDR endpoints: %v", err)
}
defer DeleteEndpointGroup(t, client, peerEPGroup.ID)

localEPGroup, err := CreateEndpointGroupWithSubnet(t, client, subnet.ID)
if err != nil {
t.Fatalf("Unable to create Endpoint Group with subnet endpoints: %v", err)
}
defer DeleteEndpointGroup(t, client, localEPGroup.ID)

conn, err := CreateSiteConnection(t, client, ikepolicy.ID, ipsecpolicy.ID, service.ID, peerEPGroup.ID, localEPGroup.ID)
if err != nil {
t.Fatalf("Unable to create IPSec Site Connection: %v", err)
}
defer DeleteSiteConnection(t, client, conn.ID)

tools.PrintResource(t, conn)

Expand Down
15 changes: 15 additions & 0 deletions acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,18 @@ func CreateSiteConnection(t *testing.T, client *gophercloud.ServiceClient, ikepo

return connection, nil
}

// DeleteSiteConnection will delete an IPSec site connection 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 DeleteSiteConnection(t *testing.T, client *gophercloud.ServiceClient, siteConnectionID string) {
t.Logf("Attempting to delete site connection: %s", siteConnectionID)

err := siteconnections.Delete(client, siteConnectionID).ExtractErr()
if err != nil {
t.Fatalf("Unable to delete site connection %s: %v", siteConnectionID, err)
}

t.Logf("Deleted site connection: %s", siteConnectionID)

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,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 site connection 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 @@ -105,3 +105,9 @@ func (r commonResult) Extract() (*Connection, 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 @@ -122,3 +122,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/ipsec-site-connections/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 := siteconnections.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828")
th.AssertNoErr(t, res.Err)
}