Skip port create if MAC is blank

During redifsh inspect, skip the creation of ports for
any nics that are reported without a MAC address.

Story: #2009016
Task: #42736
Change-Id: I1815ebaf7ed9882d8c61a0741fb605dff2db7efb
This commit is contained in:
Derek Higgins 2021-06-30 11:35:31 +00:00
parent e539ae5f1f
commit 0cc6d8204a
3 changed files with 34 additions and 7 deletions

View File

@ -361,18 +361,25 @@ def get_enabled_macs(task, system):
in a {'mac': 'state'} format in a {'mac': 'state'} format
""" """
enabled_macs = {}
if (system.ethernet_interfaces if (system.ethernet_interfaces
and system.ethernet_interfaces.summary): and system.ethernet_interfaces.summary):
macs = system.ethernet_interfaces.summary macs = system.ethernet_interfaces.summary
# Identify ports for the NICs being in 'enabled' state # Identify ports for the NICs being in 'enabled' state
enabled_macs = {nic_mac: nic_state for nic_mac, nic_state in macs.items():
for nic_mac, nic_state in macs.items() if nic_state != sushy.STATE_ENABLED:
if nic_state == sushy.STATE_ENABLED} continue
return enabled_macs elif not nic_mac:
else: LOG.warning("Ignoring device for %(node)s as no MAC "
LOG.debug("No ethernet interface information is available " "reported", {'node': task.node.uuid})
"for node %(node)s", {'node': task.node.uuid}) continue
enabled_macs[nic_mac] = nic_state
if enabled_macs:
return enabled_macs
LOG.debug("No ethernet interface information is available "
"for node %(node)s", {'node': task.node.uuid})
def wait_until_get_system_ready(node): def wait_until_get_system_ready(node):

View File

@ -279,6 +279,21 @@ class RedfishInspectTestCase(db_base.DbTestCase):
port = mock_list_by_node_id.return_value port = mock_list_by_node_id.return_value
self.assertFalse(port[0].pxe_enabled) self.assertFalse(port[0].pxe_enabled)
@mock.patch.object(redfish_utils, 'get_system', autospec=True)
def test_inspect_hardware_with_no_mac(self, mock_get_system):
self.init_system_mock(mock_get_system.return_value)
system = mock_get_system.return_value
system.ethernet_interfaces.summary = {
'00:11:22:33:44:55': sushy.STATE_ENABLED,
'': sushy.STATE_ENABLED,
}
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
task.driver.inspect.inspect_hardware(task)
ports = objects.Port.list_by_node_id(task.context, self.node.id)
self.assertEqual(1, len(ports))
@mock.patch.object(objects.Port, 'list_by_node_id') # noqa @mock.patch.object(objects.Port, 'list_by_node_id') # noqa
@mock.patch.object(redfish_utils, 'get_system', autospec=True) @mock.patch.object(redfish_utils, 'get_system', autospec=True)
def test_inspect_hardware_with_empty_pxe_port_macs( def test_inspect_hardware_with_empty_pxe_port_macs(

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Skips port creation during redfish inspect for devices
reported without a MAC address.