Skip to content

Commit ab2d170

Browse files
committed
Have port_bios_name out-of-band inspection hook set the port name
We were leaving these NULL but actually it is better to have the port name set to something meaningful.
1 parent c900d19 commit ab2d170

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

python/ironic-understack/ironic_understack/port_bios_name_hook.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ def __call__(self, task, inventory, plugin_data):
5252
baremetal_port.pxe_enabled = required_pxe
5353
baremetal_port.save()
5454

55+
if required_bios_name:
56+
required_port_name = task.node.name + ":" + required_bios_name
57+
if baremetal_port.name != required_port_name:
58+
LOG.info(
59+
"Port %s changing name from %s to %s",
60+
mac,
61+
baremetal_port.name,
62+
required_port_name,
63+
)
64+
baremetal_port.name = required_port_name
65+
5566

5667
def _pxe_interface_name(inspected_interfaces: list[dict]) -> str:
5768
"""Use a heuristic to determine our default interface for PXE."""

python/ironic-understack/ironic_understack/tests/test_port_bios_name_hook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ def test_adding_bios_name(mocker, caplog):
1919
node_uuid = uuidutils.generate_uuid()
2020
mock_context = mocker.Mock()
2121
mock_node = mocker.Mock(id=1234)
22+
mock_node.name = "Dell-CR1MB0"
2223
mock_task = mocker.Mock(node=mock_node, context=mock_context)
2324
mock_port = mocker.Mock(
2425
uuid=uuidutils.generate_uuid(),
2526
node_id=node_uuid,
2627
address="11:11:11:11:11:11",
2728
extra={},
2829
)
30+
mock_port.name = "some-arbitrary-name"
2931

3032
mocker.patch(
3133
"ironic_understack.port_bios_name_hook.ironic_ports_for_node",
@@ -35,6 +37,7 @@ def test_adding_bios_name(mocker, caplog):
3537
PortBiosNameHook().__call__(mock_task, _INVENTORY, {})
3638

3739
assert mock_port.extra == {"bios_name": "NIC.Integrated.1-1"}
40+
assert mock_port.name == "Dell-CR1MB0:NIC.Integrated.1-1"
3841
mock_port.save.assert_called()
3942

4043

@@ -44,13 +47,15 @@ def test_removing_bios_name(mocker, caplog):
4447
node_uuid = uuidutils.generate_uuid()
4548
mock_context = mocker.Mock()
4649
mock_node = mocker.Mock(id=1234)
50+
mock_node.name = "Dell-CR1MB0"
4751
mock_task = mocker.Mock(node=mock_node, context=mock_context)
4852
mock_port = mocker.Mock(
4953
uuid=uuidutils.generate_uuid(),
5054
node_id=node_uuid,
5155
address="33:33:33:33:33:33",
5256
extra={"bios_name": "old_name_no_longer_valid"},
5357
)
58+
mock_port.name = "original-name"
5459

5560
mocker.patch(
5661
"ironic_understack.port_bios_name_hook.ironic_ports_for_node",
@@ -59,5 +64,6 @@ def test_removing_bios_name(mocker, caplog):
5964

6065
PortBiosNameHook().__call__(mock_task, _INVENTORY, {})
6166

67+
assert mock_port.name == "original-name"
6268
assert "bios_name" not in mock_port.extra
6369
mock_port.save.assert_called()

0 commit comments

Comments
 (0)