From 45e65d8c0301da689de1afcbc9f45756e71097ab Mon Sep 17 00:00:00 2001 From: Yaguang Tang Date: Fri, 8 Mar 2013 11:29:43 +0800 Subject: Update instance network info cache to include vif_type. vif_type is a new param in legacy_nw_info added in grizzly, and when upgrading from folsom to grizzly, the existing instance's network info cache in the db doesn't contain this param, which is needed by vif driver to plug vif to instance. Nova compute will try to plug the vif when it starts the instance, so we need to update the existing instance's network info cache before pluging instance's VIF. fix bug #1152426 Change-Id: I1b839bf791b402b933354d9c17c5713fde21ab09 --- nova/compute/manager.py | 8 ++++++++ nova/tests/compute/test_compute.py | 31 +++++++++++++++++++++++++++++++ nova/tests/fake_network_cache_model.py | 1 + 3 files changed, 40 insertions(+) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 604362783..05eeb8ac0 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -460,6 +460,14 @@ class ComputeManager(manager.SchedulerDependentManager): # We're calling plug_vifs to ensure bridge and iptables # rules exist. This needs to be called for each instance. legacy_net_info = self._legacy_nw_info(net_info) + + # Keep compatibility with folsom, update networkinfo and + # add vif type to instance_info_cache. + if legacy_net_info and legacy_net_info[0][1].get('vif_type') is None: + # Call to network API to get instance info, this will + # force an update to the instance's info_cache + net_info = self._get_instance_nw_info(context, instance) + legacy_net_info = self._legacy_nw_info(net_info) self.driver.plug_vifs(instance, legacy_net_info) if instance['task_state'] == task_states.RESIZE_MIGRATING: diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index e92f1b41f..b1b661d19 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3964,6 +3964,37 @@ class ComputeTestCase(BaseTestCase): self.compute._init_instance(self.context, instance) + def test_init_instance_update_nw_info_cache(self): + cached_nw_info = fake_network_cache_model.new_vif() + cached_nw_info = network_model.NetworkInfo([cached_nw_info]) + old_cached_nw_info = copy.deepcopy(cached_nw_info) + # Folsom has no 'type' in network cache info. + del old_cached_nw_info[0]['type'] + fake_info_cache = {'network_info': old_cached_nw_info.json()} + instance = { + 'uuid': 'a-foo-uuid', + 'vm_state': vm_states.ACTIVE, + 'task_state': None, + 'power_state': power_state.RUNNING, + 'info_cache': fake_info_cache, + } + + self.mox.StubOutWithMock(self.compute, '_get_power_state') + self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') + self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') + + self.compute._get_power_state(mox.IgnoreArg(), + instance).AndReturn(power_state.RUNNING) + # Call network API to get instance network info, and force + # an update to instance's info_cache. + self.compute._get_instance_nw_info(self.context, + instance).AndReturn(cached_nw_info) + self.compute.driver.plug_vifs(instance, cached_nw_info.legacy()) + + self.mox.ReplayAll() + + self.compute._init_instance(self.context, instance) + def test_get_instances_on_driver(self): fake_context = context.get_admin_context() diff --git a/nova/tests/fake_network_cache_model.py b/nova/tests/fake_network_cache_model.py index 3aa3bf586..2c1d0ad25 100644 --- a/nova/tests/fake_network_cache_model.py +++ b/nova/tests/fake_network_cache_model.py @@ -65,6 +65,7 @@ def new_vif(vif_dict=None): vif = dict( id=1, address='aa:aa:aa:aa:aa:aa', + type='bridge', network=new_network()) vif_dict = vif_dict or {} vif.update(vif_dict) -- cgit