Merge "Support name option for volume restore"
This commit is contained in:
@@ -434,6 +434,17 @@ class ShellTest(utils.TestCase):
|
|||||||
self.run_command('backup-restore 1234')
|
self.run_command('backup-restore 1234')
|
||||||
self.assert_called('POST', '/backups/1234/restore')
|
self.assert_called('POST', '/backups/1234/restore')
|
||||||
|
|
||||||
|
def test_restore_with_name(self):
|
||||||
|
self.run_command('backup-restore 1234 --name restore_vol')
|
||||||
|
expected = {'restore': {'volume_id': None, 'name': 'restore_vol'}}
|
||||||
|
self.assert_called('POST', '/backups/1234/restore',
|
||||||
|
body=expected)
|
||||||
|
|
||||||
|
def test_restore_with_name_error(self):
|
||||||
|
self.assertRaises(exceptions.CommandError, self.run_command,
|
||||||
|
'backup-restore 1234 --volume fake_vol --name '
|
||||||
|
'restore_vol')
|
||||||
|
|
||||||
@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,
|
||||||
@@ -441,9 +452,11 @@ class ShellTest(utils.TestCase):
|
|||||||
mock_print_dict):
|
mock_print_dict):
|
||||||
backup_id = '1234'
|
backup_id = '1234'
|
||||||
volume_id = '5678'
|
volume_id = '5678'
|
||||||
|
name = None
|
||||||
input = {
|
input = {
|
||||||
'backup': backup_id,
|
'backup': backup_id,
|
||||||
'volume': volume_id
|
'volume': volume_id,
|
||||||
|
'name': None
|
||||||
}
|
}
|
||||||
|
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -455,7 +468,8 @@ class ShellTest(utils.TestCase):
|
|||||||
test_shell.do_backup_restore(self.cs, args)
|
test_shell.do_backup_restore(self.cs, args)
|
||||||
mocked_restore.assert_called_once_with(
|
mocked_restore.assert_called_once_with(
|
||||||
input['backup'],
|
input['backup'],
|
||||||
volume_id)
|
volume_id,
|
||||||
|
name)
|
||||||
self.assertTrue(mock_print_dict.called)
|
self.assertTrue(mock_print_dict.called)
|
||||||
|
|
||||||
def test_record_export(self):
|
def test_record_export(self):
|
||||||
|
@@ -126,6 +126,16 @@ class VolumeBackupsTest(utils.TestCase):
|
|||||||
volume_backups_restore.VolumeBackupsRestore)
|
volume_backups_restore.VolumeBackupsRestore)
|
||||||
self._assert_request_id(info)
|
self._assert_request_id(info)
|
||||||
|
|
||||||
|
def test_restore_with_name(self):
|
||||||
|
backup_id = '76a17945-3c6f-435c-975b-b5685db10b62'
|
||||||
|
name = 'restore_vol'
|
||||||
|
info = cs.restores.restore(backup_id, name=name)
|
||||||
|
expected_body = {'restore': {'volume_id': None, 'name': name}}
|
||||||
|
cs.assert_called('POST', '/backups/%s/restore' % backup_id,
|
||||||
|
body=expected_body)
|
||||||
|
self.assertIsInstance(info,
|
||||||
|
volume_backups_restore.VolumeBackupsRestore)
|
||||||
|
|
||||||
def test_reset_state(self):
|
def test_reset_state(self):
|
||||||
b = cs.backups.list()[0]
|
b = cs.backups.list()[0]
|
||||||
api = '/backups/76a17945-3c6f-435c-975b-b5685db10b62/action'
|
api = '/backups/76a17945-3c6f-435c-975b-b5685db10b62/action'
|
||||||
|
@@ -1507,7 +1507,14 @@ def do_backup_delete(cs, args):
|
|||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
@utils.arg('--volume', metavar='<volume>',
|
@utils.arg('--volume', metavar='<volume>',
|
||||||
default=None,
|
default=None,
|
||||||
help='Name or ID of volume to which to restore. '
|
help='Name or ID of existing volume to which to restore. '
|
||||||
|
'This is mutually exclusive with --name and takes priority. '
|
||||||
|
'Default=None.')
|
||||||
|
@utils.arg('--name', metavar='<name>',
|
||||||
|
default=None,
|
||||||
|
help='Use the name for new volume creation to restore. '
|
||||||
|
'This is mutually exclusive with --volume (or the deprecated '
|
||||||
|
'--volume-id) and --volume (or --volume-id) takes priority. '
|
||||||
'Default=None.')
|
'Default=None.')
|
||||||
@utils.service_type('volumev3')
|
@utils.service_type('volumev3')
|
||||||
def do_backup_restore(cs, args):
|
def do_backup_restore(cs, args):
|
||||||
@@ -1515,10 +1522,15 @@ def do_backup_restore(cs, args):
|
|||||||
vol = args.volume or args.volume_id
|
vol = args.volume or args.volume_id
|
||||||
if vol:
|
if vol:
|
||||||
volume_id = utils.find_volume(cs, vol).id
|
volume_id = utils.find_volume(cs, vol).id
|
||||||
|
if args.name:
|
||||||
|
args.name = None
|
||||||
|
print('Mutually exclusive options are specified simultaneously: '
|
||||||
|
'"--volume (or the deprecated --volume-id) and --name". '
|
||||||
|
'The --volume (or --volume-id) option takes priority.')
|
||||||
else:
|
else:
|
||||||
volume_id = None
|
volume_id = None
|
||||||
|
|
||||||
restore = cs.restores.restore(args.backup, volume_id)
|
restore = cs.restores.restore(args.backup, volume_id, args.name)
|
||||||
|
|
||||||
info = {"backup_id": args.backup}
|
info = {"backup_id": args.backup}
|
||||||
info.update(restore._info)
|
info.update(restore._info)
|
||||||
|
@@ -31,13 +31,14 @@ class VolumeBackupRestoreManager(base.Manager):
|
|||||||
"""Manage :class:`VolumeBackupsRestore` resources."""
|
"""Manage :class:`VolumeBackupsRestore` resources."""
|
||||||
resource_class = VolumeBackupsRestore
|
resource_class = VolumeBackupsRestore
|
||||||
|
|
||||||
def restore(self, backup_id, volume_id=None):
|
def restore(self, backup_id, volume_id=None, name=None):
|
||||||
"""Restore a backup to a volume.
|
"""Restore a backup to a volume.
|
||||||
|
|
||||||
:param backup_id: The ID of the backup to restore.
|
:param backup_id: The ID of the backup to restore.
|
||||||
:param volume_id: The ID of the volume to restore the backup to.
|
:param volume_id: The ID of the volume to restore the backup to.
|
||||||
|
:param name : The name for new volume creation to restore.
|
||||||
:rtype: :class:`Restore`
|
:rtype: :class:`Restore`
|
||||||
"""
|
"""
|
||||||
body = {'restore': {'volume_id': volume_id}}
|
body = {'restore': {'volume_id': volume_id, 'name': name}}
|
||||||
return self._create("/backups/%s/restore" % backup_id,
|
return self._create("/backups/%s/restore" % backup_id,
|
||||||
body, "restore")
|
body, "restore")
|
||||||
|
Reference in New Issue
Block a user