Add new parameter "is_default" to Network QoS policy.

Add a set of exclusive parameters to the Network QoS policy:
  --default: makes this policy the default policy for
             the project to which the qos policy belongs.
  --no-default: unset the property.

Closes-Bug: #1639220
Depends-On: If5ff2b00fa828f93aa089e275ddbd1ff542b79d4
Depends-On: Ibe7b7881cb190bfd5582f35b6de51a8bc21135de
Change-Id: I0269b837dc29bbd8ee2089d847cadb72d800fa30
This commit is contained in:
Rodolfo Alonso Hernandez 2017-02-16 18:55:02 +00:00
parent 79b992b53b
commit c17819ab58
6 changed files with 112 additions and 13 deletions

View File

@ -20,6 +20,7 @@ Create new Network QoS policy
[--share | --no-share]
[--project <project>]
[--project-domain <project-domain>]
[--default | --no-default]
<name>
.. option:: --description <description>
@ -43,6 +44,14 @@ Create new Network QoS policy
Domain the project belongs to (name or ID).
This can be used in case collisions between project names exist.
.. option:: --default
Set this as a default network QoS policy
.. option:: --no-default
Set this as a non-default network QoS policy
.. _network_qos_policy_create-name:
.. describe:: <name>
@ -105,6 +114,7 @@ Set Network QoS policy properties
[--name <name>]
[--description <description>]
[--share | --no-share]
[--default | --no-default]
<qos-policy>
.. option:: --name <name>
@ -123,6 +133,14 @@ Set Network QoS policy properties
Make the QoS policy not accessible by other projects
.. option:: --default
Set this as a default network QoS policy
.. option:: --no-default
Set this as a non-default network QoS policy
.. _network_qos_policy_set-qos-policy:
.. describe:: <qos-policy>

View File

@ -45,7 +45,15 @@ def _get_attrs(client_manager, parsed_args):
attrs['shared'] = True
if parsed_args.no_share:
attrs['shared'] = False
if parsed_args.project is not None:
# NOTE(ralonsoh): 'default' and 'no_default' parameters are defined only in
# create and set commands context only.
if 'default' in parsed_args and parsed_args.default:
attrs['is_default'] = True
if 'no_default' in parsed_args and parsed_args.no_default:
attrs['is_default'] = False
# NOTE(ralonsoh): 'project' parameter is defined only in create and list
# commands context only.
if 'project' in parsed_args and parsed_args.project is not None:
identity_client = client_manager.identity
project_id = identity_common.find_project(
identity_client,
@ -93,6 +101,17 @@ class CreateNetworkQosPolicy(command.ShowOne):
help=_("Owner's project (name or ID)")
)
identity_common.add_project_domain_option_to_parser(parser)
default_group = parser.add_mutually_exclusive_group()
default_group.add_argument(
'--default',
action='store_true',
help=_("Set this as a default network QoS policy"),
)
default_group.add_argument(
'--no-default',
action='store_true',
help=_("Set this as a non-default network QoS policy"),
)
return parser
def take_action(self, parsed_args):
@ -170,12 +189,14 @@ class ListNetworkQosPolicy(command.Lister):
'id',
'name',
'is_shared',
'is_default',
'project_id',
)
column_headers = (
'ID',
'Name',
'Shared',
'Default',
'Project',
)
attrs = _get_attrs(self.app.client_manager, parsed_args)
@ -219,6 +240,17 @@ class SetNetworkQosPolicy(command.Command):
action='store_true',
help=_('Make the QoS policy not accessible by other projects'),
)
default_group = parser.add_mutually_exclusive_group()
default_group.add_argument(
'--default',
action='store_true',
help=_("Set this as a default network QoS policy"),
)
default_group.add_argument(
'--no-default',
action='store_true',
help=_("Set this as a non-default network QoS policy"),
)
return parser
def take_action(self, parsed_args):
@ -226,15 +258,7 @@ class SetNetworkQosPolicy(command.Command):
obj = client.find_qos_policy(
parsed_args.policy,
ignore_missing=False)
attrs = {}
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
if parsed_args.share:
attrs['shared'] = True
if parsed_args.no_share:
attrs['shared'] = False
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
attrs = _get_attrs(self.app.client_manager, parsed_args)
client.update_qos_policy(obj, **attrs)

View File

@ -68,3 +68,16 @@ class NetworkQosPolicyTests(common.NetworkTests):
raw_output = self.openstack('network qos policy show ' + self.NAME +
opts)
self.assertEqual("True\n", raw_output)
def test_qos_policy_default(self):
self.openstack('network qos policy set --default ' + self.NAME)
opts = self.get_opts(['is_default'])
raw_output = self.openstack('network qos policy show ' + self.NAME +
opts)
self.assertEqual("True\n", raw_output)
self.openstack('network qos policy set --no-default ' + self.NAME)
opts = self.get_opts(['is_default'])
raw_output = self.openstack('network qos policy show ' + self.NAME +
opts)
self.assertEqual("False\n", raw_output)

View File

@ -841,6 +841,7 @@ class FakeNetworkQosPolicy(object):
qos_policy_attrs = {
'name': 'qos-policy-name-' + uuid.uuid4().hex,
'id': qos_id,
'is_default': False,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
'shared': False,
'description': 'qos-policy-description-' + uuid.uuid4().hex,

View File

@ -48,6 +48,7 @@ class TestCreateNetworkQosPolicy(TestQosPolicy):
columns = (
'description',
'id',
'is_default',
'name',
'project_id',
'rules',
@ -57,6 +58,7 @@ class TestCreateNetworkQosPolicy(TestQosPolicy):
data = (
new_qos_policy.description,
new_qos_policy.id,
new_qos_policy.is_default,
new_qos_policy.name,
new_qos_policy.project_id,
new_qos_policy.rules,
@ -106,12 +108,14 @@ class TestCreateNetworkQosPolicy(TestQosPolicy):
'--project', self.project.name,
self.new_qos_policy.name,
'--description', 'QoS policy description',
'--default',
]
verifylist = [
('share', True),
('project', self.project.name),
('name', self.new_qos_policy.name),
('description', 'QoS policy description'),
('default', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -122,6 +126,28 @@ class TestCreateNetworkQosPolicy(TestQosPolicy):
'tenant_id': self.project.id,
'name': self.new_qos_policy.name,
'description': 'QoS policy description',
'is_default': True,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_create_no_default(self):
arglist = [
self.new_qos_policy.name,
'--no-default'
]
verifylist = [
('project', None),
('name', self.new_qos_policy.name),
('default', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = (self.cmd.take_action(parsed_args))
self.network.create_qos_policy.assert_called_once_with(**{
'name': self.new_qos_policy.name,
'is_default': False,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
@ -220,6 +246,7 @@ class TestListNetworkQosPolicy(TestQosPolicy):
'ID',
'Name',
'Shared',
'Default',
'Project',
)
data = []
@ -228,6 +255,7 @@ class TestListNetworkQosPolicy(TestQosPolicy):
qos_policy.id,
qos_policy.name,
qos_policy.shared,
qos_policy.is_default,
qos_policy.project_id,
))
@ -333,17 +361,19 @@ class TestSetNetworkQosPolicy(TestQosPolicy):
self._qos_policy, **attrs)
self.assertIsNone(result)
def test_set_name_share_description(self):
def test_set_name_share_description_default(self):
arglist = [
'--name', 'new_qos_policy',
'--share',
'--description', 'QoS policy description',
'--default',
self._qos_policy.name,
]
verifylist = [
('name', 'new_qos_policy'),
('share', True),
('description', 'QoS policy description'),
('default', True),
('policy', self._qos_policy.name),
]
@ -353,25 +383,29 @@ class TestSetNetworkQosPolicy(TestQosPolicy):
'name': 'new_qos_policy',
'description': 'QoS policy description',
'shared': True,
'is_default': True,
}
self.network.update_qos_policy.assert_called_with(
self._qos_policy, **attrs)
self.assertIsNone(result)
def test_set_no_share(self):
def test_set_no_share_no_default(self):
arglist = [
'--no-share',
'--no-default',
self._qos_policy.name,
]
verifylist = [
('no_share', True),
('no_default', True),
('policy', self._qos_policy.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
attrs = {
'shared': False
'shared': False,
'is_default': False
}
self.network.update_qos_policy.assert_called_with(
self._qos_policy, **attrs)
@ -386,6 +420,7 @@ class TestShowNetworkQosPolicy(TestQosPolicy):
columns = (
'description',
'id',
'is_default',
'name',
'project_id',
'rules',
@ -394,6 +429,7 @@ class TestShowNetworkQosPolicy(TestQosPolicy):
data = (
_qos_policy.description,
_qos_policy.id,
_qos_policy.is_default,
_qos_policy.name,
_qos_policy.project_id,
_qos_policy.rules,

View File

@ -0,0 +1,7 @@
---
features:
- |
Add ``--default`` and ``--no-default`` options to
``network qos policy create`` and ``network qos policy set``
comamnds.
[Bug `1639220 <https://bugs.launchpad.net/bugs/1639220>`_]