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
(cherry picked from commit c47900064f)
This commit is contained in:
Aaron Rosen 2014-03-14 23:50:57 -07:00 committed by Chuck Short
parent 1d60a98729
commit c816488776
5 changed files with 6 additions and 50 deletions

View File

@ -1387,7 +1387,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)

View File

@ -2096,12 +2096,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]

View File

@ -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.db import base
from nova import exception
@ -32,7 +32,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
@ -493,12 +492,7 @@ class API(base.Base):
" 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]

View File

@ -1720,40 +1720,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,

View File

@ -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',