Browse Source

Add VIP QoS Policy client support

* Allow to specify QoS Policy ID for VIP, both in loadbalancer
create and update.
* Loadbalancer show will now display the VIP QoS Policy ID.

Task: 5864
Story: 2001310

Depends-On: I43aba9d2ae816b1498d16da077936d6bdb62e30a

Change-Id: I54ae195ee953a63b1bffaf4ef1e0cb00d0945f3e
changes/17/526217/5
Bar RH 4 years ago
parent
commit
3f0ab0ea75
5 changed files with 92 additions and 5 deletions
  1. +1
    -0
      octaviaclient/osc/v2/constants.py
  2. +10
    -0
      octaviaclient/osc/v2/load_balancer.py
  3. +10
    -0
      octaviaclient/osc/v2/utils.py
  4. +66
    -5
      octaviaclient/tests/unit/osc/v2/test_load_balancer.py
  5. +5
    -0
      releasenotes/notes/add-qos-policy-argument-1741126d759630da.yaml

+ 1
- 0
octaviaclient/osc/v2/constants.py View File

@ -29,6 +29,7 @@ LOAD_BALANCER_ROWS = (
'vip_address',
'vip_network_id',
'vip_port_id',
'vip_qos_policy_id',
'vip_subnet_id',
)


+ 10
- 0
octaviaclient/osc/v2/load_balancer.py View File

@ -75,6 +75,11 @@ class CreateLoadBalancer(command.ShowOne):
metavar='<vip_network_id>',
help="Set network for the load balancer (name or ID)."
)
parser.add_argument(
'--vip-qos-policy-id',
metavar='<vip_qos_policy_id>',
help="Set QoS policy ID for VIP port. Unset with 'None'.",
)
parser.add_argument(
'--project',
@ -272,6 +277,11 @@ class SetLoadBalancer(command.Command):
metavar='<description>',
help="Set load balancer description."
)
parser.add_argument(
'--vip-qos-policy-id',
metavar='<vip_qos_policy_id>',
help="Set QoS policy ID for VIP port. Unset with 'None'.",
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(


+ 10
- 0
octaviaclient/osc/v2/utils.py View File

@ -71,6 +71,11 @@ def get_resource_id(resource, resource_name, name):
The UUID of the found resource
"""
try:
# Allow None as a value
if resource_name in ('policies',):
if name.lower() in ('none', 'null', 'void'):
return None
# Projects can be non-uuid so we need to account for this
if resource_name == 'project':
if name != 'non-uuid':
@ -146,6 +151,11 @@ def get_loadbalancer_attrs(client_manager, parsed_args):
'networks',
client_manager.neutronclient.list_networks
),
'vip_qos_policy_id': (
'vip_qos_policy_id',
'policies',
client_manager.neutronclient.list_qos_policies,
),
'enable': ('admin_state_up', lambda x: True),
'disable': ('admin_state_up', lambda x: False),
'cascade': ('cascade', lambda x: True)


+ 66
- 5
octaviaclient/tests/unit/osc/v2/test_load_balancer.py View File

@ -16,6 +16,7 @@ import itertools
import mock
from osc_lib import exceptions
from oslo_utils import uuidutils
from octaviaclient.osc.v2 import load_balancer as load_balancer
from octaviaclient.tests.unit.osc.v2 import fakes as lb_fakes
@ -160,9 +161,37 @@ class TestLoadBalancerCreate(TestLoadBalancer):
self.api_mock.load_balancer_create.assert_called_with(
json={'loadbalancer': self.lb_info['loadbalancers'][0]})
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_create_with_qos_policy(self, mock_client):
qos_policy_id = 'qos_id'
lb_info = copy.deepcopy(self.lb_info['loadbalancers'][0])
lb_info.update({'vip_qos_policy_id': qos_policy_id})
mock_client.return_value = lb_info
arglist = [
'--name', self._lb.name,
'--vip-network-id', self._lb.vip_network_id,
'--project', self._lb.project_id,
'--vip-qos-policy-id', qos_policy_id,
]
verifylist = [
('name', self._lb.name),
('vip_network_id', self._lb.vip_network_id),
('project', self._lb.project_id),
('vip_qos_policy_id', qos_policy_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.load_balancer_create.assert_called_with(
json={'loadbalancer': lb_info})
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_create_missing_args(self, mock_client):
attrs_list = self.lb_info['loadbalancers'][0]
# Clone load balancer to avoid race conditions
lb = lb_fakes.FakeLoadBalancer.create_one_load_balancer()
attrs_list = lb.to_dict()
args = ("vip_subnet_id", "vip_network_id", "vip_port_id")
for a in args:
# init missing keys
@ -223,17 +252,49 @@ class TestLoadBalancerSet(TestLoadBalancer):
lb_client.load_balancer = self.api_mock
self.cmd = load_balancer.SetLoadBalancer(self.app, None)
def test_load_balancer_set(self):
arglist = [self._lb.id, '--name', 'new_name']
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_set(self, mock_attrs):
qos_policy_id = uuidutils.generate_uuid()
mock_attrs.return_value = {
'loadbalancer_id': self._lb.id,
'name': 'new_name',
'vip_qos_policy_id': qos_policy_id,
}
arglist = [self._lb.id, '--name', 'new_name',
'--vip-qos-policy-id', qos_policy_id]
verifylist = [
('loadbalancer', self._lb.id),
('name', 'new_name')
('name', 'new_name'),
('vip_qos_policy_id', qos_policy_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.api_mock.load_balancer_set.assert_called_with(
self._lb.id, json={'loadbalancer': {'name': 'new_name'}})
self._lb.id, json={
'loadbalancer': {
'name': 'new_name',
'vip_qos_policy_id': qos_policy_id,
}
})
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_remove_qos_policy(self, mock_attrs):
mock_attrs.return_value = {
'loadbalancer_id': self._lb.id,
'vip_qos_policy_id': None,
}
arglist = [self._lb.id, '--vip-qos-policy-id', 'None']
verifylist = [
('loadbalancer', self._lb.id),
('vip_qos_policy_id', 'None'),
]
try:
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
except Exception as e:
self.fail("%s raised unexpectedly" % e)
class TestLoadBalancerStats(TestLoadBalancer):


+ 5
- 0
releasenotes/notes/add-qos-policy-argument-1741126d759630da.yaml View File

@ -0,0 +1,5 @@
---
features:
- |
Optional QoS policy argument for VIP, in loadbalancer create,
and loadbalancer set.

Loading…
Cancel
Save