Skip to content

Commit

Permalink
[Refactor] VPCEP services and endpoints (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-sidelnikov authored Dec 11, 2024
1 parent 3b0fb91 commit 8e0297a
Show file tree
Hide file tree
Showing 24 changed files with 897 additions and 595 deletions.
48 changes: 27 additions & 21 deletions acceptance/openstack/vpcep/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

func createService(t *testing.T, client *golangsdk.ServiceClient, elbPortID string) string {
iFalse := false
createOpts := &services.CreateOpts{
createOpts := services.CreateOpts{
PortID: elbPortID,
ServiceName: tools.RandomString("svc-", 5),
RouterID: routerID,
VpcId: routerID,
ServerType: services.ServerTypeLB,
ServiceType: services.ServiceTypeInterface,
Ports: []services.PortMapping{
Expand All @@ -29,49 +29,51 @@ func createService(t *testing.T, client *golangsdk.ServiceClient, elbPortID stri
},
ApprovalEnabled: &iFalse,
}
svc, err := services.Create(client, createOpts).Extract()
svc, err := services.Create(client, createOpts)
th.AssertNoErr(t, err)

err = services.WaitForServiceStatus(client, svc.ID, services.StatusAvailable, 30)
th.AssertNoErr(t, err)
return svc.ID
}

func deleteService(t *testing.T, client *golangsdk.ServiceClient, id string) {
th.AssertNoErr(t, services.Delete(client, id).ExtractErr())
}

func TestEndpointLifecycle(t *testing.T) {
if routerID == "" || networkID == "" || subnetID == "" {
t.Skip("OS_ROUTER_ID/VPC_ID, OS_SUBNET_ID and OS_NETWORK_ID variables need to be set")
}

t.Parallel()

client, err := clients.NewVPCEndpointV1Client()
th.AssertNoErr(t, err)

elb := createELB(t)
defer deleteELB(t, elb.ID)

t.Logf("Attempting to CREATE VPCEP service with port: %s", elb.VipPortID)
srvID := createService(t, client, elb.VipPortID)
defer deleteService(t, client, srvID)
t.Cleanup(func() {
t.Logf("Attempting to DELETE VPCEP Service: %s", srvID)
th.AssertNoErr(t, services.Delete(client, srvID))
th.AssertNoErr(t, services.WaitForServiceStatus(client, srvID, services.StatusDeleted, 30))
})

t.Logf("Attempting to CREATE VPCEP Endpoint for service: %s", srvID)
opts := endpoints.CreateOpts{
NetworkID: networkID,
ServiceID: srvID,
RouterID: routerID,
VpcId: routerID,
EnableDNS: true,
PortIP: openstack.ValidIP(t, networkID),
Tags: []tags.ResourceTag{{Key: "fizz", Value: "buzz"}},
}
created, err := endpoints.Create(client, opts).Extract()
created, err := endpoints.Create(client, opts)
th.AssertNoErr(t, err)
th.AssertEquals(t, endpoints.StatusCreating, created.Status)

defer func() {
th.AssertNoErr(t, endpoints.Delete(client, created.ID).ExtractErr())
}()
t.Cleanup(func() {
t.Logf("Attempting to DELETE VPCEP Endpoint: %s", created.ID)
th.AssertNoErr(t, endpoints.Delete(client, created.ID))
th.AssertNoErr(t, endpoints.WaitForEndpointStatus(client, created.ID, "", 30))
})

th.AssertNoErr(t, endpoints.WaitForEndpointStatus(client, created.ID, endpoints.StatusAccepted, 30))

Expand All @@ -81,24 +83,28 @@ func TestEndpointLifecycle(t *testing.T) {
},
Action: "add",
}

t.Logf("Attempting to UPDATE VPCEP Endpoint whitelists: %s", created.ServiceID)
whiteList, err := endpoints.BatchUpdateWhitelist(client, created.ServiceID, batchUpdate)
th.AssertNoErr(t, err)
th.AssertEquals(t, whiteList.Permissions[0], batchUpdate.Permissions[0])

t.Logf("Attempting to OBTAIN VPCEP Endpoint whitelists: %s", created.ServiceID)
getWhitelist, err := endpoints.GetWhitelist(client, created.ServiceID)
th.AssertNoErr(t, err)
th.AssertEquals(t, getWhitelist.Permissions[0].Permission, batchUpdate.Permissions[0])

got, err := endpoints.Get(client, created.ID).Extract()
t.Logf("Attempting to OBTAIN VPCEP Endpoint: %s", created.ID)
got, err := endpoints.Get(client, created.ID)
th.AssertNoErr(t, err)
th.AssertEquals(t, opts.PortIP, got.IP)

pages, err := endpoints.List(client, nil).AllPages()
t.Log("Attempting to LIST VPCEP Endpoints")
eps, err := endpoints.List(client, endpoints.ListOpts{})
th.AssertNoErr(t, err)
th.AssertEquals(t, created.ID, eps[0].ID)

eps, err := endpoints.ExtractEndpoints(pages)
t.Log("Attempting to OBTAIN basic VPCEP Endpoint service information")
info, err := services.GetBasicInfo(client, services.BasicOpts{Name: "com.t-systems.otc.eu-de.apig"})
th.AssertNoErr(t, err)

th.AssertEquals(t, created.ID, eps[0].ID)
th.AssertEquals(t, "interface", info.ServiceType)
}
95 changes: 75 additions & 20 deletions acceptance/openstack/vpcep/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/vpcep/v1/endpoints"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/vpcep/v1/quota"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/vpcep/v1/services"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)
Expand All @@ -20,6 +24,7 @@ var (
func createELB(t *testing.T) *loadbalancers.LoadBalancer {
client, err := clients.NewElbV2Client()
th.AssertNoErr(t, err)
t.Log("Attempting to CREATE ELB for service")
lb, err := loadbalancers.Create(client, loadbalancers.CreateOpts{
Name: tools.RandomString("svc-lb-", 5),
VipSubnetID: subnetID,
Expand All @@ -31,6 +36,7 @@ func createELB(t *testing.T) *loadbalancers.LoadBalancer {
func deleteELB(t *testing.T, id string) {
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)
t.Logf("Attempting to DELETE ELB instance: %s", id)
th.AssertNoErr(t, loadbalancers.Delete(client, id).ExtractErr())
}

Expand All @@ -39,18 +45,24 @@ func TestListPublicServices(t *testing.T) {

client, err := clients.NewVPCEndpointV1Client()
th.AssertNoErr(t, err)

pages, err := services.ListPublic(client, nil).AllPages()
th.AssertNoErr(t, err)

public, err := services.ExtractPublicServices(pages)
t.Log("Attempting to LIST Public services")
public, err := services.ListPublic(client, services.ListPublicOpts{})
th.AssertNoErr(t, err)
if len(public) == 0 {
t.Fatal("Empty public service list")
}
th.AssertEquals(t, "OTC", public[0].Owner)
}

func TestGetQuota(t *testing.T) {
client, err := clients.NewVPCEndpointV1Client()
th.AssertNoErr(t, err)
t.Log("Attempting to Get VPCEP endpoint_service quota")
q, err := quota.Get(client, "endpoint_service")
th.AssertNoErr(t, err)
th.AssertEquals(t, "endpoint_service", q.Quotas.Resources[0].Type)
}

func TestServicesWorkflow(t *testing.T) {
if routerID == "" || networkID == "" || subnetID == "" {
t.Skip("OS_ROUTER_ID/VPC_ID, OS_SUBNET_ID and OS_NETWORK_ID variables need to be set")
Expand All @@ -64,10 +76,10 @@ func TestServicesWorkflow(t *testing.T) {
elb := createELB(t)
defer deleteELB(t, elb.ID)

createOpts := &services.CreateOpts{
createOpts := services.CreateOpts{
PortID: elb.VipPortID,
ServiceName: tools.RandomString("svc-", 5),
RouterID: routerID,
VpcId: routerID,
ServerType: services.ServerTypeLB,
ServiceType: services.ServiceTypeInterface,
Ports: []services.PortMapping{
Expand All @@ -77,29 +89,29 @@ func TestServicesWorkflow(t *testing.T) {
},
},
}
svc, err := services.Create(client, createOpts).Extract()
t.Log("Attempting to CREATE VPCEP service")
svc, err := services.Create(client, createOpts)
th.AssertNoErr(t, err)

err = services.WaitForServiceStatus(client, svc.ID, services.StatusAvailable, 30)
th.AssertNoErr(t, err)

defer func() {
err := services.Delete(client, svc.ID).ExtractErr()
th.AssertNoErr(t, err)
t.Cleanup(func() {
t.Logf("Attempting to DELETE VPCEP Endpoint service: %s", svc.ID)
th.AssertNoErr(t, services.Delete(client, svc.ID))
th.AssertNoErr(t, services.WaitForServiceStatus(client, svc.ID, services.StatusDeleted, 30))
}()
})

pages, err := services.List(client, &services.ListOpts{
t.Log("Attempting to LIST VPCEP Endpoint services")
svcs, err := services.List(client, services.ListOpts{
ID: svc.ID,
}).AllPages()
th.AssertNoErr(t, err)

svcs, err := services.ExtractServices(pages)
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, len(svcs))
th.AssertEquals(t, svc.ID, svcs[0].ID)

got, err := services.Get(client, svc.ID).Extract()
t.Logf("Attempting to OBTAIN VPCEP Endpoint service: %s", svc.ID)
got, err := services.Get(client, svc.ID)
th.AssertNoErr(t, err)

th.AssertEquals(t, svc.VIPPortID, got.VIPPortID)
Expand All @@ -112,8 +124,51 @@ func TestServicesWorkflow(t *testing.T) {
ApprovalEnabled: &iFalse,
ServiceName: tools.RandomString("edited-", 5),
}
updated, err := services.Update(client, svc.ID, uOpts).Extract()
t.Logf("Attempting to UPDATE VPCEP Endpoint service: %s", svc.ID)
updated, err := services.Update(client, svc.ID, uOpts)
th.AssertNoErr(t, err)

th.AssertEquals(t, fmt.Sprintf("%s.%s.%s", client.RegionID, uOpts.ServiceName, svc.ID), updated.ServiceName)

t.Logf("Attempting to CREATE VPCEP Endpoint for service: %s", svc.ID)
opts := endpoints.CreateOpts{
NetworkID: networkID,
ServiceID: svc.ID,
VpcId: routerID,
EnableDNS: true,
PortIP: openstack.ValidIP(t, networkID),
Tags: []tags.ResourceTag{{Key: "fizz", Value: "buzz"}},
}
ep, err := endpoints.Create(client, opts)
th.AssertNoErr(t, err)
th.AssertEquals(t, endpoints.StatusCreating, ep.Status)
th.AssertNoErr(t, endpoints.WaitForEndpointStatus(client, ep.ID, endpoints.StatusAccepted, 30))

t.Cleanup(func() {
t.Logf("Attempting to DELETE VPCEP Endpoint: %s", ep.ID)
th.AssertNoErr(t, endpoints.Delete(client, ep.ID))
th.AssertNoErr(t, endpoints.WaitForEndpointStatus(client, ep.ID, "", 30))
})

t.Logf("Attempting to ACCEPT VPCEP Endpoint to service: %s", ep.ID)
aOpts := services.ActionOpts{
Action: "receive",
Endpoints: []string{ep.ID},
}
c, err := services.Action(client, svc.ID, aOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, "accepted", c[0].Status)

t.Logf("Attempting to OBTAIN VPCEP Endpoint service connections: %s", svc.ID)
connections, err := services.ListConnections(client, svc.ID, services.ListConnectionsOpts{})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, len(connections))

t.Logf("Attempting to REJECT VPCEP Endpoint to service: %s", ep.ID)
rejectOpts := services.ActionOpts{
Action: "reject",
Endpoints: []string{ep.ID},
}
rej, err := services.Action(client, svc.ID, rejectOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, "rejected", rej[0].Status)
}
Loading

0 comments on commit 8e0297a

Please sign in to comment.