From eeda2a27a071adea43218807336435475d0197aa Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 16 Jan 2024 15:08:47 -0500 Subject: [PATCH] gofumpt & fix e2e The additional VIPs should not be created before the load balancer, Octavia already takes care of creating the port for us. Also, this feature is only available in Zed and beyond. --- .../loadbalancer/v2/loadbalancers_test.go | 46 +++++++++++++------ .../openstack/networking/v2/networking.go | 2 +- .../v2/loadbalancers/testing/fixtures_test.go | 9 ++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/internal/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go b/internal/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go index c262b7d026..9d33c74576 100644 --- a/internal/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go +++ b/internal/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go @@ -245,15 +245,11 @@ func TestLoadbalancerHTTPCRUD(t *testing.T) { defer DeleteMonitor(t, lbClient, lb.ID, monitor.ID) } -func TestLoadbalancersCRUD(t *testing.T) { - netClient, err := clients.NewNetworkV2Client() - th.AssertNoErr(t, err) +func TestLoadBalancerWithAdditionalVips(t *testing.T) { + clients.SkipReleasesBelow(t, "stable/zed") - // Create QoS policy first as the loadbalancer and its port - //needs to be deleted before the QoS policy can be deleted - policy2, err := policies.CreateQoSPolicy(t, netClient) + netClient, err := clients.NewNetworkV2Client() th.AssertNoErr(t, err) - defer policies.DeleteQoSPolicy(t, netClient, policy2.ID) lbClient, err := clients.NewLoadBalancerV2Client() th.AssertNoErr(t, err) @@ -270,21 +266,45 @@ func TestLoadbalancersCRUD(t *testing.T) { th.AssertNoErr(t, err) defer networking.DeleteSubnet(t, netClient, additionalSubnet.ID) - additionalSubnetPort, err := networking.CreatePort(t, netClient, network.ID, additionalSubnet.ID) + tags := []string{"test"} + // Octavia takes care of creating the port for the loadbalancer + additionalSubnetIP := "192.168.2.207" + lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "", []loadbalancers.AdditionalVip{{SubnetID: additionalSubnet.ID, IPAddress: additionalSubnetIP}}) + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, len(lb.AdditionalVips)) + th.AssertEquals(t, additionalSubnetIP, lb.AdditionalVips[0].IPAddress) + defer DeleteLoadBalancer(t, lbClient, lb.ID) +} + +func TestLoadbalancersCRUD(t *testing.T) { + netClient, err := clients.NewNetworkV2Client() + th.AssertNoErr(t, err) + + // Create QoS policy first as the loadbalancer and its port + // needs to be deleted before the QoS policy can be deleted + policy2, err := policies.CreateQoSPolicy(t, netClient) + th.AssertNoErr(t, err) + defer policies.DeleteQoSPolicy(t, netClient, policy2.ID) + + lbClient, err := clients.NewLoadBalancerV2Client() + th.AssertNoErr(t, err) + + network, err := networking.CreateNetwork(t, netClient) + th.AssertNoErr(t, err) + defer networking.DeleteNetwork(t, netClient, network.ID) + + subnet, err := networking.CreateSubnetWithCIDR(t, netClient, network.ID, "192.168.1.0/24", "192.168.1.1") th.AssertNoErr(t, err) - defer networking.DeletePort(t, netClient, additionalSubnetPort.ID) + defer networking.DeleteSubnet(t, netClient, subnet.ID) policy1, err := policies.CreateQoSPolicy(t, netClient) th.AssertNoErr(t, err) defer policies.DeleteQoSPolicy(t, netClient, policy1.ID) tags := []string{"test"} - lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, policy1.ID, []loadbalancers.AdditionalVip{{SubnetID: additionalSubnet.ID, IPAddress: additionalSubnetPort.FixedIPs[0].IPAddress}}) + lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, policy1.ID, nil) th.AssertNoErr(t, err) th.AssertEquals(t, lb.VipQosPolicyID, policy1.ID) - th.AssertEquals(t, 1, len(lb.AdditionalVips)) - th.AssertEquals(t, additionalSubnetPort.FixedIPs[0].IPAddress, lb.AdditionalVips[0].IPAddress) - th.AssertEquals(t, additionalSubnetPort.FixedIPs[0].SubnetID, lb.AdditionalVips[0].SubnetID) defer DeleteLoadBalancer(t, lbClient, lb.ID) lbDescription := "" diff --git a/internal/acceptance/openstack/networking/v2/networking.go b/internal/acceptance/openstack/networking/v2/networking.go index 666e1b549a..2d3ce57e27 100644 --- a/internal/acceptance/openstack/networking/v2/networking.go +++ b/internal/acceptance/openstack/networking/v2/networking.go @@ -394,7 +394,7 @@ func CreateSubnetWithDefaultGateway(t *testing.T, client *gophercloud.ServiceCli // specified Network ID. An error will be returned if the subnet could not be // created. func CreateSubnetWithNoGateway(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*subnets.Subnet, error) { - var noGateway = "" + noGateway := "" subnetName := tools.RandomString("TESTACC-", 8) subnetOctet := tools.RandomInt(1, 250) subnetCIDR := fmt.Sprintf("192.168.%d.0/24", subnetOctet) diff --git a/openstack/loadbalancer/v2/loadbalancers/testing/fixtures_test.go b/openstack/loadbalancer/v2/loadbalancers/testing/fixtures_test.go index cffe5e3488..948ed4ef61 100644 --- a/openstack/loadbalancer/v2/loadbalancers/testing/fixtures_test.go +++ b/openstack/loadbalancer/v2/loadbalancers/testing/fixtures_test.go @@ -251,8 +251,10 @@ const GetLoadbalancerStatsBody = ` } ` -var createdTime, _ = time.Parse(time.RFC3339, "2019-06-30T04:15:37Z") -var updatedTime, _ = time.Parse(time.RFC3339, "2019-06-30T05:18:49Z") +var ( + createdTime, _ = time.Parse(time.RFC3339, "2019-06-30T04:15:37Z") + updatedTime, _ = time.Parse(time.RFC3339, "2019-06-30T05:18:49Z") +) var ( LoadbalancerWeb = loadbalancers.LoadBalancer{ @@ -294,7 +296,8 @@ var ( SubnetID: "0d4f6a08-60b7-44ab-8903-f7d76ec54095", IPAddress: "192.168.10.10", }, - }} + }, + } LoadbalancerUpdated = loadbalancers.LoadBalancer{ ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab", ProjectID: "54030507-44f7-473c-9342-b4d14a95f692",