Changed backup-restore to accept backup name

Edited do_backup_restore function to accept the name of the backup
as well as its id. Changed the test to comply with this.

DocImpact

Closes-Bug: #1604892

Change-Id: Iaec69dd053a119366fa5a8437701a6f7c3da2235
This commit is contained in:
Ellen Leahy
2016-07-20 17:48:01 +01:00
parent 3722a2a9d5
commit 2b0bd49b24
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

@@ -1501,7 +1501,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)
@@ -1530,9 +1530,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)