From 09423854b9bc253f0a42b400f3bafa14f3c49324 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 13 Jan 2022 11:32:41 +0100 Subject: 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 Conflicts: ironic/drivers/modules/inspect_utils.py ironic/tests/unit/drivers/modules/test_inspect_utils.py Change-Id: I0023e0750e372185747ca28cddd2a8dda110dd7f (cherry picked from commit 9308c0a0b689fec5ca72ecb008a824ea23667a07) --- ironic/drivers/modules/inspect_utils.py | 7 +++++++ ironic/ironic.sqlite-shm | Bin 0 -> 32768 bytes ironic/ironic.sqlite-wal | Bin 0 -> 148352 bytes .../tests/unit/drivers/modules/test_inspect_utils.py | 9 +++++---- releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml | 5 +++++ 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 ironic/ironic.sqlite-shm create mode 100644 ironic/ironic.sqlite-wal 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 41390b63a..f434a2f05 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 @@ -39,6 +40,12 @@ def create_ports_if_not_exist( node = task.node for k_v_pair in macs.items(): mac = get_mac_address(k_v_pair) + 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/ironic.sqlite-shm b/ironic/ironic.sqlite-shm new file mode 100644 index 000000000..26befc0fa Binary files /dev/null and b/ironic/ironic.sqlite-shm differ diff --git a/ironic/ironic.sqlite-wal b/ironic/ironic.sqlite-wal new file mode 100644 index 000000000..27124125a Binary files /dev/null and b/ironic/ironic.sqlite-wal differ diff --git a/ironic/tests/unit/drivers/modules/test_inspect_utils.py b/ironic/tests/unit/drivers/modules/test_inspect_utils.py index 8b44dde5a..3a4e28aa9 100644 --- a/ironic/tests/unit/drivers/modules/test_inspect_utils.py +++ b/ironic/tests/unit/drivers/modules/test_inspect_utils.py @@ -55,18 +55,19 @@ 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, 'warning', 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): create_mock.side_effect = exception.MACAlreadyExists('f') - macs = {'Port 1': 'aa:aa:aa:aa:aa:aa', 'Port 2': 'bb:bb:bb:bb:bb:bb'} + macs = {'Port 1': 'aa:aa:aa:aa:aa:aa', 'Port 2': 'bb:bb:bb:bb:bb:bb', + 'Port 3': '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(3, log_mock.call_count) + self.assertEqual(2, create_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 000000000..129c84de6 --- /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). -- cgit v1.2.1