Show backup and volume info in backup_restore
When no volume is specified in backup_restore command, a new volume is created with specified name. If running the same command several times, several volumes with same name are created, it needs to check logs to find out which volume is latest. This update is to show the returned info from api. Change-Id: I035fc85aa636b716b16c8a543c843ebf4659a96e Closes-Bug: #1472493 Depends-On: I9f5d8ded993fcf1d351d4c65b6806929693b15d6
This commit is contained in:
parent
f860668d71
commit
b426b71d7d
cinderclient
@ -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'
|
||||
|
@ -1238,7 +1238,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>',
|
||||
|
Loading…
x
Reference in New Issue
Block a user