Merge "Remove unneeded call to fetch network info on shutdown"

This commit is contained in:
Jenkins 2014-04-17 02:40:39 +00:00 committed by Gerrit Code Review
commit 95b1737bf1
5 changed files with 6 additions and 50 deletions

View File

@ -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)

View File

@ -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]

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 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]

View File

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

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