Support for snapshot force delete

Cinder snapshot force delete is supported from cinder server
side but cinderclient support is not present.

This patchset adds support for cinder snapshot force delete
from cinderclient side.

Closes-Bug:#1418353

Change-Id: I8c4f02f9c3b855d44b1a3c7da7083d87b3b70da9
Implements: Blueprint snapshot-backup-force-delete
This commit is contained in:
Sheel Rana 2016-05-08 17:57:46 +05:30
parent 8d79acda0f
commit 699a2f5dce
4 changed files with 48 additions and 9 deletions

View File

@ -356,6 +356,8 @@ class FakeHTTPClient(base_client.HTTPClient):
assert 'status' in body['os-reset_status']
elif action == 'os-update_snapshot_status':
assert 'status' in body['os-update_snapshot_status']
elif action == 'os-force_delete':
assert body[action] is None
elif action == 'os-unmanage':
assert body[action] is None
else:

View File

@ -933,17 +933,44 @@ class ShellTest(utils.TestCase):
self.assert_called('POST', '/volumes/1234/action', body=expected)
def test_snapshot_delete(self):
"""Tests delete snapshot without force parameter"""
self.run_command('snapshot-delete 1234')
self.assert_called('DELETE', '/snapshots/1234')
def test_snapshot_delete_multiple(self):
"""Tests delete multiple snapshots without force parameter"""
self.run_command('snapshot-delete 5678 1234')
self.assert_called_anytime('DELETE', '/snapshots/5678')
self.assert_called('DELETE', '/snapshots/1234')
def test_force_snapshot_delete(self):
"""Tests delete snapshot with default force parameter value(True)"""
self.run_command('snapshot-delete 1234 --force')
expected_body = {'os-force_delete': None}
self.assert_called('POST',
'/snapshots/1234/action',
expected_body)
def test_force_snapshot_delete_multiple(self):
"""
Tests delete multiple snapshots with force parameter
Snapshot delete with force parameter allows deleting snapshot of a
volume when its status is other than "available" or "error".
"""
self.run_command('snapshot-delete 5678 1234 --force')
expected_body = {'os-force_delete': None}
self.assert_called_anytime('POST',
'/snapshots/5678/action',
expected_body)
self.assert_called_anytime('POST',
'/snapshots/1234/action',
expected_body)
def test_quota_delete(self):
self.run_command('quota-delete 1234')
self.assert_called('DELETE', '/os-quota-sets/1234')
def test_snapshot_delete_multiple(self):
self.run_command('snapshot-delete 5678')
self.assert_called('DELETE', '/snapshots/5678')
def test_volume_manage(self):
self.run_command('manage host1 some_fake_name '
'--name foo --description bar '

View File

@ -780,13 +780,19 @@ def do_snapshot_create(cs, args):
@utils.arg('snapshot',
metavar='<snapshot>', nargs='+',
help='Name or ID of the snapshot(s) to delete.')
@utils.arg('--force',
action="store_true",
help='Allows deleting snapshot of a volume '
'when its status is other than "available" or "error". '
'Default=False.')
@utils.service_type('volumev3')
def do_snapshot_delete(cs, args):
"""Removes one or more snapshots."""
failure_count = 0
for snapshot in args.snapshot:
try:
_find_volume_snapshot(cs, snapshot).delete()
_find_volume_snapshot(cs, snapshot).delete(args.force)
except Exception as e:
failure_count += 1
print("Delete for snapshot %s failed: %s" % (snapshot, e))

View File

@ -25,9 +25,9 @@ class Snapshot(base.Resource):
def __repr__(self):
return "<Snapshot: %s>" % self.id
def delete(self):
def delete(self, force=False):
"""Delete this snapshot."""
return self.manager.delete(self)
return self.manager.delete(self, force)
def update(self, **kwargs):
"""Update the name or description for this snapshot."""
@ -118,12 +118,16 @@ class SnapshotManager(base.ManagerWithFind):
limit=limit, sort=sort)
return self._list(url, resource_type, limit=limit)
def delete(self, snapshot):
def delete(self, snapshot, force=False):
"""Delete a snapshot.
:param snapshot: The :class:`Snapshot` to delete.
:param force: Allow delete in state other than error or available.
"""
return self._delete("/snapshots/%s" % base.getid(snapshot))
if force:
return self._action('os-force_delete', snapshot)
else:
return self._delete("/snapshots/%s" % base.getid(snapshot))
def update(self, snapshot, **kwargs):
"""Update the name or description for a snapshot.