Fix RBD delete image on creation failure

When an exception rises on RBD store while adding/creating an image, and
the image has already been created, this new image is not properly
deleted as it should be.

Fault lies in incorrect call to Store._delete_image method, as it is
called with the wrong arguments.

Change-Id: Ib74f7eafbb04ab893039b480a7d3eaa15e7d59d1
Closes-Bug: #1449639
This commit is contained in:
Gorka Eguileor 2015-04-28 18:10:38 +02:00
parent adfeab405b
commit 751f9ae444
2 changed files with 13 additions and 6 deletions

View File

@ -381,7 +381,9 @@ class Store(driver.Store):
except Exception as exc:
# Delete image if one was created
try:
self._delete_image(loc.image, loc.snapshot)
target_pool = loc.pool or self.pool
self._delete_image(target_pool, loc.image,
loc.snapshot)
except exceptions.NotFound:
pass

View File

@ -186,7 +186,10 @@ class TestStore(base.StoreBaseTest,
self.called_commands_actual.append('create')
return self.location
def _fake_delete_image(*args, **kwargs):
def _fake_delete_image(target_pool, image_name, snapshot_name=None):
self.assertEqual(self.location.pool, target_pool)
self.assertEqual(self.location.image, image_name)
self.assertEqual(self.location.snapshot, snapshot_name)
self.called_commands_actual.append('delete')
def _fake_enter(*args, **kwargs):
@ -234,7 +237,7 @@ class TestStore(base.StoreBaseTest,
with mock.patch.object(MockRBD.RBD, 'remove') as remove_image:
remove_image.side_effect = _fake_remove
self.store._delete_image('fake_pool', self.location)
self.store._delete_image('fake_pool', self.location.image)
self.called_commands_expected = ['remove']
@mock.patch.object(MockRBD.RBD, 'remove')
@ -253,7 +256,7 @@ class TestStore(base.StoreBaseTest,
remove.side_effect = _fake_remove
unprotect.side_effect = _fake_unprotect_snap
remove_snap.side_effect = _fake_remove_snap
self.store._delete_image('fake_pool', self.location,
self.store._delete_image('fake_pool', self.location.image,
snapshot_name='snap')
self.called_commands_expected = ['unprotect_snap', 'remove_snap',
@ -268,7 +271,8 @@ class TestStore(base.StoreBaseTest,
mocked.side_effect = _fake_unprotect_snap
self.assertRaises(exceptions.NotFound, self.store._delete_image,
'fake_pool', self.location, snapshot_name='snap')
'fake_pool', self.location.image,
snapshot_name='snap')
self.called_commands_expected = ['unprotect_snap']
@ -280,7 +284,8 @@ class TestStore(base.StoreBaseTest,
with mock.patch.object(MockRBD.RBD, 'remove') as remove:
remove.side_effect = _fake_remove
self.assertRaises(exceptions.NotFound, self.store._delete_image,
'fake_pool', self.location, snapshot_name='snap')
'fake_pool', self.location.image,
snapshot_name='snap')
self.called_commands_expected = ['remove']