Merge "Support for snapshot force delete"
This commit is contained in:
@@ -356,6 +356,8 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
assert 'status' in body['os-reset_status']
|
assert 'status' in body['os-reset_status']
|
||||||
elif action == 'os-update_snapshot_status':
|
elif action == 'os-update_snapshot_status':
|
||||||
assert 'status' in body['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':
|
elif action == 'os-unmanage':
|
||||||
assert body[action] is None
|
assert body[action] is None
|
||||||
else:
|
else:
|
||||||
|
@@ -946,17 +946,44 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
self.assert_called('POST', '/volumes/1234/action', body=expected)
|
||||||
|
|
||||||
def test_snapshot_delete(self):
|
def test_snapshot_delete(self):
|
||||||
|
"""Tests delete snapshot without force parameter"""
|
||||||
self.run_command('snapshot-delete 1234')
|
self.run_command('snapshot-delete 1234')
|
||||||
self.assert_called('DELETE', '/snapshots/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):
|
def test_quota_delete(self):
|
||||||
self.run_command('quota-delete 1234')
|
self.run_command('quota-delete 1234')
|
||||||
self.assert_called('DELETE', '/os-quota-sets/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):
|
def test_volume_manage(self):
|
||||||
self.run_command('manage host1 some_fake_name '
|
self.run_command('manage host1 some_fake_name '
|
||||||
'--name foo --description bar '
|
'--name foo --description bar '
|
||||||
|
@@ -784,13 +784,19 @@ def do_snapshot_create(cs, args):
|
|||||||
@utils.arg('snapshot',
|
@utils.arg('snapshot',
|
||||||
metavar='<snapshot>', nargs='+',
|
metavar='<snapshot>', nargs='+',
|
||||||
help='Name or ID of the snapshot(s) to delete.')
|
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')
|
@utils.service_type('volumev3')
|
||||||
def do_snapshot_delete(cs, args):
|
def do_snapshot_delete(cs, args):
|
||||||
"""Removes one or more snapshots."""
|
"""Removes one or more snapshots."""
|
||||||
failure_count = 0
|
failure_count = 0
|
||||||
|
|
||||||
for snapshot in args.snapshot:
|
for snapshot in args.snapshot:
|
||||||
try:
|
try:
|
||||||
_find_volume_snapshot(cs, snapshot).delete()
|
_find_volume_snapshot(cs, snapshot).delete(args.force)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failure_count += 1
|
failure_count += 1
|
||||||
print("Delete for snapshot %s failed: %s" % (snapshot, e))
|
print("Delete for snapshot %s failed: %s" % (snapshot, e))
|
||||||
|
@@ -25,9 +25,9 @@ class Snapshot(base.Resource):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Snapshot: %s>" % self.id
|
return "<Snapshot: %s>" % self.id
|
||||||
|
|
||||||
def delete(self):
|
def delete(self, force=False):
|
||||||
"""Delete this snapshot."""
|
"""Delete this snapshot."""
|
||||||
return self.manager.delete(self)
|
return self.manager.delete(self, force)
|
||||||
|
|
||||||
def update(self, **kwargs):
|
def update(self, **kwargs):
|
||||||
"""Update the name or description for this snapshot."""
|
"""Update the name or description for this snapshot."""
|
||||||
@@ -118,11 +118,15 @@ class SnapshotManager(base.ManagerWithFind):
|
|||||||
limit=limit, sort=sort)
|
limit=limit, sort=sort)
|
||||||
return self._list(url, resource_type, limit=limit)
|
return self._list(url, resource_type, limit=limit)
|
||||||
|
|
||||||
def delete(self, snapshot):
|
def delete(self, snapshot, force=False):
|
||||||
"""Delete a snapshot.
|
"""Delete a snapshot.
|
||||||
|
|
||||||
:param snapshot: The :class:`Snapshot` to delete.
|
:param snapshot: The :class:`Snapshot` to delete.
|
||||||
|
:param force: Allow delete in state other than error or available.
|
||||||
"""
|
"""
|
||||||
|
if force:
|
||||||
|
return self._action('os-force_delete', snapshot)
|
||||||
|
else:
|
||||||
return self._delete("/snapshots/%s" % base.getid(snapshot))
|
return self._delete("/snapshots/%s" % base.getid(snapshot))
|
||||||
|
|
||||||
def update(self, snapshot, **kwargs):
|
def update(self, snapshot, **kwargs):
|
||||||
|
Reference in New Issue
Block a user