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

View File

@ -45,7 +45,15 @@ def _get_attrs(client_manager, parsed_args):
attrs['shared'] = True attrs['shared'] = True
if parsed_args.no_share: if parsed_args.no_share:
attrs['shared'] = False 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 identity_client = client_manager.identity
project_id = identity_common.find_project( project_id = identity_common.find_project(
identity_client, identity_client,
@ -93,6 +101,17 @@ class CreateNetworkQosPolicy(command.ShowOne):
help=_("Owner's project (name or ID)") help=_("Owner's project (name or ID)")
) )
identity_common.add_project_domain_option_to_parser(parser) 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 return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -170,12 +189,14 @@ class ListNetworkQosPolicy(command.Lister):
'id', 'id',
'name', 'name',
'is_shared', 'is_shared',
'is_default',
'project_id', 'project_id',
) )
column_headers = ( column_headers = (
'ID', 'ID',
'Name', 'Name',
'Shared', 'Shared',
'Default',
'Project', 'Project',
) )
attrs = _get_attrs(self.app.client_manager, parsed_args) attrs = _get_attrs(self.app.client_manager, parsed_args)
@ -219,6 +240,17 @@ class SetNetworkQosPolicy(command.Command):
action='store_true', action='store_true',
help=_('Make the QoS policy not accessible by other projects'), 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 return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -226,15 +258,7 @@ class SetNetworkQosPolicy(command.Command):
obj = client.find_qos_policy( obj = client.find_qos_policy(
parsed_args.policy, parsed_args.policy,
ignore_missing=False) ignore_missing=False)
attrs = {} attrs = _get_attrs(self.app.client_manager, parsed_args)
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
client.update_qos_policy(obj, **attrs) 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 + raw_output = self.openstack('network qos policy show ' + self.NAME +
opts) opts)
self.assertEqual("True\n", raw_output) 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 = { qos_policy_attrs = {
'name': 'qos-policy-name-' + uuid.uuid4().hex, 'name': 'qos-policy-name-' + uuid.uuid4().hex,
'id': qos_id, 'id': qos_id,
'is_default': False,
'tenant_id': 'project-id-' + uuid.uuid4().hex, 'tenant_id': 'project-id-' + uuid.uuid4().hex,
'shared': False, 'shared': False,
'description': 'qos-policy-description-' + uuid.uuid4().hex, 'description': 'qos-policy-description-' + uuid.uuid4().hex,

View File

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