Browse Source

Merge "Do not fail inspection on invalid MAC"

changes/81/822781/6
Zuul 7 days ago
committed by Gerrit Code Review
parent
commit
097ec2f8ee
  1. 7
      ironic/drivers/modules/inspect_utils.py
  2. 9
      ironic/tests/unit/drivers/modules/test_inspect_utils.py
  3. 5
      releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml

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

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

5
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).
Loading…
Cancel
Save