diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py index ffed52e8f..a11eb7c06 100644 --- a/cinderclient/tests/unit/v2/fakes.py +++ b/cinderclient/tests/unit/v2/fakes.py @@ -811,6 +811,12 @@ class FakeHTTPClient(base_client.HTTPClient): def delete_backups_76a17945_3c6f_435c_975b_b5685db10b62(self, **kw): return (202, {}, None) + def delete_backups_1234(self, **kw): + return (202, {}, None) + + def delete_backups_5678(self, **kw): + return (202, {}, None) + def post_backups(self, **kw): base_uri = 'http://localhost:8776' tenant_id = '0fa851f6668144cf9cd8c8419c1646c1' diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 75239c92d..03f25f689 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -415,6 +415,11 @@ class ShellTest(utils.TestCase): self.run_command('backup-create 1234 --snapshot-id 4321') self.assert_called('POST', '/backups') + def test_multiple_backup_delete(self): + self.run_command('backup-delete 1234 5678') + self.assert_called_anytime('DELETE', '/backups/1234') + self.assert_called('DELETE', '/backups/5678') + def test_restore(self): self.run_command('backup-restore 1234') self.assert_called('POST', '/backups/1234/restore') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 6bcbd4476..b7b01d4a6 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1472,13 +1472,22 @@ def do_backup_list(cs, args): utils.print_list(backups, columns) -@utils.arg('backup', metavar='', - help='Name or ID of backup to delete.') +@utils.arg('backup', metavar='', nargs='+', + help='Name or ID of backup(s) to delete.') @utils.service_type('volumev2') def do_backup_delete(cs, args): - """Removes a backup.""" - backup = _find_backup(cs, args.backup) - backup.delete() + """Removes one or more backups.""" + failure_count = 0 + for backup in args.backup: + try: + _find_backup(cs, backup).delete() + print("Request to delete backup %s has been accepted." % (backup)) + except Exception as e: + failure_count += 1 + print("Delete for backup %s failed: %s" % (backup, e)) + if failure_count == len(args.backup): + raise exceptions.CommandError("Unable to delete any of the specified " + "backups.") @utils.arg('backup', metavar='',