diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-03-25 16:58:01 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-03-25 16:58:01 +0000 |
| commit | 58cc26c4dc6af8d10e623fb915f4c6232bc07cd7 (patch) | |
| tree | 7bfa73b376d5f0e2a1b962de9134f8391bc35795 | |
| parent | d40bdd43bc8fec44925788faf3eb32dac0ae06d2 (diff) | |
| parent | 45e65d8c0301da689de1afcbc9f45756e71097ab (diff) | |
| download | nova-58cc26c4dc6af8d10e623fb915f4c6232bc07cd7.tar.gz nova-58cc26c4dc6af8d10e623fb915f4c6232bc07cd7.tar.xz nova-58cc26c4dc6af8d10e623fb915f4c6232bc07cd7.zip | |
Merge "Update instance network info cache to include vif_type."
| -rwxr-xr-x | nova/compute/manager.py | 8 | ||||
| -rw-r--r-- | nova/tests/compute/test_compute.py | 31 | ||||
| -rw-r--r-- | nova/tests/fake_network_cache_model.py | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index fda7f490a..ff3ace09f 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -463,6 +463,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 ce688eb90..c36496f79 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) |
