summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGorka Eguileor <geguileo@redhat.com>2015-04-28 18:10:38 +0200
committerGorka Eguileor <geguileo@redhat.com>2015-04-28 18:10:38 +0200
commit751f9ae444d25f9beaffee2796095102f884fe8d (patch)
treebbde18715b022c8b1d3ad6041beded6d8d921345
parentadfeab405b61064c7cbf2cd82058b8d0cc3a2e16 (diff)
downloadglance_store-751f9ae444d25f9beaffee2796095102f884fe8d.tar.gz
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
-rw-r--r--glance_store/_drivers/rbd.py4
-rw-r--r--tests/unit/test_rbd_store.py15
2 files changed, 13 insertions, 6 deletions
diff --git a/glance_store/_drivers/rbd.py b/glance_store/_drivers/rbd.py
index c37adf8..7ff86db 100644
--- a/glance_store/_drivers/rbd.py
+++ b/glance_store/_drivers/rbd.py
@@ -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
diff --git a/tests/unit/test_rbd_store.py b/tests/unit/test_rbd_store.py
index e6148cc..ceb2965 100644
--- a/tests/unit/test_rbd_store.py
+++ b/tests/unit/test_rbd_store.py
@@ -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']