Skip to content

Commit 9e21d13

Browse files
committed
Add VipQosPolicyID to loadbalancer Create and Update
VipQosPolicyID can be defined for loadbalancers during creation and update. Moreover add the `neutron-qos` service to loadbalancer workflow. [Docs](https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=create-a-load-balancer-detail,update-a-load-balancer-detail#create-a-load-balancer)
1 parent 400038a commit 9e21d13

5 files changed

Lines changed: 38 additions & 7 deletions

File tree

.github/workflows/functional-loadbalancer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
conf_overrides: |
4545
enable_plugin octavia https://opendev.org/openstack/octavia ${{ matrix.openstack_version }}
4646
enable_plugin neutron https://opendev.org/openstack/neutron ${{ matrix.openstack_version }}
47-
enabled_services: 'octavia,o-api,o-cw,o-hk,o-hm,o-da'
47+
enabled_services: 'octavia,o-api,o-cw,o-hk,o-hm,o-da,neutron-qos'
4848
- name: Checkout go
4949
uses: actions/setup-go@v3
5050
with:

acceptance/openstack/loadbalancer/v2/loadbalancer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func CreateListenerHTTP(t *testing.T, client *gophercloud.ServiceClient, lb *loa
110110

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

@@ -126,6 +126,10 @@ func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetI
126126
createOpts.Tags = tags
127127
}
128128

129+
if len(policyID) > 0 {
130+
createOpts.VipQosPolicyID = policyID
131+
}
132+
129133
lb, err := loadbalancers.Create(client, createOpts).Extract()
130134
if err != nil {
131135
return lb, err
@@ -149,6 +153,10 @@ func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetI
149153
th.AssertDeepEquals(t, lb.Tags, tags)
150154
}
151155

156+
if len(policyID) > 0 {
157+
th.AssertEquals(t, lb.VipQosPolicyID, policyID)
158+
}
159+
152160
return lb, nil
153161
}
154162

acceptance/openstack/loadbalancer/v2/loadbalancers_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/gophercloud/gophercloud/acceptance/clients"
1010
networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2"
11+
"github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/qos/policies"
1112
"github.com/gophercloud/gophercloud/acceptance/tools"
1213
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies"
1314
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners"
@@ -50,7 +51,7 @@ func TestLoadbalancersListByTags(t *testing.T) {
5051
// Add "test" tag intentionally to test the "not-tags" parameter. Because "test" tag is also used in other test
5152
// cases, we use "test" tag to exclude load balancers created by other test case.
5253
tags := []string{"tag1", "tag2", "test"}
53-
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags)
54+
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "")
5455
th.AssertNoErr(t, err)
5556
defer DeleteLoadBalancer(t, lbClient, lb.ID)
5657

@@ -110,7 +111,7 @@ func TestLoadbalancerHTTPCRUD(t *testing.T) {
110111
th.AssertNoErr(t, err)
111112
defer networking.DeleteSubnet(t, netClient, subnet.ID)
112113

113-
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, nil)
114+
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, nil, "")
114115
th.AssertNoErr(t, err)
115116
defer DeleteLoadBalancer(t, lbClient, lb.ID)
116117

@@ -239,6 +240,12 @@ func TestLoadbalancersCRUD(t *testing.T) {
239240
netClient, err := clients.NewNetworkV2Client()
240241
th.AssertNoErr(t, err)
241242

243+
// Create QoS policy first as the loadbalancer and its port
244+
//needs to be deleted before the QoS policy can be deleted
245+
policy2, err := policies.CreateQoSPolicy(t, netClient)
246+
th.AssertNoErr(t, err)
247+
defer policies.DeleteQoSPolicy(t, netClient, policy2.ID)
248+
242249
lbClient, err := clients.NewLoadBalancerV2Client()
243250
th.AssertNoErr(t, err)
244251

@@ -250,14 +257,20 @@ func TestLoadbalancersCRUD(t *testing.T) {
250257
th.AssertNoErr(t, err)
251258
defer networking.DeleteSubnet(t, netClient, subnet.ID)
252259

260+
policy1, err := policies.CreateQoSPolicy(t, netClient)
261+
th.AssertNoErr(t, err)
262+
defer policies.DeleteQoSPolicy(t, netClient, policy1.ID)
263+
253264
tags := []string{"test"}
254-
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags)
265+
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, policy1.ID)
255266
th.AssertNoErr(t, err)
267+
th.AssertEquals(t, lb.VipQosPolicyID, policy1.ID)
256268
defer DeleteLoadBalancer(t, lbClient, lb.ID)
257269

258270
lbDescription := ""
259271
updateLoadBalancerOpts := loadbalancers.UpdateOpts{
260-
Description: &lbDescription,
272+
Description: &lbDescription,
273+
VipQosPolicyID: &policy2.ID,
261274
}
262275
_, err = loadbalancers.Update(lbClient, lb.ID, updateLoadBalancerOpts).Extract()
263276
th.AssertNoErr(t, err)
@@ -272,6 +285,7 @@ func TestLoadbalancersCRUD(t *testing.T) {
272285
tools.PrintResource(t, newLB)
273286

274287
th.AssertEquals(t, newLB.Description, lbDescription)
288+
th.AssertEquals(t, newLB.VipQosPolicyID, policy2.ID)
275289

276290
lbStats, err := loadbalancers.GetStats(lbClient, lb.ID).Extract()
277291
th.AssertNoErr(t, err)
@@ -449,7 +463,7 @@ func TestLoadbalancersCascadeCRUD(t *testing.T) {
449463
defer networking.DeleteSubnet(t, netClient, subnet.ID)
450464

451465
tags := []string{"test"}
452-
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags)
466+
lb, err := CreateLoadBalancer(t, lbClient, subnet.ID, tags, "")
453467
th.AssertNoErr(t, err)
454468
defer CascadeDeleteLoadBalancer(t, lbClient, lb.ID)
455469

openstack/loadbalancer/v2/loadbalancers/requests.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ type CreateOpts struct {
107107
// The IP address of the Loadbalancer.
108108
VipAddress string `json:"vip_address,omitempty"`
109109

110+
// The ID of the QoS Policy which will apply to the Virtual IP
111+
VipQosPolicyID string `json:"vip_qos_policy_id,omitempty"`
112+
110113
// The administrative state of the Loadbalancer. A valid value is true (UP)
111114
// or false (DOWN).
112115
AdminStateUp *bool `json:"admin_state_up,omitempty"`
@@ -185,6 +188,9 @@ type UpdateOpts struct {
185188
// or false (DOWN).
186189
AdminStateUp *bool `json:"admin_state_up,omitempty"`
187190

191+
// The ID of the QoS Policy which will apply to the Virtual IP
192+
VipQosPolicyID *string `json:"vip_qos_policy_id,omitempty"`
193+
188194
// Tags is a set of resource tags.
189195
Tags *[]string `json:"tags,omitempty"`
190196
}

openstack/loadbalancer/v2/loadbalancers/results.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type LoadBalancer struct {
4747
// Loadbalancer address.
4848
VipNetworkID string `json:"vip_network_id"`
4949

50+
// The ID of the QoS Policy which will apply to the Virtual IP
51+
VipQosPolicyID string `json:"vip_qos_policy_id"`
52+
5053
// The unique ID for the LoadBalancer.
5154
ID string `json:"id"`
5255

0 commit comments

Comments
 (0)