From 9308c0a0b689fec5ca72ecb008a824ea23667a07 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 13 Jan 2022 11:32:41 +0100 Subject: [PATCH] Do not fail inspection on invalid MAC Some adapters may have addresses that are not MAC. See for example: https://github.com/metal3-io/ironic-image/issues/314 Change-Id: I0023e0750e372185747ca28cddd2a8dda110dd7f --- ironic/drivers/modules/inspect_utils.py | 7 +++++++ ironic/tests/unit/drivers/modules/test_inspect_utils.py | 9 +++++++-- releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml diff --git a/ironic/drivers/modules/inspect_utils.py b/ironic/drivers/modules/inspect_utils.py index 911c5b4025..89a13e658e 100644 --- a/ironic/drivers/modules/inspect_utils.py +++ b/ironic/drivers/modules/inspect_utils.py @@ -14,6 +14,7 @@ # under the License. from oslo_log import log as logging +from oslo_utils import netutils from ironic.common import exception from ironic import objects @@ -34,6 +35,12 @@ def create_ports_if_not_exist(task, macs): """ node = task.node for mac in macs: + if not netutils.is_valid_mac(mac): + LOG.warning("Ignoring NIC address %(address)s for node %(node)s " + "because it is not a valid MAC", + {'address': mac, 'node': node.uuid}) + continue + port_dict = {'address': mac, 'node_id': node.id} port = objects.Port(task.context, **port_dict) diff --git a/ironic/tests/unit/drivers/modules/test_inspect_utils.py b/ironic/tests/unit/drivers/modules/test_inspect_utils.py index 3c443c3fcc..3c636a1b19 100644 --- a/ironic/tests/unit/drivers/modules/test_inspect_utils.py +++ b/ironic/tests/unit/drivers/modules/test_inspect_utils.py @@ -55,17 +55,22 @@ class InspectFunctionTestCase(db_base.DbTestCase): port_obj1.create.assert_called_once_with() port_obj2.create.assert_called_once_with() + @mock.patch.object(utils.LOG, 'warning', spec_set=True, autospec=True) @mock.patch.object(utils.LOG, 'info', spec_set=True, autospec=True) @mock.patch.object(objects.Port, 'create', spec_set=True, autospec=True) def test_create_ports_if_not_exist_mac_exception(self, create_mock, - log_mock): + log_mock, + warn_mock): create_mock.side_effect = exception.MACAlreadyExists('f') - macs = {'aa:aa:aa:aa:aa:aa', 'bb:bb:bb:bb:bb:bb'} + macs = {'aa:aa:aa:aa:aa:aa', 'bb:bb:bb:bb:bb:bb', + 'aa:aa:aa:aa:aa:aa:bb:bb'} # WWN with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: utils.create_ports_if_not_exist(task, macs) self.assertEqual(2, log_mock.call_count) + self.assertEqual(2, create_mock.call_count) + self.assertEqual(1, warn_mock.call_count) @mock.patch.object(utils.LOG, 'info', spec_set=True, autospec=True) @mock.patch.object(objects, 'Port', spec_set=True, autospec=True) diff --git a/releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml b/releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml new file mode 100644 index 0000000000..129c84de64 --- /dev/null +++ b/releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Inspection no longer fails when one of the NICs reports NIC address that + is not a valid MAC (e.g. a WWN).