summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2013-04-03 21:09:50 +0000
committerRick Harris <rconradharris@gmail.com>2013-04-03 21:19:32 +0000
commit948d1fefe6cb1e17c5567d3cf3313e13c16a3d57 (patch)
tree6deb3c4e3c7ddbd14766a91b29c4353aaaf554cf /nova/tests
parent1ad8d1a749544c1710fe3bb911fb61df0317b105 (diff)
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
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/compute/test_compute.py34
1 files changed, 25 insertions, 9 deletions
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()