Skip to content

Commit

Permalink
Fix DB access when refreshing the network cache.
Browse files Browse the repository at this point in the history
When calling ComputeManager.attach_interface(), the following happens:

1) self.network_api.allocate_port_for_instance() is called from within
   ComputeManager.attach_interface();
2) refresh_cache() is called, since it decorates allocate_port_for_instance();
3) refresh_cache calls update_instance_cache_with_nw_info(), with
   "conductor_api=None" since 'conductor_api' cannot be found in the kwargs;
4) update_instance_cache_with_nw_info() calls
   api.db.instance_info_cache_update();
5) Since the call to the database should be made through the conductor, a
   DBNotAllowed exception is raised, which prevents the cache from being updated.

This patch fixes the call to allocate_port_for_instance (step 1) so that
'conductor_api' can be found in the kwargs (step 3).

When using ComputeManager.detach_interface, the exact same problem arises (with
deallocate_port_for_instance instead of allocate_port_for_instance).

This is a first step towards fixing bug #1197192.

Change-Id: I647795907b22790759d3be74afcaf70b712cb338
  • Loading branch information
CyrilRoelandteNovance committed Jul 18, 2013
1 parent 80ccf6d commit 3379e95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions nova/compute/manager.py
Expand Up @@ -3542,7 +3542,7 @@ def attach_interface(self, context, instance, network_id, port_id,
"""Use hotplug to add an network adapter to an instance."""
network_info = self.network_api.allocate_port_for_instance(
context, instance, port_id, network_id, requested_ip,
self.conductor_api)
conductor_api=self.conductor_api)
if len(network_info) != 1:
LOG.error(_('allocate_port_for_instance returned %(ports)s ports')
% dict(ports=len(network_info)))
Expand All @@ -3568,8 +3568,7 @@ def detach_interface(self, context, instance, port_id):
"attached") % port_id)

self.network_api.deallocate_port_for_instance(context, instance,
port_id,
self.conductor_api)
port_id, conductor_api=self.conductor_api)
self.driver.detach_interface(instance, [condemned])

def _get_compute_info(self, context, host):
Expand Down
4 changes: 2 additions & 2 deletions nova/tests/compute/test_compute.py
Expand Up @@ -7696,7 +7696,7 @@ def test_attach_interface(self):
req_ip = '1.2.3.4'
self.compute.network_api.allocate_port_for_instance(
self.context, instance, port_id, network_id, req_ip,
self.compute.conductor_api).AndReturn(nwinfo)
conductor_api=self.compute.conductor_api).AndReturn(nwinfo)
compute_manager._get_image_meta(self.context, instance['image_ref'])
self.mox.ReplayAll()
network, mapping = self.compute.attach_interface(self.context,
Expand All @@ -7713,7 +7713,7 @@ def test_detach_interface(self):
lambda *a, **k: nwinfo)
self.stubs.Set(self.compute.network_api,
'deallocate_port_for_instance',
lambda a, b, c, d: [])
lambda a, b, c, conductor_api=None: [])
self.compute.detach_interface(self.context, {}, port_id)
self.assertEqual(self.compute.driver._interfaces, {})

Expand Down

0 comments on commit 3379e95

Please sign in to comment.