diff --git a/nova_powervm/tests/virt/powervm/tasks/test_network.py b/nova_powervm/tests/virt/powervm/tasks/test_network.py index b7b103f3..6abdd990 100644 --- a/nova_powervm/tests/virt/powervm/tasks/test_network.py +++ b/nova_powervm/tests/virt/powervm/tasks/test_network.py @@ -148,8 +148,6 @@ class TestNetwork(test.TestCase): {'address': 'aa:bb:cc:dd:ee:ff'}, {'address': 'aa:bb:cc:dd:ee:11'} ] - mock_state.return_value = True - # Run method p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info, 'host_uuid') @@ -160,17 +158,27 @@ class TestNetwork(test.TestCase): self.assertEqual(0, mock_vm_crt.call_count) self.assertEqual([], resp) + # State check shouldn't have even been invoked as no creates were + # required + self.assertEqual(0, mock_state.call_count) + @mock.patch('nova_powervm.virt.powervm.tasks.network.state_ok_for_plug') @mock.patch('nova_powervm.virt.powervm.vm.crt_vif') - def test_plug_vifs_invalid_state(self, mock_vm_crt, mock_state): + @mock.patch('nova_powervm.virt.powervm.vm.get_cnas') + def test_plug_vifs_invalid_state(self, mock_vm_get, mock_vm_crt, + mock_state): """Tests that a crt_vif fails when the LPAR state is bad.""" inst = objects.Instance(**powervm.TEST_INSTANCE) + # Mock up the CNA response. Only doing one for simplicity + mock_vm_get.return_value = [] + net_info = [{'address': 'aa:bb:cc:dd:ee:ff'}] + # Mock that the state is incorrect mock_state.return_value = False # Run method - p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, [], + p_vifs = tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info, 'host_uuid') self.assertRaises(exception.VirtualInterfaceCreateException, p_vifs.execute, mock.Mock()) diff --git a/nova_powervm/virt/powervm/tasks/network.py b/nova_powervm/virt/powervm/tasks/network.py index d6d1d922..792da009 100644 --- a/nova_powervm/virt/powervm/tasks/network.py +++ b/nova_powervm/virt/powervm/tasks/network.py @@ -148,15 +148,6 @@ class PlugVifs(task.Task): LOG.info(_LI('Plugging the Network Interfaces to instance %s'), self.instance.name) - # Check to see if the LPAR is OK to add VIFs to. - if not state_ok_for_plug(lpar_wrap): - LOG.error(_LE('Unable to create VIF(s) for instance %(sys)s. The ' - 'VM was in a state where VIF plugging is not ' - 'acceptable. The system may be running without an ' - 'active RMC connection.'), - {'sys': self.instance.name}, instance=self.instance) - raise exception.VirtualInterfaceCreateException() - # Get the current adapters on the system cna_w_list = vm.get_cnas(self.adapter, self.instance, self.host_uuid) @@ -173,6 +164,15 @@ class PlugVifs(task.Task): if len(crt_vifs) == 0: return [] + # Check to see if the LPAR is OK to add VIFs to. + if not state_ok_for_plug(lpar_wrap): + LOG.error(_LE('Unable to create VIF(s) for instance %(sys)s. The ' + 'VM was in a state where VIF plugging is not ' + 'acceptable. The system may be running without an ' + 'active RMC connection.'), + {'sys': self.instance.name}, instance=self.instance) + raise exception.VirtualInterfaceCreateException() + # For the VIFs, run the creates (and wait for the events back) try: with self.virt_api.wait_for_instance_event(