Merge "Backup create is not available from 3.0 to 3.42"
This commit is contained in:
@@ -1035,13 +1035,31 @@ class ShellTest(utils.TestCase):
|
||||
mock_time.sleep.call_args_list)
|
||||
self.assertEqual([mock.call(some_id)] * 2, poll_fn.call_args_list)
|
||||
|
||||
def test_backup(self):
|
||||
self.run_command('--os-volume-api-version 3.42 backup-create '
|
||||
'--name 1234 1234')
|
||||
expected = {'backup': {'volume_id': 1234,
|
||||
'container': None,
|
||||
'name': '1234',
|
||||
'description': None,
|
||||
'incremental': False,
|
||||
'force': False,
|
||||
'snapshot_id': None,
|
||||
}}
|
||||
self.assert_called('POST', '/backups', body=expected)
|
||||
|
||||
def test_backup_with_metadata(self):
|
||||
cmd = '--os-volume-api-version 3.43 '
|
||||
cmd += 'backup-create '
|
||||
cmd += '--metadata foo=bar '
|
||||
cmd += '1234'
|
||||
self.run_command(cmd)
|
||||
self.assert_called('POST', '/backups')
|
||||
self.run_command('--os-volume-api-version 3.43 backup-create '
|
||||
'--metadata foo=bar --name 1234 1234')
|
||||
expected = {'backup': {'volume_id': 1234,
|
||||
'container': None,
|
||||
'name': '1234',
|
||||
'description': None,
|
||||
'incremental': False,
|
||||
'force': False,
|
||||
'snapshot_id': None,
|
||||
'metadata': {'foo': 'bar'}, }}
|
||||
self.assert_called('POST', '/backups', body=expected)
|
||||
|
||||
@mock.patch("cinderclient.utils.print_list")
|
||||
def test_snapshot_list_with_userid(self, mock_print_list):
|
||||
|
@@ -2220,7 +2220,7 @@ def do_service_get_log(cs, args):
|
||||
columns = ('Binary', 'Host', 'Prefix', 'Level')
|
||||
utils.print_list(log_levels, columns)
|
||||
|
||||
@api_versions.wraps('3.43')
|
||||
|
||||
@utils.arg('volume', metavar='<volume>',
|
||||
help='Name or ID of volume to backup.')
|
||||
@utils.arg('--container', metavar='<container>',
|
||||
@@ -2258,6 +2258,7 @@ def do_service_get_log(cs, args):
|
||||
nargs='*',
|
||||
metavar='<key=value>',
|
||||
default=None,
|
||||
start_version='3.43',
|
||||
help='Metadata key and value pairs. Default=None.')
|
||||
def do_backup_create(cs, args):
|
||||
"""Creates a volume backup."""
|
||||
@@ -2268,14 +2269,23 @@ def do_backup_create(cs, args):
|
||||
args.description = args.display_description
|
||||
|
||||
volume = utils.find_volume(cs, args.volume)
|
||||
backup = cs.backups.create(volume.id,
|
||||
args.container,
|
||||
args.name,
|
||||
args.description,
|
||||
args.incremental,
|
||||
args.force,
|
||||
args.snapshot_id,
|
||||
args.metadata)
|
||||
if hasattr(args, 'metadata') and args.metadata:
|
||||
backup = cs.backups.create(volume.id,
|
||||
args.container,
|
||||
args.name,
|
||||
args.description,
|
||||
args.incremental,
|
||||
args.force,
|
||||
args.snapshot_id,
|
||||
shell_utils.extract_metadata(args))
|
||||
else:
|
||||
backup = cs.backups.create(volume.id,
|
||||
args.container,
|
||||
args.name,
|
||||
args.description,
|
||||
args.incremental,
|
||||
args.force,
|
||||
args.snapshot_id)
|
||||
|
||||
info = {"volume_id": volume.id}
|
||||
info.update(backup._info)
|
||||
|
@@ -39,7 +39,31 @@ class VolumeBackupManager(volume_backups.VolumeBackupManager):
|
||||
|
||||
return self._update("/backups/%s" % base.getid(backup), body)
|
||||
|
||||
@api_versions.wraps("3.43")
|
||||
@api_versions.wraps("3.0")
|
||||
def create(self, volume_id, container=None,
|
||||
name=None, description=None,
|
||||
incremental=False, force=False,
|
||||
snapshot_id=None):
|
||||
"""Creates a volume backup.
|
||||
|
||||
:param volume_id: The ID of the volume to backup.
|
||||
:param container: The name of the backup service container.
|
||||
:param name: The name of the backup.
|
||||
:param description: The description of the backup.
|
||||
:param incremental: Incremental backup.
|
||||
:param force: If True, allows an in-use volume to be backed up.
|
||||
:rtype: :class:`VolumeBackup`
|
||||
"""
|
||||
body = {'backup': {'volume_id': volume_id,
|
||||
'container': container,
|
||||
'name': name,
|
||||
'description': description,
|
||||
'incremental': incremental,
|
||||
'force': force,
|
||||
'snapshot_id': snapshot_id, }}
|
||||
return self._create('/backups', body, 'backup')
|
||||
|
||||
@api_versions.wraps("3.43") # noqa: F811
|
||||
def create(self, volume_id, container=None,
|
||||
name=None, description=None,
|
||||
incremental=False, force=False,
|
||||
@@ -56,6 +80,7 @@ class VolumeBackupManager(volume_backups.VolumeBackupManager):
|
||||
:param metadata: Key Value pairs
|
||||
:rtype: :class:`VolumeBackup`
|
||||
"""
|
||||
# pylint: disable=function-redefined
|
||||
body = {'backup': {'volume_id': volume_id,
|
||||
'container': container,
|
||||
'name': name,
|
||||
|
Reference in New Issue
Block a user