no instance info cache update if instance deleted
Avoid instance info cache update if the instance is deleted, as the deleted instance's info cache is already deleted in db layer and it will report InstanceInfoCacheNotFound exception and lead to a few exception logs in compute. Please note this is different to regular info cache and lead to InstanceInfoCacheNotFound exception, it's in the case when you first create the info cache after instance delete and InstanceInfo is also deleted. Change-Id: I860e9e7c7ef458722135a21c6c5745f5519c56c4 Closes-Bug: 1618822
This commit is contained in:
parent
4dc7682e79
commit
ef85c99f5e
|
@ -33,6 +33,11 @@ LOG = logging.getLogger(__name__)
|
|||
@hooks.add_hook('instance_network_info')
|
||||
def update_instance_cache_with_nw_info(impl, context, instance,
|
||||
nw_info=None, update_cells=True):
|
||||
if instance.deleted:
|
||||
LOG.debug('Instance is deleted, no further info cache update',
|
||||
instance=instance)
|
||||
return
|
||||
|
||||
try:
|
||||
if not isinstance(nw_info, network_model.NetworkInfo):
|
||||
nw_info = None
|
||||
|
|
|
@ -144,7 +144,7 @@ class ApiTestCase(test.TestCase):
|
|||
instance = objects.Instance(id=1, uuid=uuids.instance,
|
||||
project_id='project_id',
|
||||
host='host', system_metadata={},
|
||||
flavor=flavor)
|
||||
flavor=flavor, deleted=False)
|
||||
self.network_api.allocate_for_instance(
|
||||
self.context, instance, 'vpn', requested_networks=None,
|
||||
macs=macs)
|
||||
|
@ -565,7 +565,7 @@ class TestUpdateInstanceCache(test.NoDBTestCase):
|
|||
def setUp(self):
|
||||
super(TestUpdateInstanceCache, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.instance = objects.Instance(uuid=FAKE_UUID)
|
||||
self.instance = objects.Instance(uuid=FAKE_UUID, deleted=False)
|
||||
vifs = [network_model.VIF(id='super_vif')]
|
||||
self.nw_info = network_model.NetworkInfo(vifs)
|
||||
self.nw_json = fields.NetworkModel.to_primitive(self, 'network_info',
|
||||
|
@ -584,6 +584,12 @@ class TestUpdateInstanceCache(test.NoDBTestCase):
|
|||
{'network_info': self.nw_json})
|
||||
self.assertEqual(self.nw_info, self.instance.info_cache.network_info)
|
||||
|
||||
def test_update_nw_info_none_instance_deleted(self, db_mock, api_mock):
|
||||
instance = objects.Instance(uuid=FAKE_UUID, deleted=True)
|
||||
base_api.update_instance_cache_with_nw_info(
|
||||
api_mock, self.context, instance)
|
||||
self.assertFalse(api_mock.called)
|
||||
|
||||
def test_update_nw_info_one_network(self, db_mock, api_mock):
|
||||
info_cache = copy.deepcopy(fake_info_cache)
|
||||
info_cache.update({'network_info': self.nw_json})
|
||||
|
|
Loading…
Reference in New Issue