From 4e46c04f921c81927ded78f17fd28d5a55ebf9e2 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Tue, 28 Jun 2016 15:54:13 +0800 Subject: [PATCH] Add "--force" option to "volume qos delete" command Add ``--force`` option to ``volume qos delete`` command in volume v1 and v2 to allow users to delete in-use QoS specification(s). Change-Id: I46036e5f55ced8b8a1be54c521f2a5c242b89160 Closes-Bug: #1596821 --- doc/source/command-objects/volume-qos.rst | 5 +++++ .../tests/volume/v1/test_qos_specs.py | 20 +++++++++++++++++-- .../tests/volume/v2/test_qos_specs.py | 18 ++++++++++++++++- openstackclient/volume/v1/qos_specs.py | 8 +++++++- openstackclient/volume/v2/qos_specs.py | 8 +++++++- .../notes/bug-1596821-a07599eb4beb6342.yaml | 6 ++++++ 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/bug-1596821-a07599eb4beb6342.yaml diff --git a/doc/source/command-objects/volume-qos.rst b/doc/source/command-objects/volume-qos.rst index 2d9d14a4f..f3c7ec211 100644 --- a/doc/source/command-objects/volume-qos.rst +++ b/doc/source/command-objects/volume-qos.rst @@ -58,8 +58,13 @@ Delete QoS specification .. code:: bash os volume qos delete + [--force] [ ...] +.. option:: --force + + Allow to delete in-use QoS specification(s) + .. describe:: QoS specification(s) to delete (name or ID) diff --git a/openstackclient/tests/volume/v1/test_qos_specs.py b/openstackclient/tests/volume/v1/test_qos_specs.py index 392017c65..4e1733fde 100644 --- a/openstackclient/tests/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/volume/v1/test_qos_specs.py @@ -211,7 +211,7 @@ class TestQosDelete(TestQos): result = self.cmd.take_action(parsed_args) - self.qos_mock.delete.assert_called_with(volume_fakes.qos_id) + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id, False) self.assertIsNone(result) def test_qos_delete_with_name(self): @@ -225,7 +225,23 @@ class TestQosDelete(TestQos): result = self.cmd.take_action(parsed_args) - self.qos_mock.delete.assert_called_with(volume_fakes.qos_id) + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id, False) + self.assertIsNone(result) + + def test_qos_delete_with_force(self): + arglist = [ + '--force', + volume_fakes.qos_id + ] + verifylist = [ + ('force', True), + ('qos_specs', [volume_fakes.qos_id]) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.qos_mock.delete.assert_called_with(volume_fakes.qos_id, True) self.assertIsNone(result) diff --git a/openstackclient/tests/volume/v2/test_qos_specs.py b/openstackclient/tests/volume/v2/test_qos_specs.py index 11047535c..92ffca74e 100644 --- a/openstackclient/tests/volume/v2/test_qos_specs.py +++ b/openstackclient/tests/volume/v2/test_qos_specs.py @@ -175,7 +175,23 @@ class TestQosDelete(TestQos): result = self.cmd.take_action(parsed_args) - self.qos_mock.delete.assert_called_with(self.qos_spec.id) + self.qos_mock.delete.assert_called_with(self.qos_spec.id, False) + self.assertIsNone(result) + + def test_qos_delete_with_force(self): + arglist = [ + '--force', + self.qos_spec.id + ] + verifylist = [ + ('force', True), + ('qos_specs', [self.qos_spec.id]) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.qos_mock.delete.assert_called_with(self.qos_spec.id, True) self.assertIsNone(result) diff --git a/openstackclient/volume/v1/qos_specs.py b/openstackclient/volume/v1/qos_specs.py index 56a96256a..c5850871e 100644 --- a/openstackclient/volume/v1/qos_specs.py +++ b/openstackclient/volume/v1/qos_specs.py @@ -103,13 +103,19 @@ class DeleteQos(command.Command): nargs="+", help=_('QoS specification(s) to delete (name or ID)'), ) + parser.add_argument( + '--force', + action='store_true', + default=False, + help=_("Allow to delete in-use QoS specification(s)") + ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume for qos in parsed_args.qos_specs: qos_spec = utils.find_resource(volume_client.qos_specs, qos) - volume_client.qos_specs.delete(qos_spec.id) + volume_client.qos_specs.delete(qos_spec.id, parsed_args.force) class DisassociateQos(command.Command): diff --git a/openstackclient/volume/v2/qos_specs.py b/openstackclient/volume/v2/qos_specs.py index 7ec272b38..5ed1225bf 100644 --- a/openstackclient/volume/v2/qos_specs.py +++ b/openstackclient/volume/v2/qos_specs.py @@ -103,13 +103,19 @@ class DeleteQos(command.Command): nargs="+", help=_('QoS specification(s) to delete (name or ID)'), ) + parser.add_argument( + '--force', + action='store_true', + default=False, + help=_("Allow to delete in-use QoS specification(s)") + ) return parser def take_action(self, parsed_args): volume_client = self.app.client_manager.volume for qos in parsed_args.qos_specs: qos_spec = utils.find_resource(volume_client.qos_specs, qos) - volume_client.qos_specs.delete(qos_spec.id) + volume_client.qos_specs.delete(qos_spec.id, parsed_args.force) class DisassociateQos(command.Command): diff --git a/releasenotes/notes/bug-1596821-a07599eb4beb6342.yaml b/releasenotes/notes/bug-1596821-a07599eb4beb6342.yaml new file mode 100644 index 000000000..4843314b7 --- /dev/null +++ b/releasenotes/notes/bug-1596821-a07599eb4beb6342.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add ``--force`` option to ``volume qos delete`` command to allow users to + delete in-use QoS specification(s). + [Bug `1596821 `_]