Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/ironic-understack/ironic_understack/port_bios_name_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def __call__(self, task, inventory, plugin_data):
baremetal_port.pxe_enabled = required_pxe
baremetal_port.save()

if required_bios_name:
required_port_name = task.node.name + ":" + required_bios_name
if baremetal_port.name != required_port_name:
LOG.info(
"Port %s changing name from %s to %s",
mac,
baremetal_port.name,
required_port_name,
)
baremetal_port.name = required_port_name


def _pxe_interface_name(inspected_interfaces: list[dict]) -> str:
"""Use a heuristic to determine our default interface for PXE."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def test_adding_bios_name(mocker, caplog):
node_uuid = uuidutils.generate_uuid()
mock_context = mocker.Mock()
mock_node = mocker.Mock(id=1234)
mock_node.name = "Dell-CR1MB0"
mock_task = mocker.Mock(node=mock_node, context=mock_context)
mock_port = mocker.Mock(
uuid=uuidutils.generate_uuid(),
node_id=node_uuid,
address="11:11:11:11:11:11",
extra={},
)
mock_port.name = "some-arbitrary-name"

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

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


Expand All @@ -44,13 +47,15 @@ def test_removing_bios_name(mocker, caplog):
node_uuid = uuidutils.generate_uuid()
mock_context = mocker.Mock()
mock_node = mocker.Mock(id=1234)
mock_node.name = "Dell-CR1MB0"
mock_task = mocker.Mock(node=mock_node, context=mock_context)
mock_port = mocker.Mock(
uuid=uuidutils.generate_uuid(),
node_id=node_uuid,
address="33:33:33:33:33:33",
extra={"bios_name": "old_name_no_longer_valid"},
)
mock_port.name = "original-name"

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

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

assert mock_port.name == "original-name"
assert "bios_name" not in mock_port.extra
mock_port.save.assert_called()
Loading