diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index c47bab37c..e1257e2ed 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -22,6 +22,7 @@ from cinderclient import client from cinderclient import exceptions from cinderclient import shell from cinderclient.v2 import volumes +from cinderclient.v2 import volume_backups from cinderclient.v2 import shell as test_shell from cinderclient.tests.unit import utils from cinderclient.tests.unit.v2 import fakes @@ -445,11 +446,13 @@ class ShellTest(utils.TestCase): 'backup-restore 1234 --volume fake_vol --name ' 'restore_vol') + @mock.patch('cinderclient.v3.shell._find_backup') @mock.patch('cinderclient.utils.print_dict') @mock.patch('cinderclient.utils.find_volume') def test_do_backup_restore(self, mock_find_volume, - mock_print_dict): + mock_print_dict, + mock_find_backup): backup_id = '1234' volume_id = '5678' name = None @@ -465,9 +468,16 @@ class ShellTest(utils.TestCase): mock_find_volume.return_value = volumes.Volume(self, {'id': volume_id}, loaded = True) + mock_find_backup.return_value = volume_backups.VolumeBackup( + self, + {'id': backup_id}, + loaded = True) test_shell.do_backup_restore(self.cs, args) + mock_find_backup.assert_called_once_with( + self.cs, + backup_id) mocked_restore.assert_called_once_with( - input['backup'], + backup_id, volume_id, name) self.assertTrue(mock_print_dict.called) diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 2f8900569..24fd7a14f 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -1501,7 +1501,7 @@ def do_backup_delete(cs, args): @utils.arg('backup', metavar='', - help='ID of backup to restore.') + help='Name or ID of backup to restore.') @utils.arg('--volume-id', metavar='', default=None, help=argparse.SUPPRESS) @@ -1530,9 +1530,10 @@ def do_backup_restore(cs, args): else: volume_id = None + backup = _find_backup(cs, args.backup) restore = cs.restores.restore(args.backup, volume_id, args.name) - info = {"backup_id": args.backup} + info = {"backup_id": backup.id} info.update(restore._info) info.pop('links', None)