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:
Jun Hong Li 2015-02-05 17:20:42 +08:00
parent 65b85bfdb7
commit 8bd848df43
2 changed files with 18 additions and 0 deletions

View File

@ -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 '

View File

@ -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):
"""