Merge "Do not fail inspection on invalid MAC"
This commit is contained in:
commit
097ec2f8ee
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_utils import netutils
|
||||||
|
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic import objects
|
from ironic import objects
|
||||||
@ -34,6 +35,12 @@ def create_ports_if_not_exist(task, macs):
|
|||||||
"""
|
"""
|
||||||
node = task.node
|
node = task.node
|
||||||
for mac in macs:
|
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_dict = {'address': mac, 'node_id': node.id}
|
||||||
port = objects.Port(task.context, **port_dict)
|
port = objects.Port(task.context, **port_dict)
|
||||||
|
|
||||||
|
@ -55,17 +55,22 @@ class InspectFunctionTestCase(db_base.DbTestCase):
|
|||||||
port_obj1.create.assert_called_once_with()
|
port_obj1.create.assert_called_once_with()
|
||||||
port_obj2.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(utils.LOG, 'info', spec_set=True, autospec=True)
|
||||||
@mock.patch.object(objects.Port, 'create', 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,
|
def test_create_ports_if_not_exist_mac_exception(self,
|
||||||
create_mock,
|
create_mock,
|
||||||
log_mock):
|
log_mock,
|
||||||
|
warn_mock):
|
||||||
create_mock.side_effect = exception.MACAlreadyExists('f')
|
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,
|
with task_manager.acquire(self.context, self.node.uuid,
|
||||||
shared=False) as task:
|
shared=False) as task:
|
||||||
utils.create_ports_if_not_exist(task, macs)
|
utils.create_ports_if_not_exist(task, macs)
|
||||||
self.assertEqual(2, log_mock.call_count)
|
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(utils.LOG, 'info', spec_set=True, autospec=True)
|
||||||
@mock.patch.object(objects, 'Port', spec_set=True, autospec=True)
|
@mock.patch.object(objects, 'Port', spec_set=True, autospec=True)
|
||||||
|
5
releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml
Normal file
5
releasenotes/notes/invalid-mac-b0e3d99f23afeb30.yaml
Normal 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).
|
Loading…
x
Reference in New Issue
Block a user