Merge "Add '--force' option to 'volume snapshot delete' command"
This commit is contained in:
commit
d09fd7d832
@ -51,8 +51,13 @@ Delete volume snapshot(s)
|
|||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
os volume snapshot delete
|
os volume snapshot delete
|
||||||
|
[--force]
|
||||||
<snapshot> [<snapshot> ...]
|
<snapshot> [<snapshot> ...]
|
||||||
|
|
||||||
|
.. option:: --force
|
||||||
|
|
||||||
|
Attempt forced removal of snapshot(s), regardless of state (defaults to False)
|
||||||
|
|
||||||
.. _volume_snapshot_delete-snapshot:
|
.. _volume_snapshot_delete-snapshot:
|
||||||
.. describe:: <snapshot>
|
.. describe:: <snapshot>
|
||||||
|
|
||||||
|
@ -179,7 +179,24 @@ class TestSnapshotDelete(TestSnapshot):
|
|||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.snapshots_mock.delete.assert_called_with(
|
self.snapshots_mock.delete.assert_called_with(
|
||||||
self.snapshots[0].id)
|
self.snapshots[0].id, False)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_snapshot_delete_with_force(self):
|
||||||
|
arglist = [
|
||||||
|
'--force',
|
||||||
|
self.snapshots[0].id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('force', True),
|
||||||
|
("snapshots", [self.snapshots[0].id])
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.snapshots_mock.delete.assert_called_with(
|
||||||
|
self.snapshots[0].id, True)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_delete_multiple_snapshots(self):
|
def test_delete_multiple_snapshots(self):
|
||||||
@ -195,7 +212,7 @@ class TestSnapshotDelete(TestSnapshot):
|
|||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
for s in self.snapshots:
|
for s in self.snapshots:
|
||||||
calls.append(call(s.id))
|
calls.append(call(s.id, False))
|
||||||
self.snapshots_mock.delete.assert_has_calls(calls)
|
self.snapshots_mock.delete.assert_has_calls(calls)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ -226,7 +243,7 @@ class TestSnapshotDelete(TestSnapshot):
|
|||||||
|
|
||||||
self.assertEqual(2, find_mock.call_count)
|
self.assertEqual(2, find_mock.call_count)
|
||||||
self.snapshots_mock.delete.assert_called_once_with(
|
self.snapshots_mock.delete.assert_called_once_with(
|
||||||
self.snapshots[0].id
|
self.snapshots[0].id, False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,6 +98,12 @@ class DeleteVolumeSnapshot(command.Command):
|
|||||||
nargs="+",
|
nargs="+",
|
||||||
help=_("Snapshot(s) to delete (name or ID)")
|
help=_("Snapshot(s) to delete (name or ID)")
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--force',
|
||||||
|
action='store_true',
|
||||||
|
help=_("Attempt forced removal of snapshot(s), "
|
||||||
|
"regardless of state (defaults to False)")
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -108,7 +114,8 @@ class DeleteVolumeSnapshot(command.Command):
|
|||||||
try:
|
try:
|
||||||
snapshot_id = utils.find_resource(
|
snapshot_id = utils.find_resource(
|
||||||
volume_client.volume_snapshots, i).id
|
volume_client.volume_snapshots, i).id
|
||||||
volume_client.volume_snapshots.delete(snapshot_id)
|
volume_client.volume_snapshots.delete(
|
||||||
|
snapshot_id, parsed_args.force)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result += 1
|
result += 1
|
||||||
LOG.error(_("Failed to delete snapshot with "
|
LOG.error(_("Failed to delete snapshot with "
|
||||||
|
6
releasenotes/notes/bug-1597195-54ff1ecf381899f6.yaml
Normal file
6
releasenotes/notes/bug-1597195-54ff1ecf381899f6.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--force`` option to ``volume snapshot delete`` command to allow delete
|
||||||
|
in state other than error or available.
|
||||||
|
[Bug `1597195 <https://bugs.launchpad.net/bugs/1597195>`_]
|
Loading…
Reference in New Issue
Block a user