Ironic: Do not try to unplug VIF if not associated
During instance spawn, Ironic attempts to unplug any plugged VIFs from ports associated with an instance. If there are no associated VIFs to unplug, this would raise an exeception that would be logged into n-cpu. This patch fix that behavior by making the driver check if the port has an VIF associated with it before trying to remove it. Change-Id: I5608b9eec625452edda9a0c9eb366ece2a95800f Closes-Bug: #1292733
This commit is contained in:
parent
e3af9b42b5
commit
d3acac0f5b
|
@ -996,7 +996,7 @@ class IronicDriverTestCase(test.NoDBTestCase):
|
|||
def test_unplug_vifs(self, mock_node, mock_update):
|
||||
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
||||
node = ironic_utils.get_test_node(uuid=node_uuid)
|
||||
port = ironic_utils.get_test_port()
|
||||
port = ironic_utils.get_test_port(extra={'vif_port_id': 'fake-vif'})
|
||||
|
||||
mock_node.get.return_value = node
|
||||
mock_node.list_ports.return_value = [port]
|
||||
|
@ -1010,9 +1010,26 @@ class IronicDriverTestCase(test.NoDBTestCase):
|
|||
|
||||
# asserts
|
||||
mock_node.get.assert_called_once_with(node_uuid)
|
||||
mock_node.list_ports.assert_called_once_with(node_uuid)
|
||||
mock_node.list_ports.assert_called_once_with(node_uuid, detail=True)
|
||||
mock_update.assert_called_once_with(port.uuid, expected_patch)
|
||||
|
||||
@mock.patch.object(FAKE_CLIENT.port, 'update')
|
||||
@mock.patch.object(FAKE_CLIENT, 'node')
|
||||
def test_unplug_vifs_port_not_associated(self, mock_node, mock_update):
|
||||
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
||||
node = ironic_utils.get_test_node(uuid=node_uuid)
|
||||
port = ironic_utils.get_test_port(extra={})
|
||||
|
||||
mock_node.get.return_value = node
|
||||
mock_node.list_ports.return_value = [port]
|
||||
instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid)
|
||||
self.driver.unplug_vifs(instance, utils.get_test_network_info())
|
||||
|
||||
mock_node.get.assert_called_once_with(node_uuid)
|
||||
mock_node.list_ports.assert_called_once_with(node_uuid, detail=True)
|
||||
# assert port.update() was not called
|
||||
self.assertFalse(mock_update.called)
|
||||
|
||||
@mock.patch.object(FAKE_CLIENT.port, 'update')
|
||||
def test_unplug_vifs_no_network_info(self, mock_update):
|
||||
instance = fake_instance.fake_instance_obj(self.ctx)
|
||||
|
|
|
@ -889,16 +889,17 @@ class IronicDriver(virt_driver.ComputeDriver):
|
|||
'network_info': network_info_str})
|
||||
if network_info and len(network_info) > 0:
|
||||
icli = client_wrapper.IronicClientWrapper()
|
||||
ports = icli.call("node.list_ports", node.uuid)
|
||||
ports = icli.call("node.list_ports", node.uuid, detail=True)
|
||||
|
||||
# not needed if no vif are defined
|
||||
for vif, pif in zip(network_info, ports):
|
||||
# we can not attach a dict directly
|
||||
patch = [{'op': 'remove', 'path': '/extra/vif_port_id'}]
|
||||
try:
|
||||
icli.call("port.update", pif.uuid, patch)
|
||||
except ironic.exc.BadRequest:
|
||||
pass
|
||||
if 'vif_port_id' in pif.extra:
|
||||
# we can not attach a dict directly
|
||||
patch = [{'op': 'remove', 'path': '/extra/vif_port_id'}]
|
||||
try:
|
||||
icli.call("port.update", pif.uuid, patch)
|
||||
except ironic.exc.BadRequest:
|
||||
pass
|
||||
|
||||
def plug_vifs(self, instance, network_info):
|
||||
"""Plug VIFs into networks.
|
||||
|
|
Loading…
Reference in New Issue