summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun Hong Li <junhongl@cn.ibm.com>2015-02-05 17:20:42 +0800
committerJun Hong Li <junhongl@cn.ibm.com>2015-03-10 09:53:44 +0800
commit8bd848df43ea96b7431802748a1e8567a8e89203 (patch)
tree254544d1610e3a634f4d92112a4b86e157f143bc
parent65b85bfdb718f57265e43325da313dcef9abda97 (diff)
downloadglance_store-8bd848df43ea96b7431802748a1e8567a8e89203.tar.gz
Throw NotFound exception when template is gone
When using vsphere backend store, if the template is deleted in vCenter datastore by some reason, it fails to delete the image from glance due to the generic Exception. The bug is fixed by catching oslo.vmware.FileNotFoundException, and throw NotFound exception. So that the behavior of deleting image will be identical with file system backend. Change-Id: If22f71feadec025eaf9a38c4cb15eb7f669820f8 Closes-Bug: 1418396
-rw-r--r--glance_store/_drivers/vmware_datastore.py5
-rw-r--r--tests/unit/test_vmware_store.py13
2 files changed, 18 insertions, 0 deletions
diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py
index 22e7093..8197107 100644
--- a/glance_store/_drivers/vmware_datastore.py
+++ b/glance_store/_drivers/vmware_datastore.py
@@ -26,6 +26,7 @@ from oslo_utils import excutils
from oslo_utils import units
from oslo_vmware import api
from oslo_vmware import constants
+import oslo_vmware.exceptions as vexc
from oslo_vmware.objects import datacenter as oslo_datacenter
from oslo_vmware.objects import datastore as oslo_datastore
from oslo_vmware import vim_util
@@ -572,6 +573,10 @@ class Store(glance_store.Store):
datacenter=dc_obj.ref)
try:
self.session.wait_for_task(delete_task)
+ except vexc.FileNotFoundException:
+ msg = _('Image file %s not found') % file_path
+ LOG.warn(msg)
+ raise exceptions.NotFound(message=msg)
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE('Failed to delete image %(image)s '
diff --git a/tests/unit/test_vmware_store.py b/tests/unit/test_vmware_store.py
index 22c3ac9..7b2175f 100644
--- a/tests/unit/test_vmware_store.py
+++ b/tests/unit/test_vmware_store.py
@@ -21,6 +21,7 @@ import uuid
import mock
from oslo_utils import units
from oslo_vmware import api
+from oslo_vmware.exceptions import FileNotFoundException
from oslo_vmware.objects import datacenter as oslo_datacenter
from oslo_vmware.objects import datastore as oslo_datastore
import six
@@ -224,6 +225,18 @@ class TestStore(base.StoreBaseTest,
HttpConn.return_value = FakeHTTPConnection(status=404)
self.assertRaises(exceptions.NotFound, self.store.get, loc)
+ def test_delete_non_existing(self):
+ """
+ Test that trying to delete an image that doesn't exist raises an error
+ """
+ loc = location.get_location_from_uri(
+ "vsphere://127.0.0.1/folder/openstack_glance/%s?"
+ "dsName=ds1&dcPath=dc1" % FAKE_UUID, conf=self.conf)
+ with mock.patch.object(self.store.session,
+ 'wait_for_task') as mock_task:
+ mock_task.side_effect = FileNotFoundException
+ self.assertRaises(exceptions.NotFound, self.store.delete, loc)
+
@mock.patch('oslo_vmware.api.VMwareAPISession')
def test_get_size(self, mock_api_session):
"""