Move VM state check post VIF required check
The VIF code determines if a VM is in a valid state for a plug vif, and then determines if a plug vif is needed. This can lead to odd scenarios where the plug of the VIF will fail, when in fact no VIF plugs were actually required. This change set swaps the checks around to prevent this failure. Change-Id: Ic759080fa2848eee179f322dd047bce3048624e8 Closes-Bug: 1466698
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user