Merge "Changed backup-restore to accept backup name"

This commit is contained in:
Jenkins
2016-08-03 12:34:54 +00:00
committed by Gerrit Code Review
2 changed files with 15 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ from cinderclient import client
from cinderclient import exceptions from cinderclient import exceptions
from cinderclient import shell from cinderclient import shell
from cinderclient.v2 import volumes from cinderclient.v2 import volumes
from cinderclient.v2 import volume_backups
from cinderclient.v2 import shell as test_shell from cinderclient.v2 import shell as test_shell
from cinderclient.tests.unit import utils from cinderclient.tests.unit import utils
from cinderclient.tests.unit.v2 import fakes from cinderclient.tests.unit.v2 import fakes
@@ -445,11 +446,13 @@ class ShellTest(utils.TestCase):
'backup-restore 1234 --volume fake_vol --name ' 'backup-restore 1234 --volume fake_vol --name '
'restore_vol') 'restore_vol')
@mock.patch('cinderclient.v3.shell._find_backup')
@mock.patch('cinderclient.utils.print_dict') @mock.patch('cinderclient.utils.print_dict')
@mock.patch('cinderclient.utils.find_volume') @mock.patch('cinderclient.utils.find_volume')
def test_do_backup_restore(self, def test_do_backup_restore(self,
mock_find_volume, mock_find_volume,
mock_print_dict): mock_print_dict,
mock_find_backup):
backup_id = '1234' backup_id = '1234'
volume_id = '5678' volume_id = '5678'
name = None name = None
@@ -465,9 +468,16 @@ class ShellTest(utils.TestCase):
mock_find_volume.return_value = volumes.Volume(self, mock_find_volume.return_value = volumes.Volume(self,
{'id': volume_id}, {'id': volume_id},
loaded = True) loaded = True)
mock_find_backup.return_value = volume_backups.VolumeBackup(
self,
{'id': backup_id},
loaded = True)
test_shell.do_backup_restore(self.cs, args) 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( mocked_restore.assert_called_once_with(
input['backup'], backup_id,
volume_id, volume_id,
name) name)
self.assertTrue(mock_print_dict.called) self.assertTrue(mock_print_dict.called)

View File

@@ -1511,7 +1511,7 @@ def do_backup_delete(cs, args):
@utils.arg('backup', metavar='<backup>', @utils.arg('backup', metavar='<backup>',
help='ID of backup to restore.') help='Name or ID of backup to restore.')
@utils.arg('--volume-id', metavar='<volume>', @utils.arg('--volume-id', metavar='<volume>',
default=None, default=None,
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
@@ -1540,9 +1540,10 @@ def do_backup_restore(cs, args):
else: else:
volume_id = None volume_id = None
backup = _find_backup(cs, args.backup)
restore = cs.restores.restore(args.backup, volume_id, args.name) 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.update(restore._info)
info.pop('links', None) info.pop('links', None)