From c47900064f2f3b4384cfa3fd6fe21f452514fa36 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Fri, 14 Mar 2014 23:50:57 -0700 Subject: [PATCH] Remove unneeded call to fetch network info on shutdown There is no reason to fetch the network_info from the network api on shutdown since we can just pull it out of the local cache. There are probably other places where this call to the network api call can be removed but this patch just handles the case for shutdown. Note: the following test was removed 'test_terminate_no_fixed_ips' as the call to the network api is no longer done so this test would be the same as test_terminate_no_network. Closes-bug: #1288392 Change-Id: Ifbf751739c215e566926719f481c03e2c064163a --- nova/api/ec2/cloud.py | 2 +- nova/compute/manager.py | 7 +---- nova/network/neutronv2/api.py | 10 ++----- nova/tests/compute/test_compute.py | 34 ------------------------ nova/tests/compute/test_compute_utils.py | 3 ++- 5 files changed, 6 insertions(+), 50 deletions(-) diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index b73792872fb9..4e08d396f05f 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -1388,7 +1388,7 @@ class CloudController(object): def _ec2_ids_to_instances(self, context, instance_id, objects=False): """Get all instances first, to prevent partial executions.""" instances = [] - extra = ['system_metadata', 'metadata'] + extra = ['system_metadata', 'metadata', 'info_cache'] for ec2_id in instance_id: validate_ec2_id(ec2_id) instance_uuid = ec2utils.ec2_inst_id_to_uuid(context, ec2_id) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 760653cf4d37..5aa994db85d8 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2131,12 +2131,7 @@ class ComputeManager(manager.Manager): self._notify_about_instance_usage(context, instance, "shutdown.start") - # get network info before tearing down - try: - network_info = self._get_instance_nw_info(context, instance) - except (exception.NetworkNotFound, exception.NoMoreFixedIps, - exception.InstanceInfoCacheNotFound): - network_info = network_model.NetworkInfo() + network_info = compute_utils.get_nw_info_for_instance(instance) # NOTE(vish) get bdms before destroying the instance vol_bdms = [bdm for bdm in bdms if bdm.is_volume] diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index 9b472a665e29..8ad277d99f71 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -19,9 +19,9 @@ import time from neutronclient.common import exceptions as neutron_client_exc from oslo.config import cfg -import six from nova.compute import flavors +from nova.compute import utils as compute_utils from nova import conductor from nova import exception from nova.network import base_api @@ -31,7 +31,6 @@ from nova.network.neutronv2 import constants from nova.network.security_group import openstack_driver from nova.openstack.common import excutils from nova.openstack.common.gettextutils import _ -from nova.openstack.common import jsonutils from nova.openstack.common import log as logging from nova.openstack.common import uuidutils @@ -488,12 +487,7 @@ class API(base_api.NetworkAPI): " networks as not none.") raise exception.NovaException(message=message) - # Unfortunately, this is sometimes in unicode and sometimes not - if isinstance(instance['info_cache']['network_info'], six.text_type): - ifaces = jsonutils.loads(instance['info_cache']['network_info']) - else: - ifaces = instance['info_cache']['network_info'] - + ifaces = compute_utils.get_nw_info_for_instance(instance) # This code path is only done when refreshing the network_cache if port_ids is None: port_ids = [iface['id'] for iface in ifaces] diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index ebc38b9bf245..1beb14d78341 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1726,40 +1726,6 @@ class ComputeTestCase(BaseTestCase): instances = db.instance_get_all(self.context) LOG.info(_("Running instances: %s"), instances) self.assertEqual(len(instances), 1) - - # Make it look like this is no instance - self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') - self.compute._get_instance_nw_info( - mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise( - exception.NetworkNotFound(network_id='fake') - ) - self.mox.ReplayAll() - - self.compute.terminate_instance(self.context, - self._objectify(instance), [], []) - - instances = db.instance_get_all(self.context) - LOG.info(_("After terminating instances: %s"), instances) - self.assertEqual(len(instances), 0) - - def test_terminate_no_fixed_ips(self): - # This is as reported in LP bug 1192893 - instance = jsonutils.to_primitive(self._create_fake_instance()) - - self.compute.run_instance(self.context, instance, {}, {}, [], None, - None, True, None, False) - - instances = db.instance_get_all(self.context) - LOG.info(_("Running instances: %s"), instances) - self.assertEqual(len(instances), 1) - - self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') - self.compute._get_instance_nw_info( - mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise( - exception.NoMoreFixedIps() - ) self.mox.ReplayAll() self.compute.terminate_instance(self.context, diff --git a/nova/tests/compute/test_compute_utils.py b/nova/tests/compute/test_compute_utils.py index 1e9702af5b3b..2304e95fc6a9 100644 --- a/nova/tests/compute/test_compute_utils.py +++ b/nova/tests/compute/test_compute_utils.py @@ -428,6 +428,7 @@ class UsageInfoTestCase(test.TestCase): inst['ami_launch_index'] = 0 inst['root_gb'] = 0 inst['ephemeral_gb'] = 0 + inst['info_cache'] = {'network_info': '[]'} inst.update(params) return db.instance_create(self.context, inst)['id'] @@ -472,7 +473,7 @@ class UsageInfoTestCase(test.TestCase): # Ensure 'exists' notification generates appropriate usage data. instance_id = self._create_instance() instance = instance_obj.Instance.get_by_id(self.context, instance_id, - expected_attrs=['metadata', 'system_metadata']) + expected_attrs=['metadata', 'system_metadata', 'info_cache']) # Set some system metadata sys_metadata = {'image_md_key1': 'val1', 'image_md_key2': 'val2',