From 948d1fefe6cb1e17c5567d3cf3313e13c16a3d57 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 3 Apr 2013 21:09:50 +0000 Subject: Fix legacy_net_info guard The existing code assumes that `legacy_net_info` is always in legacy mode, meaning a list of tuples which causes it to break when passed a new-style NetworkInfo object. Fixes bug 1164152 Change-Id: I2131d9b24045cd7531454b65d97776b11ec3ab02 --- nova/compute/manager.py | 4 +++- nova/tests/compute/test_compute.py | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 0c038bf4c..8577e9532 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -466,7 +466,9 @@ class ComputeManager(manager.SchedulerDependentManager): # 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: + if (legacy_net_info and + isinstance(legacy_net_info[0], tuple) 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) diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 7e85ad0a7..61ba5c11e 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3998,10 +3998,13 @@ class ComputeTestCase(BaseTestCase): self.compute._init_instance(self.context, instance) - def test_init_instance_update_nw_info_cache(self): + def _test_init_instance_update_nw_info_cache_helper(self, legacy_nwinfo): + self.compute.driver.legacy_nwinfo = lambda *a, **k: legacy_nwinfo + 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()} @@ -4014,21 +4017,34 @@ class ComputeTestCase(BaseTestCase): } 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()) + + if legacy_nwinfo: + self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info') + # 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.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') + self.compute.driver.plug_vifs(instance, cached_nw_info.legacy()) + else: + self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs') + self.compute.driver.plug_vifs(instance, cached_nw_info) self.mox.ReplayAll() self.compute._init_instance(self.context, instance) + def test_init_instance_update_nw_info_cache_legacy(self): + """network_info in legacy is form [(network_dict, info_dict)].""" + self._test_init_instance_update_nw_info_cache_helper(True) + + def test_init_instance_update_nw_info_cache(self): + """network_info is NetworkInfo list-like object.""" + self._test_init_instance_update_nw_info_cache_helper(False) + def test_get_instances_on_driver(self): fake_context = context.get_admin_context() -- cgit