Do not fail cell's instance deletion, if it's missing info_cache

Currently the methods in cell messaging are trying to refresh the
instance. However, in some corner cases info_cache is not being
created for instances in ERROR state. This makes the delete
operation, of such instances, to fail, while it should not.

Handling the InstanceInfoCacheNotFound exception and not
re-raising it, for delete operations.

Closes-Bug: #1316373
Change-Id: I33c33e3ac1180e8293d950d60fb126e325a2c0cf
This commit is contained in:
Vladik Romanovsky
2014-05-12 17:24:48 -04:00
parent a216f3b709
commit 47898ba8f9
2 changed files with 31 additions and 0 deletions

View File

@@ -836,6 +836,10 @@ class _TargetedMessageMethods(_BaseMessageMethods):
instance = {'uuid': instance.uuid}
self.msg_runner.instance_destroy_at_top(ctxt,
instance)
except exception.InstanceInfoCacheNotFound:
if method != 'delete':
raise
fn = getattr(self.compute_api, method, None)
return fn(ctxt, instance, *args, **kwargs)

View File

@@ -17,6 +17,8 @@
Tests For Cells Messaging module
"""
import contextlib
import mock
import mox
from oslo.config import cfg
@@ -1103,6 +1105,31 @@ class CellsTargetedMethodsTestCase(test.TestCase):
extra_properties='props')
self.assertEqual('foo', result)
def test_call_compute_api_with_obj_no_cache(self):
instance = objects.Instance()
instance.uuid = uuidutils.generate_uuid()
error = exception.InstanceInfoCacheNotFound(
instance_uuid=instance.uuid)
with mock.patch.object(instance, 'refresh', side_effect=error):
self.assertRaises(exception.InstanceInfoCacheNotFound,
self.tgt_methods_cls._call_compute_api_with_obj,
self.ctxt, instance, 'snapshot')
def test_call_delete_compute_api_with_obj_no_cache(self):
instance = objects.Instance()
instance.uuid = uuidutils.generate_uuid()
error = exception.InstanceInfoCacheNotFound(
instance_uuid=instance.uuid)
with contextlib.nested(
mock.patch.object(instance, 'refresh',
side_effect=error),
mock.patch.object(self.tgt_compute_api, 'delete')) as (inst,
delete):
self.tgt_methods_cls._call_compute_api_with_obj(self.ctxt,
instance,
'delete')
delete.assert_called_once_with(self.ctxt, instance)
def test_call_compute_with_obj_unknown_instance(self):
instance = objects.Instance()
instance.uuid = uuidutils.generate_uuid()