Skip to content

Commit

Permalink
Do not hide exception in update_instance_cache_with_nw_info
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aaronorosen committed Nov 25, 2013
1 parent 2e52049 commit 4c03383
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nova/network/api.py
Expand Up @@ -28,6 +28,7 @@
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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions nova/tests/api/ec2/test_cloud.py
Expand Up @@ -304,6 +304,16 @@ def test_associate_disassociate_address(self):
'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)
Expand Down
8 changes: 8 additions & 0 deletions nova/tests/network/test_api.py
Expand Up @@ -131,6 +131,14 @@ def fake_instance_info_cache_update(context, instance_uuid, cache):
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',
Expand Down

0 comments on commit 4c03383

Please sign in to comment.