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
This commit is contained in:
parent
65b85bfdb7
commit
8bd848df43
|
@ -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 '
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue