Merge "Do not fail inspection on invalid MAC"

This commit is contained in:
Zuul 2022-01-15 02:44:38 +00:00 committed by Gerrit Code Review
commit 097ec2f8ee
3 changed files with 19 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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).