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 `_.