various fixes for snapshots
Change-Id: I5d399a34d6b68267063966b0b601bcbaacfcc461
This commit is contained in:
parent
764bbcf8b3
commit
08508cc252
@ -61,7 +61,8 @@ def delete_snapshot(context, snapshot_id):
|
|||||||
cinder.volume_snapshots.delete(snapshot['os_id'])
|
cinder.volume_snapshots.delete(snapshot['os_id'])
|
||||||
except cinder_exception.NotFound:
|
except cinder_exception.NotFound:
|
||||||
pass
|
pass
|
||||||
db_api.delete_item(context, snapshot['id'])
|
# NOTE(andrey-mp) Don't delete item from DB until it disappears from Cloud
|
||||||
|
# It will be deleted by describer in the future
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -122,11 +123,18 @@ def _format_snapshot(context, snapshot, os_snapshot, volumes={},
|
|||||||
context, 'vol', os_snapshot.volume_id, volumes)
|
context, 'vol', os_snapshot.volume_id, volumes)
|
||||||
volume_id = volume['id']
|
volume_id = volume['id']
|
||||||
|
|
||||||
|
# NOTE(andrey-mp): ownerId and progress are empty in just created snapshot
|
||||||
|
ownerId = os_snapshot.project_id
|
||||||
|
if not ownerId:
|
||||||
|
ownerId = context.project_id
|
||||||
|
progress = os_snapshot.progress
|
||||||
|
if not progress:
|
||||||
|
progress = '0%'
|
||||||
return {'snapshotId': snapshot['id'],
|
return {'snapshotId': snapshot['id'],
|
||||||
'volumeId': volume_id,
|
'volumeId': volume_id,
|
||||||
'status': mapped_status,
|
'status': mapped_status,
|
||||||
'startTime': os_snapshot.created_at,
|
'startTime': os_snapshot.created_at,
|
||||||
'progress': os_snapshot.progress,
|
'progress': progress,
|
||||||
'ownerId': os_snapshot.project_id,
|
'ownerId': ownerId,
|
||||||
'volumeSize': os_snapshot.size,
|
'volumeSize': os_snapshot.size,
|
||||||
'description': os_snapshot.display_description}
|
'description': os_snapshot.display_description}
|
||||||
|
@ -62,6 +62,7 @@ def attach_volume(context, volume_id, instance_id, device):
|
|||||||
nova.volumes.create_server_volume(instance['os_id'], volume['os_id'],
|
nova.volumes.create_server_volume(instance['os_id'], volume['os_id'],
|
||||||
device)
|
device)
|
||||||
except (nova_exception.Conflict, nova_exception.BadRequest):
|
except (nova_exception.Conflict, nova_exception.BadRequest):
|
||||||
|
# TODO(andrey-mp): raise correct errors for different cases
|
||||||
raise exception.UnsupportedOperation()
|
raise exception.UnsupportedOperation()
|
||||||
cinder = clients.cinder(context)
|
cinder = clients.cinder(context)
|
||||||
os_volume = cinder.volumes.get(volume['os_id'])
|
os_volume = cinder.volumes.get(volume['os_id'])
|
||||||
@ -96,6 +97,7 @@ def delete_volume(context, volume_id):
|
|||||||
try:
|
try:
|
||||||
cinder.volumes.delete(volume['os_id'])
|
cinder.volumes.delete(volume['os_id'])
|
||||||
except cinder_exception.BadRequest:
|
except cinder_exception.BadRequest:
|
||||||
|
# TODO(andrey-mp): raise correct errors for different cases
|
||||||
raise exception.UnsupportedOperation()
|
raise exception.UnsupportedOperation()
|
||||||
except cinder_exception.NotFound:
|
except cinder_exception.NotFound:
|
||||||
pass
|
pass
|
||||||
|
@ -72,6 +72,26 @@ class SnapshotTestCase(base.ApiTestCase):
|
|||||||
'DescribeSnapshots', 'snapshotSet',
|
'DescribeSnapshots', 'snapshotSet',
|
||||||
fakes.ID_EC2_SNAPSHOT_1, 'snapshotId')
|
fakes.ID_EC2_SNAPSHOT_1, 'snapshotId')
|
||||||
|
|
||||||
|
def test_describe_snapshots_auto_remove(self):
|
||||||
|
self.cinder.volume_snapshots.list.return_value = []
|
||||||
|
|
||||||
|
self.db_api.get_items.side_effect = (
|
||||||
|
fakes.get_db_api_get_items({
|
||||||
|
'snap': [fakes.DB_SNAPSHOT_1],
|
||||||
|
'vol': [fakes.DB_VOLUME_2]}))
|
||||||
|
|
||||||
|
resp = self.execute('DescribeSnapshots', {})
|
||||||
|
self.assertEqual(200, resp['http_status_code'])
|
||||||
|
resp.pop('http_status_code')
|
||||||
|
self.assertThat(resp, matchers.DictMatches(
|
||||||
|
{'snapshotSet': []},
|
||||||
|
orderless_lists=True))
|
||||||
|
|
||||||
|
self.db_api.get_items.assert_any_call(mock.ANY, 'vol')
|
||||||
|
self.db_api.get_items.assert_any_call(mock.ANY, 'snap')
|
||||||
|
self.db_api.delete_item.assert_any_call(mock.ANY,
|
||||||
|
fakes.ID_EC2_SNAPSHOT_1)
|
||||||
|
|
||||||
def test_describe_snapshots_invalid_parameters(self):
|
def test_describe_snapshots_invalid_parameters(self):
|
||||||
self.cinder.volume_snapshots.list.return_value = [
|
self.cinder.volume_snapshots.list.return_value = [
|
||||||
fakes.OSSnapshot(fakes.OS_SNAPSHOT_1),
|
fakes.OSSnapshot(fakes.OS_SNAPSHOT_1),
|
||||||
|
Loading…
Reference in New Issue
Block a user