From 521ff7cee562df5105c6404fadb261092af7e342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Thu, 9 Jun 2016 20:39:03 +0000 Subject: [PATCH] Add no-shared option to qos-policy-update command QoS policy can now be updated to be not shared with other tenants if it was shared before. To set QoS policy as not shared option "--no-shared" should be passed to qos-policy-update command. Option '--shared' works still like it was before so this change is backward compatible. Change-Id: I18d32813b3c59cbadfe1f4a1b9ba06725a1d7bb8 Closes-Bug: #1590942 --- neutronclient/neutron/v2_0/qos/policy.py | 13 ++++++-- .../tests/unit/qos/test_cli20_policy.py | 30 +++++++++++++++++++ ...to-qos-policy-update-56ac41fb3af7e309.yaml | 6 ++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/add-no-shared-option-to-qos-policy-update-56ac41fb3af7e309.yaml diff --git a/neutronclient/neutron/v2_0/qos/policy.py b/neutronclient/neutron/v2_0/qos/policy.py index 047888aa8..53805284b 100644 --- a/neutronclient/neutron/v2_0/qos/policy.py +++ b/neutronclient/neutron/v2_0/qos/policy.py @@ -126,11 +126,17 @@ class UpdateQoSPolicy(neutronv20.UpdateCommand): parser.add_argument( '--description', help=_('Description of the QoS policy.')) - parser.add_argument( + shared_group = parser.add_mutually_exclusive_group() + shared_group.add_argument( '--shared', action='store_true', help=_('Accessible by other tenants. ' 'Set shared to True (default is False).')) + shared_group.add_argument( + '--no-shared', + action='store_true', + help=_('Not accessible by other tenants. ' + 'Set shared to False.')) def args2body(self, parsed_args): body = {} @@ -139,7 +145,10 @@ class UpdateQoSPolicy(neutronv20.UpdateCommand): if parsed_args.description: body['description'] = parsed_args.description if parsed_args.shared: - body['shared'] = parsed_args.shared + body['shared'] = True + if parsed_args.no_shared: + body['shared'] = False + return {self.resource: body} diff --git a/neutronclient/tests/unit/qos/test_cli20_policy.py b/neutronclient/tests/unit/qos/test_cli20_policy.py index ab6cb8fbe..b1db866e4 100644 --- a/neutronclient/tests/unit/qos/test_cli20_policy.py +++ b/neutronclient/tests/unit/qos/test_cli20_policy.py @@ -104,6 +104,36 @@ class CLITestV20QoSPolicyJSON(test_cli20.CLITestV20Base): {'description': 'newdesc', }, cmd_resource=self.cmd_res) + def test_update_policy_to_shared(self): + # policy-update myid --shared + cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout), + None) + self._test_update_resource(self.res, cmd, 'myid', + ['myid', '--shared'], + {'shared': True, }, + cmd_resource=self.cmd_res) + + def test_update_policy_to_no_shared(self): + # policy-update myid --no-shared + cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout), + None) + self._test_update_resource(self.res, cmd, 'myid', + ['myid', '--no-shared'], + {'shared': False, }, + cmd_resource=self.cmd_res) + + def test_update_policy_to_shared_no_shared_together(self): + # policy-update myid --shared --no-shared + cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout), + None) + self.assertRaises( + SystemExit, + self._test_update_resource, + self.res, cmd, 'myid', + ['myid', '--shared', '--no-shared'], {}, + cmd_resource=self.cmd_res + ) + def test_list_policies(self): # qos-policy-list. cmd = policy.ListQoSPolicy(test_cli20.MyApp(sys.stdout), diff --git a/releasenotes/notes/add-no-shared-option-to-qos-policy-update-56ac41fb3af7e309.yaml b/releasenotes/notes/add-no-shared-option-to-qos-policy-update-56ac41fb3af7e309.yaml new file mode 100644 index 000000000..0c34f5eeb --- /dev/null +++ b/releasenotes/notes/add-no-shared-option-to-qos-policy-update-56ac41fb3af7e309.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + CLI support to set QoS policy as not shared if it was shared before. + The ``qos-policy-update`` command include a ``--no-shared`` option. + Closes `bug 1590942 `_.