Skip to content

Commit bbfd8cb

Browse files
author
Huanxuan Ao
committed
Add '--force' option to 'volume snapshot delete' command
Add '--force' option to 'volume snapshot delete' command in volume v2 (v2 only) to allow delete in state other than error or available. Change-Id: Ie8991e9a630d7c7e9ac6c6870aed787bbcebacf2 Closes-Bug: #1597195
1 parent 158dbe1 commit bbfd8cb

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

doc/source/command-objects/volume-snapshot.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ Delete volume snapshot(s)
5151
.. code:: bash
5252
5353
os volume snapshot delete
54+
[--force]
5455
<snapshot> [<snapshot> ...]
5556
57+
.. option:: --force
58+
59+
Attempt forced removal of snapshot(s), regardless of state (defaults to False)
60+
5661
.. _volume_snapshot_delete-snapshot:
5762
.. describe:: <snapshot>
5863

openstackclient/tests/unit/volume/v2/test_snapshot.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,24 @@ def test_snapshot_delete(self):
179179
result = self.cmd.take_action(parsed_args)
180180

181181
self.snapshots_mock.delete.assert_called_with(
182-
self.snapshots[0].id)
182+
self.snapshots[0].id, False)
183+
self.assertIsNone(result)
184+
185+
def test_snapshot_delete_with_force(self):
186+
arglist = [
187+
'--force',
188+
self.snapshots[0].id
189+
]
190+
verifylist = [
191+
('force', True),
192+
("snapshots", [self.snapshots[0].id])
193+
]
194+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
195+
196+
result = self.cmd.take_action(parsed_args)
197+
198+
self.snapshots_mock.delete.assert_called_with(
199+
self.snapshots[0].id, True)
183200
self.assertIsNone(result)
184201

185202
def test_delete_multiple_snapshots(self):
@@ -195,7 +212,7 @@ def test_delete_multiple_snapshots(self):
195212

196213
calls = []
197214
for s in self.snapshots:
198-
calls.append(call(s.id))
215+
calls.append(call(s.id, False))
199216
self.snapshots_mock.delete.assert_has_calls(calls)
200217
self.assertIsNone(result)
201218

@@ -226,7 +243,7 @@ def test_delete_multiple_snapshots_with_exception(self):
226243

227244
self.assertEqual(2, find_mock.call_count)
228245
self.snapshots_mock.delete.assert_called_once_with(
229-
self.snapshots[0].id
246+
self.snapshots[0].id, False
230247
)
231248

232249

openstackclient/volume/v2/volume_snapshot.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ def get_parser(self, prog_name):
9898
nargs="+",
9999
help=_("Snapshot(s) to delete (name or ID)")
100100
)
101+
parser.add_argument(
102+
'--force',
103+
action='store_true',
104+
help=_("Attempt forced removal of snapshot(s), "
105+
"regardless of state (defaults to False)")
106+
)
101107
return parser
102108

103109
def take_action(self, parsed_args):
@@ -108,7 +114,8 @@ def take_action(self, parsed_args):
108114
try:
109115
snapshot_id = utils.find_resource(
110116
volume_client.volume_snapshots, i).id
111-
volume_client.volume_snapshots.delete(snapshot_id)
117+
volume_client.volume_snapshots.delete(
118+
snapshot_id, parsed_args.force)
112119
except Exception as e:
113120
result += 1
114121
LOG.error(_("Failed to delete snapshot with "
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add ``--force`` option to ``volume snapshot delete`` command to allow delete
5+
in state other than error or available.
6+
[Bug `1597195 <https://bugs.launchpad.net/bugs/1597195>`_]

0 commit comments

Comments
 (0)