Merge "Support for cinder backup force delete"
This commit is contained in:
commit
1aa45d8474
cinderclient
@ -92,6 +92,32 @@ class VolumeBackupsTest(utils.TestCase):
|
|||||||
'/backups/76a17945-3c6f-435c-975b-b5685db10b62')
|
'/backups/76a17945-3c6f-435c-975b-b5685db10b62')
|
||||||
self._assert_request_id(del_back)
|
self._assert_request_id(del_back)
|
||||||
|
|
||||||
|
def test_force_delete_with_True_force_param_value(self):
|
||||||
|
"""Tests delete backup with force parameter set to True"""
|
||||||
|
b = cs.backups.list()[0]
|
||||||
|
del_back = b.delete(force=True)
|
||||||
|
expected_body = {'os-force_delete': None}
|
||||||
|
cs.assert_called('POST',
|
||||||
|
'/backups/76a17945-3c6f-435c-975b-b5685db10b62/action',
|
||||||
|
expected_body)
|
||||||
|
self._assert_request_id(del_back)
|
||||||
|
|
||||||
|
def test_force_delete_with_false_force_param_vaule(self):
|
||||||
|
"""To delete backup with force parameter set to False"""
|
||||||
|
b = cs.backups.list()[0]
|
||||||
|
del_back = b.delete(force=False)
|
||||||
|
cs.assert_called('DELETE',
|
||||||
|
'/backups/76a17945-3c6f-435c-975b-b5685db10b62')
|
||||||
|
self._assert_request_id(del_back)
|
||||||
|
del_back = cs.backups.delete('76a17945-3c6f-435c-975b-b5685db10b62')
|
||||||
|
cs.assert_called('DELETE',
|
||||||
|
'/backups/76a17945-3c6f-435c-975b-b5685db10b62')
|
||||||
|
self._assert_request_id(del_back)
|
||||||
|
del_back = cs.backups.delete(b)
|
||||||
|
cs.assert_called('DELETE',
|
||||||
|
'/backups/76a17945-3c6f-435c-975b-b5685db10b62')
|
||||||
|
self._assert_request_id(del_back)
|
||||||
|
|
||||||
def test_restore(self):
|
def test_restore(self):
|
||||||
backup_id = '76a17945-3c6f-435c-975b-b5685db10b62'
|
backup_id = '76a17945-3c6f-435c-975b-b5685db10b62'
|
||||||
info = cs.restores.restore(backup_id)
|
info = cs.restores.restore(backup_id)
|
||||||
|
@ -1472,6 +1472,11 @@ def do_backup_list(cs, args):
|
|||||||
utils.print_list(backups, columns, sortby_index=sortby_index)
|
utils.print_list(backups, columns, sortby_index=sortby_index)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--force',
|
||||||
|
action="store_true",
|
||||||
|
help='Allows deleting backup of a volume '
|
||||||
|
'when its status is other than "available" or "error". '
|
||||||
|
'Default=False.')
|
||||||
@utils.arg('backup', metavar='<backup>', nargs='+',
|
@utils.arg('backup', metavar='<backup>', nargs='+',
|
||||||
help='Name or ID of backup(s) to delete.')
|
help='Name or ID of backup(s) to delete.')
|
||||||
@utils.service_type('volumev3')
|
@utils.service_type('volumev3')
|
||||||
@ -1480,7 +1485,7 @@ def do_backup_delete(cs, args):
|
|||||||
failure_count = 0
|
failure_count = 0
|
||||||
for backup in args.backup:
|
for backup in args.backup:
|
||||||
try:
|
try:
|
||||||
_find_backup(cs, backup).delete()
|
_find_backup(cs, backup).delete(args.force)
|
||||||
print("Request to delete backup %s has been accepted." % (backup))
|
print("Request to delete backup %s has been accepted." % (backup))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failure_count += 1
|
failure_count += 1
|
||||||
|
@ -26,9 +26,9 @@ class VolumeBackup(base.Resource):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<VolumeBackup: %s>" % self.id
|
return "<VolumeBackup: %s>" % self.id
|
||||||
|
|
||||||
def delete(self):
|
def delete(self, force=False):
|
||||||
"""Delete this volume backup."""
|
"""Delete this volume backup."""
|
||||||
return self.manager.delete(self)
|
return self.manager.delete(self, force)
|
||||||
|
|
||||||
def reset_state(self, state):
|
def reset_state(self, state):
|
||||||
return self.manager.reset_state(self, state)
|
return self.manager.reset_state(self, state)
|
||||||
@ -81,12 +81,16 @@ class VolumeBackupManager(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, backup):
|
def delete(self, backup, force=False):
|
||||||
"""Delete a volume backup.
|
"""Delete a volume backup.
|
||||||
|
|
||||||
:param backup: The :class:`VolumeBackup` to delete.
|
:param backup: The :class:`VolumeBackup` to delete.
|
||||||
|
:param force: Allow delete in state other than error or available.
|
||||||
"""
|
"""
|
||||||
return self._delete("/backups/%s" % base.getid(backup))
|
if force:
|
||||||
|
return self._action('os-force_delete', backup)
|
||||||
|
else:
|
||||||
|
return self._delete("/backups/%s" % base.getid(backup))
|
||||||
|
|
||||||
def reset_state(self, backup, state):
|
def reset_state(self, backup, state):
|
||||||
"""Update the specified volume backup with the provided state."""
|
"""Update the specified volume backup with the provided state."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user