From c4ae3dd7a5edcab3050e13c89746ef121ff8518b Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Tue, 15 Oct 2013 18:09:42 +0100 Subject: [PATCH] Fixes broken v1 and v2 api backup-restore Also adds unit tests. Change-Id: I741889d49cffe46bf9165b266a62f2b328354e01 Fixes: bug 1240151 --- cinderclient/tests/v1/fakes.py | 4 ++++ cinderclient/tests/v1/test_shell.py | 8 ++++++++ cinderclient/tests/v2/fakes.py | 4 ++++ cinderclient/tests/v2/test_shell.py | 8 ++++++++ cinderclient/v1/shell.py | 4 ++-- cinderclient/v2/shell.py | 4 ++-- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index cea11a37d..5e2ab26e0 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -533,6 +533,10 @@ class FakeHTTPClient(base_client.HTTPClient): return (200, {}, {'restore': _stub_restore()}) + def post_backups_1234_restore(self, **kw): + return (200, {}, + {'restore': _stub_restore()}) + # # QoSSpecs # diff --git a/cinderclient/tests/v1/test_shell.py b/cinderclient/tests/v1/test_shell.py index a79c413bf..26571da1b 100644 --- a/cinderclient/tests/v1/test_shell.py +++ b/cinderclient/tests/v1/test_shell.py @@ -117,6 +117,14 @@ class ShellTest(utils.TestCase): self.run_command('delete 1234') self.assert_called('DELETE', '/volumes/1234') + def test_backup(self): + self.run_command('backup-create 1234') + self.assert_called('POST', '/backups') + + def test_restore(self): + self.run_command('backup-restore 1234') + self.assert_called('POST', '/backups/1234/restore') + def test_snapshot_list_filter_volume_id(self): self.run_command('snapshot-list --volume-id=1234') self.assert_called('GET', '/snapshots/detail?volume_id=1234') diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index f8485126d..e90da80ef 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -540,6 +540,10 @@ class FakeHTTPClient(base_client.HTTPClient): return (200, {}, {'restore': _stub_restore()}) + def post_backups_1234_restore(self, **kw): + return (200, {}, + {'restore': _stub_restore()}) + # # QoSSpecs # diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py index f18e39d5c..566f620c7 100644 --- a/cinderclient/tests/v2/test_shell.py +++ b/cinderclient/tests/v2/test_shell.py @@ -95,6 +95,14 @@ class ShellTest(utils.TestCase): self.run_command('delete 1234') self.assert_called('DELETE', '/volumes/1234') + def test_backup(self): + self.run_command('backup-create 1234') + self.assert_called('POST', '/backups') + + def test_restore(self): + self.run_command('backup-restore 1234') + self.assert_called('POST', '/backups/1234/restore') + def test_snapshot_list_filter_volume_id(self): self.run_command('snapshot-list --volume-id=1234') self.assert_called('GET', '/snapshots/detail?volume_id=1234') diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 74f86626a..e0658d576 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -812,8 +812,8 @@ def do_backup_delete(cs, args): @utils.service_type('volume') def do_backup_restore(cs, args): """Restore a backup.""" - if args.volume: - volume_id = utils.find_volume(cs, args.volume).id + if args.volume_id: + volume_id = utils.find_volume(cs, args.volume_id).id else: volume_id = None cs.restores.restore(args.backup, volume_id) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 6ce4e8778..3ee4bb6a3 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -903,8 +903,8 @@ def do_backup_delete(cs, args): @utils.service_type('volumev2') def do_backup_restore(cs, args): """Restore a backup.""" - if args.volume: - volume_id = utils.find_volume(cs, args.volume).id + if args.volume_id: + volume_id = utils.find_volume(cs, args.volume_id).id else: volume_id = None cs.restores.restore(args.backup, volume_id)