From a3dca1599f1fe7add715a4d78318a7583941cd26 Mon Sep 17 00:00:00 2001 From: Shilpa Jagannath Date: Tue, 9 Feb 2016 21:10:00 +0530 Subject: [PATCH] Allow "cinder backup-delete" to delete multiple backups in one request While "cinder snapshot-delete" and "cinder delete" allow multiple resources to be deleted in a single command, "cinder backup-delete" request can only delete one backup at a time. Adding this capability to backups in cinderclient. Enables "cinder backup-delete" to delete multiple backups in a single command. With this change the command can be run as below: cinder backup-delete [...] DocImpact Closes-Bug: #1543056 Implements: blueprint cli-backup-multiple-deletes Change-Id: I767710bda3b7c358c6525c9a9f074010084e411d --- cinderclient/tests/unit/v2/fakes.py | 6 ++++++ cinderclient/tests/unit/v2/test_shell.py | 5 +++++ cinderclient/v2/shell.py | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py index b787e2da6..07af4158d 100644 --- a/cinderclient/tests/unit/v2/fakes.py +++ b/cinderclient/tests/unit/v2/fakes.py @@ -806,6 +806,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='',