diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py index 9479dd34df..2bd8abe36a 100644 --- a/ironic/drivers/modules/redfish/utils.py +++ b/ironic/drivers/modules/redfish/utils.py @@ -361,18 +361,25 @@ def get_enabled_macs(task, system): in a {'mac': 'state'} format """ + enabled_macs = {} if (system.ethernet_interfaces and system.ethernet_interfaces.summary): macs = system.ethernet_interfaces.summary # Identify ports for the NICs being in 'enabled' state - enabled_macs = {nic_mac: nic_state - for nic_mac, nic_state in macs.items() - if nic_state == sushy.STATE_ENABLED} - return enabled_macs - else: - LOG.debug("No ethernet interface information is available " - "for node %(node)s", {'node': task.node.uuid}) + for nic_mac, nic_state in macs.items(): + if nic_state != sushy.STATE_ENABLED: + continue + elif not nic_mac: + LOG.warning("Ignoring device for %(node)s as no MAC " + "reported", {'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): diff --git a/ironic/tests/unit/drivers/modules/redfish/test_inspect.py b/ironic/tests/unit/drivers/modules/redfish/test_inspect.py index f67f6eb4c6..de084c3414 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_inspect.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_inspect.py @@ -279,6 +279,21 @@ class RedfishInspectTestCase(db_base.DbTestCase): port = mock_list_by_node_id.return_value 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(redfish_utils, 'get_system', autospec=True) def test_inspect_hardware_with_empty_pxe_port_macs( diff --git a/releasenotes/notes/blank-mac-f8e0b37e0bd6d719.yaml b/releasenotes/notes/blank-mac-f8e0b37e0bd6d719.yaml new file mode 100644 index 0000000000..de2c711593 --- /dev/null +++ b/releasenotes/notes/blank-mac-f8e0b37e0bd6d719.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Skips port creation during redfish inspect for devices + reported without a MAC address.