diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-04-04 06:50:04 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-04-04 06:50:04 +0000 |
| commit | f96c9ab31700bc37792de0b3bec97edd7d99aa29 (patch) | |
| tree | edd5b9845c3059fb33392257c549165672d1068f | |
| parent | a892d2f740d5bdaa82aec4583ced3f336f89bb78 (diff) | |
| parent | 948d1fefe6cb1e17c5567d3cf3313e13c16a3d57 (diff) | |
Merge "Fix legacy_net_info guard"
| -rwxr-xr-x | nova/compute/manager.py | 4 | ||||
| -rw-r--r-- | 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 8556a5d26..19c8ee1a2 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -478,7 +478,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 41da61e4e..44b004ed2 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -4048,10 +4048,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()} @@ -4064,21 +4067,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() |
