diff options
author | Yaguang Tang <yaguang.tang@canonical.com> | 2013-03-08 11:29:43 +0800 |
---|---|---|
committer | Yaguang Tang <yaguang.tang@canonical.com> | 2013-03-27 01:39:11 +0800 |
commit | ddff7707be535bd082f291bb38b31406f338cefe (patch) | |
tree | 095eee81006656c3de5bab5aff245c4eafc9d3e5 | |
parent | 2df099a66d62bd22e2cf2f8c1c85975b3f3dda0b (diff) | |
download | nova-ddff7707be535bd082f291bb38b31406f338cefe.tar.gz |
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
(cherry picked from commit 45e65d8c0301da689de1afcbc9f45756e71097ab)
-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 fda7f490ad..ff3ace09f1 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 963c7992ca..11ce2d2aa3 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 3aa3bf5866..2c1d0ad25e 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) |