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

loadbalancer additional_vips #2699 #2700

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions acceptance/openstack/loadbalancer/v2/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,18 @@ func CreateListenerHTTP(t *testing.T, client *gophercloud.ServiceClient, lb *loa

// CreateLoadBalancer will create a load balancer with a random name on a given
// subnet. An error will be returned if the loadbalancer could not be created.
func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetID string, tags []string, policyID string) (*loadbalancers.LoadBalancer, error) {
func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetID string, tags []string, policyID string, additionalVips []loadbalancers.AdditionalVip) (*loadbalancers.LoadBalancer, error) {
lbName := tools.RandomString("TESTACCT-", 8)
lbDescription := tools.RandomString("TESTACCT-DESC-", 8)

t.Logf("Attempting to create loadbalancer %s on subnet %s", lbName, subnetID)

createOpts := loadbalancers.CreateOpts{
Name: lbName,
Description: lbDescription,
VipSubnetID: subnetID,
AdminStateUp: gophercloud.Enabled,
Name: lbName,
Description: lbDescription,
VipSubnetID: subnetID,
AdminStateUp: gophercloud.Enabled,
AdditionalVips: additionalVips,
}
if len(tags) > 0 {
createOpts.Tags = tags
Expand Down
21 changes: 16 additions & 5 deletions acceptance/openstack/loadbalancer/v2/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestLoadbalancersListByTags(t *testing.T) {
// Add "test" tag intentionally to test the "not-tags" parameter. Because "test" tag is also used in other test
// cases, we use "test" tag to exclude load balancers created by other test case.
tags := []string{"tag1", "tag2", "test"}
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "")
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "", nil)
th.AssertNoErr(t, err)
defer DeleteLoadBalancer(t, lbClient, lb.ID)

Expand Down Expand Up @@ -111,7 +111,7 @@ func TestLoadbalancerHTTPCRUD(t *testing.T) {
th.AssertNoErr(t, err)
defer networking.DeleteSubnet(t, netClient, subnet.ID)

lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, nil, "")
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, nil, "", nil)
th.AssertNoErr(t, err)
defer DeleteLoadBalancer(t, lbClient, lb.ID)

Expand Down Expand Up @@ -253,18 +253,29 @@ func TestLoadbalancersCRUD(t *testing.T) {
th.AssertNoErr(t, err)
defer networking.DeleteNetwork(t, netClient, network.ID)

subnet, err := networking.CreateSubnet(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.DeleteSubnet(t, netClient, subnet.ID)

additionalSubnet, err := networking.CreateSubnetWithCIDR(t, netClient, network.ID, "192.168.2.0/24", "192.168.2.1")
th.AssertNoErr(t, err)
defer networking.DeleteSubnet(t, netClient, additionalSubnet.ID)

additionalSubnetPort, err := networking.CreatePort(t, netClient, network.ID, additionalSubnet.ID)
th.AssertNoErr(t, err)
defer networking.DeletePort(t, netClient, additionalSubnetPort.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)
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, policy1.ID, []loadbalancers.AdditionalVip{{SubnetID: additionalSubnet.ID, IPAddress: additionalSubnetPort.FixedIPs[0].IPAddress}})
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 Expand Up @@ -463,7 +474,7 @@ func TestLoadbalancersCascadeCRUD(t *testing.T) {
defer networking.DeleteSubnet(t, netClient, subnet.ID)

tags := []string{"test"}
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "")
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "", nil)
th.AssertNoErr(t, err)
defer CascadeDeleteLoadBalancer(t, lbClient, lb.ID)

Expand Down
10 changes: 8 additions & 2 deletions acceptance/openstack/networking/v2/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,17 @@ func CreatePortWithMultipleFixedIPs(t *testing.T, client *gophercloud.ServiceCli
// CreateSubnet will create a subnet on the specified Network ID. An error
// will be returned if the subnet could not be created.
func CreateSubnet(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*subnets.Subnet, error) {
subnetName := tools.RandomString("TESTACC-", 8)
subnetDescription := tools.RandomString("TESTACC-DESC-", 8)
subnetOctet := tools.RandomInt(1, 250)
subnetCIDR := fmt.Sprintf("192.168.%d.0/24", subnetOctet)
subnetGateway := fmt.Sprintf("192.168.%d.1", subnetOctet)
return CreateSubnetWithCIDR(t, client, networkID, subnetCIDR, subnetGateway)
}

// CreateSubnetWithCIDR will create a subnet on the specified Network ID and CIDR. An error
// will be returned if the subnet could not be created.
func CreateSubnetWithCIDR(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetCIDR, subnetGateway string) (*subnets.Subnet, error) {
subnetName := tools.RandomString("TESTACC-", 8)
subnetDescription := tools.RandomString("TESTACC-DESC-", 8)
createOpts := subnets.CreateOpts{
NetworkID: networkID,
CIDR: subnetCIDR,
Expand Down
4 changes: 4 additions & 0 deletions openstack/loadbalancer/v2/loadbalancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ type CreateOpts struct {

// Tags is a set of resource tags.
Tags []string `json:"tags,omitempty"`

// The additional ips of the loadbalancer. Subnets must all belong to the same network as the primary VIP.
// New in version 2.26
AdditionalVips []AdditionalVip `json:"additional_vips,omitempty"`
}

// ToLoadBalancerCreateMap builds a request body from CreateOpts.
Expand Down
10 changes: 10 additions & 0 deletions openstack/loadbalancer/v2/loadbalancers/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ type LoadBalancer struct {
// Tags is a list of resource tags. Tags are arbitrarily defined strings
// attached to the resource.
Tags []string `json:"tags"`

// The additional ips of the loadbalancer. Subnets must all belong to the same network as the primary VIP.
// New in version 2.26
AdditionalVips []AdditionalVip `json:"additional_vips"`
}

// AdditionalVip represent additional ip of a loadbalancer. IpAddress field is optional.
type AdditionalVip struct {
SubnetID string `json:"subnet_id"`
IPAddress string `json:"ip_address,omitempty"`
}

func (r *LoadBalancer) UnmarshalJSON(b []byte) error {
Expand Down
18 changes: 13 additions & 5 deletions openstack/loadbalancer/v2/loadbalancers/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
const LoadbalancersListBody = `
{
"loadbalancers":[
{
{
"id": "c331058c-6a40-4144-948e-b9fb1df9db4b",
"project_id": "54030507-44f7-473c-9342-b4d14a95f692",
"created_at": "2019-06-30T04:15:37",
Expand Down Expand Up @@ -52,7 +52,8 @@ const LoadbalancersListBody = `
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE",
"tags": ["test", "stage"]
"tags": ["test", "stage"],
"additional_vips": [{"subnet_id": "0d4f6a08-60b7-44ab-8903-f7d76ec54095", "ip_address" : "192.168.10.10"}]
}
]
}
Expand All @@ -77,7 +78,8 @@ const SingleLoadbalancerBody = `
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE",
"tags": ["test", "stage"]
"tags": ["test", "stage"],
"additional_vips": [{"subnet_id": "0d4f6a08-60b7-44ab-8903-f7d76ec54095", "ip_address" : "192.168.10.10"}]
}
}
`
Expand Down Expand Up @@ -287,7 +289,12 @@ var (
ProvisioningStatus: "PENDING_CREATE",
OperatingStatus: "OFFLINE",
Tags: []string{"test", "stage"},
}
AdditionalVips: []loadbalancers.AdditionalVip{
{
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 Expand Up @@ -540,7 +547,8 @@ func HandleLoadbalancerCreationSuccessfully(t *testing.T, response string) {
"flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4",
"provider": "haproxy",
"admin_state_up": true,
"tags": ["test", "stage"]
"tags": ["test", "stage"],
"additional_vips": [{"subnet_id": "0d4f6a08-60b7-44ab-8903-f7d76ec54095", "ip_address" : "192.168.10.10"}]
}
}`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func TestCreateLoadbalancer(t *testing.T) {
FlavorID: "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4",
Provider: "haproxy",
Tags: []string{"test", "stage"},
AdditionalVips: []loadbalancers.AdditionalVip{
{
SubnetID: "0d4f6a08-60b7-44ab-8903-f7d76ec54095",
IPAddress: "192.168.10.10",
},
},
}).Extract()
th.AssertNoErr(t, err)

Expand Down