Add "--snapshot" option to "backup create" command in volumev2
Add "--snapshot" option to "backup create" command to support backing up a snapshot. Change-Id: Ibecbf1902599875f422d372d529835f73211d3ec Closes-Bug: #1597184
This commit is contained in:
parent
4b61efe3f9
commit
6364df4cbd
@ -31,6 +31,10 @@ Create new backup
|
||||
|
||||
Description of the backup
|
||||
|
||||
.. option:: --snapshot <snapshot>
|
||||
|
||||
Snapshot to backup (name or ID)
|
||||
|
||||
.. option:: --force
|
||||
|
||||
Allow to back up an in-use volume
|
||||
|
@ -403,6 +403,7 @@ class FakeBackup(object):
|
||||
"id": 'backup-id-' + uuid.uuid4().hex,
|
||||
"name": 'backup-name-' + uuid.uuid4().hex,
|
||||
"volume_id": 'volume-id-' + uuid.uuid4().hex,
|
||||
"snapshot_id": 'snapshot-id' + uuid.uuid4().hex,
|
||||
"description": 'description-' + uuid.uuid4().hex,
|
||||
"object_count": None,
|
||||
"container": 'container-' + uuid.uuid4().hex,
|
||||
|
@ -25,6 +25,8 @@ class TestBackup(volume_fakes.TestVolume):
|
||||
self.backups_mock.reset_mock()
|
||||
self.volumes_mock = self.app.client_manager.volume.volumes
|
||||
self.volumes_mock.reset_mock()
|
||||
self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
|
||||
self.snapshots_mock.reset_mock()
|
||||
self.restores_mock = self.app.client_manager.volume.restores
|
||||
self.restores_mock.reset_mock()
|
||||
|
||||
@ -32,8 +34,9 @@ class TestBackup(volume_fakes.TestVolume):
|
||||
class TestBackupCreate(TestBackup):
|
||||
|
||||
volume = volume_fakes.FakeVolume.create_one_volume()
|
||||
snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
|
||||
new_backup = volume_fakes.FakeBackup.create_one_backup(
|
||||
attrs={'volume_id': volume.id})
|
||||
attrs={'volume_id': volume.id, 'snapshot_id': snapshot.id})
|
||||
|
||||
columns = (
|
||||
'availability_zone',
|
||||
@ -43,6 +46,7 @@ class TestBackupCreate(TestBackup):
|
||||
'name',
|
||||
'object_count',
|
||||
'size',
|
||||
'snapshot_id',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
@ -54,6 +58,7 @@ class TestBackupCreate(TestBackup):
|
||||
new_backup.name,
|
||||
new_backup.object_count,
|
||||
new_backup.size,
|
||||
new_backup.snapshot_id,
|
||||
new_backup.status,
|
||||
new_backup.volume_id,
|
||||
)
|
||||
@ -62,6 +67,7 @@ class TestBackupCreate(TestBackup):
|
||||
super(TestBackupCreate, self).setUp()
|
||||
|
||||
self.volumes_mock.get.return_value = self.volume
|
||||
self.snapshots_mock.get.return_value = self.snapshot
|
||||
self.backups_mock.create.return_value = self.new_backup
|
||||
|
||||
# Get the command object to test
|
||||
@ -73,6 +79,7 @@ class TestBackupCreate(TestBackup):
|
||||
"--description", self.new_backup.description,
|
||||
"--container", self.new_backup.container,
|
||||
"--force",
|
||||
"--snapshot", self.new_backup.snapshot_id,
|
||||
self.new_backup.volume_id,
|
||||
]
|
||||
verifylist = [
|
||||
@ -80,6 +87,7 @@ class TestBackupCreate(TestBackup):
|
||||
("description", self.new_backup.description),
|
||||
("container", self.new_backup.container),
|
||||
("force", True),
|
||||
("snapshot", self.new_backup.snapshot_id),
|
||||
("volume", self.new_backup.volume_id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
@ -92,6 +100,7 @@ class TestBackupCreate(TestBackup):
|
||||
name=self.new_backup.name,
|
||||
description=self.new_backup.description,
|
||||
force=True,
|
||||
snapshot_id=self.new_backup.snapshot_id,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
@ -117,6 +126,7 @@ class TestBackupCreate(TestBackup):
|
||||
name=None,
|
||||
description=self.new_backup.description,
|
||||
force=False,
|
||||
snapshot_id=None,
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
@ -264,6 +274,7 @@ class TestBackupShow(TestBackup):
|
||||
'name',
|
||||
'object_count',
|
||||
'size',
|
||||
'snapshot_id',
|
||||
'status',
|
||||
'volume_id',
|
||||
)
|
||||
@ -275,6 +286,7 @@ class TestBackupShow(TestBackup):
|
||||
backup.name,
|
||||
backup.object_count,
|
||||
backup.size,
|
||||
backup.snapshot_id,
|
||||
backup.status,
|
||||
backup.volume_id,
|
||||
)
|
||||
|
@ -48,6 +48,11 @@ class CreateBackup(command.ShowOne):
|
||||
metavar="<container>",
|
||||
help=_("Optional backup container name")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--snapshot",
|
||||
metavar="<snapshot>",
|
||||
help=_("Snapshot to backup (name or ID)")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--force',
|
||||
action='store_true',
|
||||
@ -60,12 +65,17 @@ class CreateBackup(command.ShowOne):
|
||||
volume_client = self.app.client_manager.volume
|
||||
volume_id = utils.find_resource(
|
||||
volume_client.volumes, parsed_args.volume).id
|
||||
snapshot_id = None
|
||||
if parsed_args.snapshot:
|
||||
snapshot_id = utils.find_resource(
|
||||
volume_client.volume_snapshots, parsed_args.snapshot).id
|
||||
backup = volume_client.backups.create(
|
||||
volume_id,
|
||||
container=parsed_args.container,
|
||||
name=parsed_args.name,
|
||||
description=parsed_args.description,
|
||||
force=parsed_args.force,
|
||||
snapshot_id=snapshot_id,
|
||||
)
|
||||
backup._info.pop("links", None)
|
||||
return zip(*sorted(six.iteritems(backup._info)))
|
||||
|
5
releasenotes/notes/bug-1597184-f4fb687b3d4d99d9.yaml
Normal file
5
releasenotes/notes/bug-1597184-f4fb687b3d4d99d9.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--snapshot`` option to ``backup create`` command.
|
||||
[Bug `1597184 <https://bugs.launchpad.net/bugs/1597184>`_]
|
Loading…
Reference in New Issue
Block a user