From 8db54f3bd590e71c6c6e383c928aa82fc28b3379 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Tue, 29 May 2012 16:04:16 -0400 Subject: Don't query nova-network on startup. Fix bug 999698. nova-compute requested network info for each instance on startup via rpc. If all services get (re)started at the same time, nova-network may not be available to take this request, resulting in a lost request. To combat this issue, get the network info from the cache in the database on startup. If by some chance this information is not correct, it will get fixed up by a periodic task. Change-Id: I0bbd475e078ac2a67c99c2be4711e86d617c609a --- nova/api/openstack/common.py | 10 ++-------- nova/api/openstack/compute/contrib/cloudpipe.py | 4 ++-- nova/compute/manager.py | 2 +- nova/compute/utils.py | 7 +++++++ nova/tests/api/openstack/compute/contrib/test_cloudpipe.py | 14 +++++++------- 5 files changed, 19 insertions(+), 18 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 3756f91a8..93b5a36ab 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -26,11 +26,11 @@ from xml.dom import minidom from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import task_states +from nova.compute import utils as compute_utils from nova.compute import vm_states from nova import exception from nova import flags from nova import log as logging -from nova.network import model as network_model from nova import quota @@ -321,12 +321,6 @@ def get_networks_for_instance_from_nw_info(nw_info): return networks -def get_nw_info_for_instance(context, instance): - info_cache = instance['info_cache'] or {} - cached_nwinfo = info_cache.get('network_info') or [] - return network_model.NetworkInfo.hydrate(cached_nwinfo) - - def get_networks_for_instance(context, instance): """Returns a prepared nw_info list for passing into the view builders @@ -338,7 +332,7 @@ def get_networks_for_instance(context, instance): {'addr': '172.16.2.1', 'version': 4}]}, ...} """ - nw_info = get_nw_info_for_instance(context, instance) + nw_info = compute_utils.get_nw_info_for_instance(instance) return get_networks_for_instance_from_nw_info(nw_info) diff --git a/nova/api/openstack/compute/contrib/cloudpipe.py b/nova/api/openstack/compute/contrib/cloudpipe.py index b0d17ff14..1d4c63da0 100644 --- a/nova/api/openstack/compute/contrib/cloudpipe.py +++ b/nova/api/openstack/compute/contrib/cloudpipe.py @@ -16,13 +16,13 @@ import os -from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.auth import manager from nova.cloudpipe import pipelib from nova import compute +from nova.compute import utils as compute_utils from nova.compute import vm_states from nova import db from nova import exception @@ -91,7 +91,7 @@ class CloudpipeController(object): return rv rv['instance_id'] = instance['uuid'] rv['created_at'] = utils.isotime(instance['created_at']) - nw_info = common.get_nw_info_for_instance(elevated, instance) + nw_info = compute_utils.get_nw_info_for_instance(instance) if not nw_info: return rv vif = nw_info[0] diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 2776ee230..a14a38e88 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -287,7 +287,7 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.debug(_('Current state is %(drv_state)s, state in DB is ' '%(db_state)s.'), locals(), instance=instance) - net_info = self._get_instance_nw_info(context, instance) + net_info = compute_utils.get_nw_info_for_instance(instance) if ((expect_running and FLAGS.resume_guests_state_on_host_boot) or FLAGS.start_guests_on_host_boot): LOG.info(_('Rebooting instance after nova-compute restart.'), diff --git a/nova/compute/utils.py b/nova/compute/utils.py index f63203a1a..67a174f51 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -19,6 +19,7 @@ from nova import db from nova import flags from nova import log +from nova.network import model as network_model from nova import notifications from nova.notifier import api as notifier_api @@ -100,3 +101,9 @@ def notify_about_instance_usage(context, instance, event_suffix, notifier_api.notify(context, 'compute.%s' % host, 'compute.instance.%s' % event_suffix, notifier_api.INFO, usage_info) + + +def get_nw_info_for_instance(instance): + info_cache = instance['info_cache'] or {} + cached_nwinfo = info_cache.get('network_info') or [] + return network_model.NetworkInfo.hydrate(cached_nwinfo) diff --git a/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py b/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py index f6e1fbcb6..c082e315f 100644 --- a/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py +++ b/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py @@ -15,9 +15,9 @@ from lxml import etree -from nova.api.openstack import common from nova.api.openstack.compute.contrib import cloudpipe from nova.api.openstack import wsgi +from nova.compute import utils as compute_utils from nova import db from nova import flags from nova import test @@ -65,11 +65,11 @@ class CloudpipeTest(test.TestCase): def test_cloudpipe_list_no_network(self): - def common_get_nw_info_for_instance(context, instance): + def fake_get_nw_info_for_instance(instance): return {} - self.stubs.Set(common, "get_nw_info_for_instance", - common_get_nw_info_for_instance) + self.stubs.Set(compute_utils, "get_nw_info_for_instance", + fake_get_nw_info_for_instance) self.stubs.Set(self.controller.compute_api, "get_all", compute_api_get_all) req = fakes.HTTPRequest.blank('/v2/fake/os-cloudpipe') @@ -86,12 +86,12 @@ class CloudpipeTest(test.TestCase): return {'vpn_public_address': '127.0.0.1', 'vpn_public_port': 22} - def common_get_nw_info_for_instance(context, instance): + def fake_get_nw_info_for_instance(instance): return fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True) - self.stubs.Set(common, "get_nw_info_for_instance", - common_get_nw_info_for_instance) + self.stubs.Set(compute_utils, "get_nw_info_for_instance", + fake_get_nw_info_for_instance) self.stubs.Set(self.controller.network_api, "get", network_api_get) self.stubs.Set(self.controller.compute_api, "get_all", -- cgit