diff --git a/nova_powervm/tests/virt/powervm/tasks/test_network.py b/nova_powervm/tests/virt/powervm/tasks/test_network.py index 718f194a..fb4e5db1 100644 --- a/nova_powervm/tests/virt/powervm/tasks/test_network.py +++ b/nova_powervm/tests/virt/powervm/tasks/test_network.py @@ -212,10 +212,13 @@ class TestNetwork(test.TestCase): # Run method p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info, 'host_uuid', 'slot_mgr') - p_vifs.execute(self.mock_lpar_wrap) + with mock.patch.object(inst, 'save') as mock_inst_save: + p_vifs.execute(self.mock_lpar_wrap) # The create should have only been called once. self.assertEqual(1, mock_plug.call_count) + # Should have called save to save the new host and then changed it back + self.assertEqual(2, mock_inst_save.call_count) self.assertEqual('host1', inst.host) @mock.patch('nova_powervm.virt.powervm.vif.plug') @@ -243,11 +246,14 @@ class TestNetwork(test.TestCase): # Run method p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info, 'host_uuid', 'slot_mgr') - self.assertRaises(exception.VirtualInterfaceCreateException, - p_vifs.execute, self.mock_lpar_wrap) + with mock.patch.object(inst, 'save') as mock_inst_save: + self.assertRaises(exception.VirtualInterfaceCreateException, + p_vifs.execute, self.mock_lpar_wrap) # The create should have only been called once. self.assertEqual(1, mock_plug.call_count) + # Should have called save to save the new host and then changed it back + self.assertEqual(2, mock_inst_save.call_count) self.assertEqual('host1', inst.host) @mock.patch('nova_powervm.virt.powervm.vif.unplug') diff --git a/nova_powervm/virt/powervm/tasks/network.py b/nova_powervm/virt/powervm/tasks/network.py index 3df294aa..80d7f082 100644 --- a/nova_powervm/virt/powervm/tasks/network.py +++ b/nova_powervm/virt/powervm/tasks/network.py @@ -153,6 +153,22 @@ class PlugVifs(task.Task): instance=self.instance) raise exception.VirtualInterfaceCreateException() + # TODO(KYLEH): We're setting up to wait for an instance event. The + # event needs to come back to our compute manager so we need to ensure + # the instance.host is set to our host. We shouldn't need to do this + # but in the evacuate/recreate case it may reflect the old host. + # See: https://bugs.launchpad.net/nova/+bug/1535918 + undo_host_change = False + if self.instance.host != CONF.host: + LOG.warning(_LW('Instance was not assigned to this host. ' + 'It was assigned to: %s'), self.instance.host, + instance=self.instance) + # Update the instance... + old_host = self.instance.host + self.instance.host = CONF.host + self.instance.save() + undo_host_change = True + # For the VIFs, run the creates (and wait for the events back) try: with self.virt_api.wait_for_instance_event( @@ -172,6 +188,12 @@ class PlugVifs(task.Task): '%(sys)s'), {'sys': self.instance.name}, instance=self.instance) raise exception.VirtualInterfaceCreateException() + finally: + if undo_host_change: + LOG.info(_LI('Undoing temporary host assignment to instance.'), + instance=self.instance) + self.instance.host = old_host + self.instance.save() # Return the list of created VIFs. return cna_w_list