Do not hide exception in update_instance_cache_with_nw_info

From time to time an exception is raised in this method causing
the nw_info cache not to be saved. If this occurs we should raise
as this error will cause later errors to occur. For example, one
won't be able to associate a floatingip with the instance as there
is no nw_info found in this table. In addition, the fixed_ips on
the instance won't be returned via the api.

This patch also stubs out update_instance_cache_with_nw_info in a
few tests where an exception was being raised previously but went
unnoticed as it was not reraised but now is.

Related-Bug: #1252849
Related-Bug: #1249065

Change-Id: Ic860f72210ba736e11c10df21c4cb7625e9c0928
(cherry picked from commit 4c03383f21)
This commit is contained in:
Aaron Rosen 2013-11-21 07:57:44 -08:00 committed by Ihar Hrachyshka
parent f44bdfe826
commit 53acc09fb9
3 changed files with 21 additions and 1 deletions

View File

@ -28,6 +28,7 @@ from nova.network import floating_ips
from nova.network import model as network_model
from nova.network import rpcapi as network_rpcapi
from nova.objects import instance_info_cache as info_cache_obj
from nova.openstack.common import excutils
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
from nova import policy
@ -81,7 +82,8 @@ def update_instance_cache_with_nw_info(api, context, instance, nw_info=None,
ic.network_info = nw_info
ic.save(update_cells=update_cells)
except Exception:
LOG.exception(_('Failed storing info cache'), instance=instance)
with excutils.save_and_reraise_exception():
LOG.exception(_('Failed storing info cache'), instance=instance)
def wrap_check_policy(func):

View File

@ -304,6 +304,16 @@ class CloudTestCase(test.TestCase):
'floating_ips': []})
self.stubs.Set(network_api.API, 'get_instance_id_by_floating_address',
lambda *args: 1)
def fake_update_instance_cache_with_nw_info(api, context, instance,
nw_info=None,
update_cells=True):
return
self.stubs.Set(network_api, "update_instance_cache_with_nw_info",
fake_update_instance_cache_with_nw_info)
self.cloud.associate_address(self.context,
instance_id=ec2_id,
public_ip=address)

View File

@ -131,6 +131,14 @@ class ApiTestCase(test.TestCase):
self.stubs.Set(self.network_api.db, 'instance_info_cache_update',
fake_instance_info_cache_update)
def fake_update_instance_cache_with_nw_info(api, context, instance,
nw_info=None,
update_cells=True):
return
self.stubs.Set(api, "update_instance_cache_with_nw_info",
fake_update_instance_cache_with_nw_info)
self.network_api.associate_floating_ip(self.context,
new_instance,
'172.24.4.225',