diff options
-rw-r--r-- | nova/compute/manager.py | 21 | ||||
-rw-r--r-- | nova/network/api.py | 26 | ||||
-rw-r--r-- | nova/network/quantumv2/api.py | 15 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 16 | ||||
-rw-r--r-- | nova/tests/network/test_quantumv2.py | 3 |
5 files changed, 39 insertions, 42 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 73361fc23..b2f66c4ff 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -565,15 +565,8 @@ class ComputeManager(manager.SchedulerDependentManager): def _get_instance_nw_info(self, context, instance): """Get a list of dictionaries of network data of an instance.""" - # Get the network info from network API, but don't let it - # update the cache, as that will hit the DB. We'll update - # the cache ourselves via the conductor. network_info = self.network_api.get_instance_nw_info(context, - instance, update_cache=False) - cache = {'network_info': network_info.json()} - self.conductor_api.instance_info_cache_update(context, - instance, - cache) + instance, conductor_api=self.conductor_api) return network_info def _legacy_nw_info(self, network_info): @@ -924,7 +917,7 @@ class ComputeManager(manager.SchedulerDependentManager): network_info = self.network_api.allocate_for_instance( context, instance, vpn=is_vpn, requested_networks=requested_networks, - macs=macs) + macs=macs, conductor_api=self.conductor_api) except Exception: LOG.exception(_('Instance failed network setup'), instance=instance) @@ -2191,9 +2184,8 @@ class ComputeManager(manager.SchedulerDependentManager): self._notify_about_instance_usage( context, instance, "create_ip.start") - self.network_api.add_fixed_ip_to_instance(context, - instance, - network_id) + self.network_api.add_fixed_ip_to_instance(context, instance, + network_id, conductor_api=self.conductor_api) network_info = self._inject_network_info(context, instance=instance) self.reset_network(context, instance) @@ -2212,9 +2204,8 @@ class ComputeManager(manager.SchedulerDependentManager): self._notify_about_instance_usage( context, instance, "delete_ip.start") - self.network_api.remove_fixed_ip_from_instance(context, - instance, - address) + self.network_api.remove_fixed_ip_from_instance(context, instance, + address, conductor_api=self.conductor_api) network_info = self._inject_network_info(context, instance=instance) diff --git a/nova/network/api.py b/nova/network/api.py index 59172d9ec..30338489d 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -52,7 +52,7 @@ def refresh_cache(f): raise Exception(msg) update_instance_cache_with_nw_info(self, context, instance, - nw_info=res) + nw_info=res, conductor_api=kwargs.get('conductor_api')) # return the original function's return value return res @@ -60,8 +60,7 @@ def refresh_cache(f): def update_instance_cache_with_nw_info(api, context, instance, - nw_info=None): - + nw_info=None, conductor_api=None): try: if not isinstance(nw_info, network_model.NetworkInfo): nw_info = None @@ -69,7 +68,10 @@ def update_instance_cache_with_nw_info(api, context, instance, nw_info = api._get_instance_nw_info(context, instance) # update cache cache = {'network_info': nw_info.json()} - api.db.instance_info_cache_update(context, instance['uuid'], cache) + if conductor_api: + conductor_api.instance_info_cache_update(context, instance, cache) + else: + api.db.instance_info_cache_update(context, instance['uuid'], cache) except Exception: LOG.exception(_('Failed storing info cache'), instance=instance) @@ -227,7 +229,8 @@ class API(base.Base): @wrap_check_policy @refresh_cache def allocate_for_instance(self, context, instance, vpn, - requested_networks, macs=None): + requested_networks, macs=None, + conductor_api=None): """Allocates all network structures for an instance. TODO(someone): document the rest of these parameters. @@ -262,7 +265,8 @@ class API(base.Base): @wrap_check_policy @refresh_cache - def add_fixed_ip_to_instance(self, context, instance, network_id): + def add_fixed_ip_to_instance(self, context, instance, network_id, + conductor_api=None): """Adds a fixed ip to instance from specified network.""" args = {'instance_id': instance['uuid'], 'host': instance['host'], @@ -271,7 +275,8 @@ class API(base.Base): @wrap_check_policy @refresh_cache - def remove_fixed_ip_from_instance(self, context, instance, address): + def remove_fixed_ip_from_instance(self, context, instance, address, + conductor_api=None): """Removes a fixed ip from instance from specified network.""" args = {'instance_id': instance['uuid'], @@ -297,12 +302,11 @@ class API(base.Base): self.network_rpcapi.associate(context, network_uuid, associations) @wrap_check_policy - def get_instance_nw_info(self, context, instance, update_cache=True): + def get_instance_nw_info(self, context, instance, conductor_api=None): """Returns all network info related to an instance.""" result = self._get_instance_nw_info(context, instance) - if update_cache: - update_instance_cache_with_nw_info(self, context, instance, - result) + update_instance_cache_with_nw_info(self, context, instance, + result, conductor_api) return result def _get_instance_nw_info(self, context, instance): diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index b2c20e225..1c8c60113 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -207,7 +207,8 @@ class API(base.Base): self.trigger_security_group_members_refresh(context, instance) self.trigger_instance_add_security_group_refresh(context, instance) - return self.get_instance_nw_info(context, instance, networks=nets) + return self.get_instance_nw_info(context, instance, networks=nets, + conductor_api=kwargs.get('conductor_api')) def deallocate_for_instance(self, context, instance, **kwargs): """Deallocate all network resources related to the instance.""" @@ -226,10 +227,10 @@ class API(base.Base): self.trigger_instance_remove_security_group_refresh(context, instance) def get_instance_nw_info(self, context, instance, networks=None, - update_cache=True): + conductor_api=None): result = self._get_instance_nw_info(context, instance, networks) - if update_cache: - update_instance_info_cache(self, context, instance, result) + update_instance_info_cache(self, context, instance, result, + conductor_api) return result def _get_instance_nw_info(self, context, instance, networks=None): @@ -238,7 +239,8 @@ class API(base.Base): nw_info = self._build_network_info_model(context, instance, networks) return network_model.NetworkInfo.hydrate(nw_info) - def add_fixed_ip_to_instance(self, context, instance, network_id): + def add_fixed_ip_to_instance(self, context, instance, network_id, + conductor_api=None): """Add a fixed ip to the instance from specified network.""" search_opts = {'network_id': network_id} data = quantumv2.get_client(context).list_subnets(**search_opts) @@ -270,7 +272,8 @@ class API(base.Base): raise exception.NetworkNotFoundForInstance( instance_id=instance['uuid']) - def remove_fixed_ip_from_instance(self, context, instance, address): + def remove_fixed_ip_from_instance(self, context, instance, address, + conductor_api=None): """Remove a fixed ip from the instance.""" zone = 'compute:%s' % instance['availability_zone'] search_opts = {'device_id': instance['uuid'], diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 6bd2c3cac..e7c470c07 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1589,7 +1589,8 @@ class ComputeTestCase(BaseTestCase): mox.IgnoreArg(), mox.IgnoreArg(), requested_networks=None, - vpn=False, macs=macs).AndReturn( + vpn=False, macs=macs, + conductor_api=self.compute.conductor_api).AndReturn( fake_network.fake_get_instance_nw_info(self.stubs, 1, 1, spectacular=True)) self.mox.StubOutWithMock(self.compute.driver, "macs_for_instance") @@ -1607,8 +1608,9 @@ class ComputeTestCase(BaseTestCase): mox.IgnoreArg(), mox.IgnoreArg(), requested_networks=None, - vpn=False, - macs=None).AndRaise(rpc_common.RemoteError()) + vpn=False, macs=None, + conductor_api=self.compute.conductor_api + ).AndRaise(rpc_common.RemoteError()) fake_network.unset_stub_network_methods(self.stubs) @@ -2877,16 +2879,12 @@ class ComputeTestCase(BaseTestCase): self.mox.StubOutWithMock(self.compute.network_api, 'get_instance_nw_info') - self.mox.StubOutWithMock(fake_nw_info, 'json') self.mox.StubOutWithMock(self.compute.conductor_api, 'instance_info_cache_update') self.compute.network_api.get_instance_nw_info(self.context, - fake_instance, update_cache=False).AndReturn(fake_nw_info) - fake_nw_info.json().AndReturn('fake-nw-info') - expected_cache = {'network_info': 'fake-nw-info'} - self.compute.conductor_api.instance_info_cache_update(self.context, - fake_instance, expected_cache) + fake_instance, conductor_api=self.compute.conductor_api + ).AndReturn(fake_nw_info) self.mox.ReplayAll() diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index c9b2e43b3..a7d6d68ac 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -424,7 +424,8 @@ class TestQuantumv2(test.TestCase): return api api.get_instance_nw_info(mox.IgnoreArg(), self.instance, - networks=nets).AndReturn(None) + networks=nets, + conductor_api=mox.IgnoreArg()).AndReturn(None) self.mox.ReplayAll() return api |