Merge "Show backup and volume info in backup_restore"
This commit is contained in:
@@ -21,6 +21,8 @@ from six.moves.urllib import parse
|
||||
from cinderclient import client
|
||||
from cinderclient import exceptions
|
||||
from cinderclient import shell
|
||||
from cinderclient.v2 import volumes
|
||||
from cinderclient.v2 import shell as test_shell
|
||||
from cinderclient.tests.unit import utils
|
||||
from cinderclient.tests.unit.v2 import fakes
|
||||
from cinderclient.tests.unit.fixture_data import keystone_client
|
||||
@@ -55,6 +57,15 @@ class ShellTest(utils.TestCase):
|
||||
'GET', keystone_client.BASE_URL,
|
||||
text=keystone_client.keystone_request_callback)
|
||||
|
||||
self.cs = mock.Mock()
|
||||
|
||||
def _make_args(self, args):
|
||||
class Args(object):
|
||||
def __init__(self, entries):
|
||||
self.__dict__.update(entries)
|
||||
|
||||
return Args(args)
|
||||
|
||||
def tearDown(self):
|
||||
# For some methods like test_image_meta_bad_action we are
|
||||
# testing a SystemExit to be thrown and object self.shell has
|
||||
@@ -363,6 +374,30 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command('backup-restore 1234')
|
||||
self.assert_called('POST', '/backups/1234/restore')
|
||||
|
||||
@mock.patch('cinderclient.utils.print_dict')
|
||||
@mock.patch('cinderclient.utils.find_volume')
|
||||
def test_do_backup_restore(self,
|
||||
mock_find_volume,
|
||||
mock_print_dict):
|
||||
backup_id = '1234'
|
||||
volume_id = '5678'
|
||||
input = {
|
||||
'backup': backup_id,
|
||||
'volume': volume_id
|
||||
}
|
||||
|
||||
args = self._make_args(input)
|
||||
with mock.patch.object(self.cs.restores,
|
||||
'restore') as mocked_restore:
|
||||
mock_find_volume.return_value = volumes.Volume(self,
|
||||
{'id': volume_id},
|
||||
loaded = True)
|
||||
test_shell.do_backup_restore(self.cs, args)
|
||||
mocked_restore.assert_called_once_with(
|
||||
input['backup'],
|
||||
volume_id)
|
||||
self.assertTrue(mock_print_dict.called)
|
||||
|
||||
def test_record_export(self):
|
||||
self.run_command('backup-export 1234')
|
||||
self.assert_called('GET', '/backups/1234/export_record')
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
from cinderclient.tests.unit import utils
|
||||
from cinderclient.tests.unit.v2 import fakes
|
||||
from cinderclient.v2 import volume_backups_restore
|
||||
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
@@ -59,8 +60,10 @@ class VolumeBackupsTest(utils.TestCase):
|
||||
|
||||
def test_restore(self):
|
||||
backup_id = '76a17945-3c6f-435c-975b-b5685db10b62'
|
||||
cs.restores.restore(backup_id)
|
||||
info = cs.restores.restore(backup_id)
|
||||
cs.assert_called('POST', '/backups/%s/restore' % backup_id)
|
||||
self.assertIsInstance(info,
|
||||
volume_backups_restore.VolumeBackupsRestore)
|
||||
|
||||
def test_record_export(self):
|
||||
backup_id = '76a17945-3c6f-435c-975b-b5685db10b62'
|
||||
|
||||
@@ -1300,7 +1300,15 @@ def do_backup_restore(cs, args):
|
||||
volume_id = utils.find_volume(cs, vol).id
|
||||
else:
|
||||
volume_id = None
|
||||
cs.restores.restore(args.backup, volume_id)
|
||||
|
||||
restore = cs.restores.restore(args.backup, volume_id)
|
||||
|
||||
info = {"backup_id": args.backup}
|
||||
info.update(restore._info)
|
||||
|
||||
info.pop('links', None)
|
||||
|
||||
utils.print_dict(info)
|
||||
|
||||
|
||||
@utils.arg('backup', metavar='<backup>',
|
||||
|
||||
Reference in New Issue
Block a user