Skip to content

Commit

Permalink
gofumpt & fix e2e
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EmilienM committed Jan 17, 2024
1 parent b25d38a commit eeda2a2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
46 changes: 33 additions & 13 deletions internal/acceptance/openstack/loadbalancer/v2/loadbalancers_test.go
Expand Up @@ -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)
Expand All @@ -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 := ""
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/openstack/networking/v2/networking.go
Expand Up @@ -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)
Expand Down
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit eeda2a2

Please sign in to comment.