Fix snapshot id for snapshot_destroy

The id passed to snapshot_destroy should be snapshot['id'],
not volume['id'].

CCLA SCHEDULE B SUBMISSION

Change-Id: I1d84f1d596ebf014c0e3ea4202902ff515b3172a
Closes-Bug: 1351997
This commit is contained in:
Xing Yang
2014-08-03 09:33:28 -04:00
parent 07534bef77
commit d3ccb0ea7f
2 changed files with 39 additions and 1 deletions

View File

@@ -1678,6 +1678,42 @@ class VolumeTestCase(BaseVolumeTestCase):
self.context,
snapshot_id)
@mock.patch.object(db, 'snapshot_create',
side_effect=exception.InvalidSnapshot(
'Create snapshot in db failed!'))
def test_create_snapshot_failed_db_snapshot(self, mock_snapshot):
"""Test exception handling when create snapshot in db failed."""
test_volume = tests_utils.create_volume(
self.context,
**self.volume_params)
self.volume.create_volume(self.context, test_volume['id'])
test_volume['status'] = 'available'
volume_api = cinder.volume.api.API()
self.assertRaises(exception.InvalidSnapshot,
volume_api.create_snapshot,
self.context,
test_volume,
'fake_name',
'fake_description')
@mock.patch.object(QUOTAS, 'commit',
side_effect=exception.QuotaError(
'Snapshot quota commit failed!'))
def test_create_snapshot_failed_quota_commit(self, mock_snapshot):
"""Test exception handling when snapshot quota commit failed."""
test_volume = tests_utils.create_volume(
self.context,
**self.volume_params)
self.volume.create_volume(self.context, test_volume['id'])
test_volume['status'] = 'available'
volume_api = cinder.volume.api.API()
self.assertRaises(exception.QuotaError,
volume_api.create_snapshot,
self.context,
test_volume,
'fake_name',
'fake_description')
def test_cannot_delete_volume_in_use(self):
"""Test volume can't be deleted in invalid stats."""
# create a volume and assign to host

View File

@@ -524,13 +524,15 @@ class API(base.Base):
'encryption_key_id': volume['encryption_key_id'],
'metadata': metadata}
snapshot = None
try:
snapshot = self.db.snapshot_create(context, options)
QUOTAS.commit(context, reservations)
except Exception:
with excutils.save_and_reraise_exception():
try:
self.db.snapshot_destroy(context, volume['id'])
if snapshot:
self.db.snapshot_destroy(context, snapshot['id'])
finally:
QUOTAS.rollback(context, reservations)