Skip to content

Commit 28d385d

Browse files
committed
Force use of qualified switch names in local_link_info
These need to be consistent with existing data.
1 parent 4048810 commit 28d385d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

python/ironic-understack/ironic_understack/inspected_port.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def local_link_connection(self) -> dict:
2121

2222
@property
2323
def parsed_name(self) -> dict[str, str]:
24-
parts = self.switch_system_name.split(".", maxsplit=1)
25-
if len(parts) != 2:
24+
parts = self.switch_system_name.split(".")
25+
if len(parts) < 2:
2626
raise ValueError(
2727
"Failed to parse switch hostname - expecting name.dc in %s", self
2828
)
29-
switch_name, data_center_name = parts
29+
switch_name, data_center_name = parts[0:2]
3030

3131
parts = switch_name.rsplit("-", maxsplit=1)
3232
if len(parts) != 2:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ironic.objects
44
from oslo_utils import uuidutils
55

6-
import ironic_understack
76
from ironic_understack.update_baremetal_port import UpdateBaremetalPortsHook
87

98
# load some metaprgramming normally taken care of during Ironic initialization:
@@ -95,7 +94,7 @@ def test_with_valid_data(mocker, caplog):
9594
assert mock_port.local_link_connection == {
9695
"port_id": "Ethernet1/18",
9796
"switch_id": "88:5a:92:ec:54:59",
98-
"switch_info": "f20-3-1.iad3",
97+
"switch_info": "f20-3-1.iad3.rackspace.net",
9998
}
10099
assert mock_port.physical_network == "f20-3-network"
101100
mock_port.save.assert_called()

python/ironic-understack/ironic_understack/update_baremetal_port.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __call__(self, task, inventory, plugin_data):
3434
3535
- local_link_info.port_id (e.g. "Ethernet1/1")
3636
- local_link_info.switch_id (e.g. "aa:bb:cc:dd:ee:ff")
37-
- local_link_info.switch_info (e.g. "a1-1-1.ord1")
37+
- local_link_info.switch_info (e.g. "a1-1-1.ord1.rackspace.net")
3838
- physical_network (e.g. "a1-1-network")
3939
4040
We also add or remove node "traits" based on the inventory data. We
@@ -72,14 +72,21 @@ def _parse_plugin_data(plugin_data: dict) -> list[InspectedPort]:
7272
InspectedPort(
7373
mac_address=mac[name],
7474
name=name,
75-
switch_system_name=str(lldp["switch_system_name"]).lower(),
75+
switch_system_name=_normalise_switch_name(lldp["switch_system_name"]),
7676
switch_chassis_id=str(lldp["switch_chassis_id"]).lower(),
7777
switch_port_id=str(lldp["switch_port_id"]),
7878
)
7979
for name, lldp in plugin_data["parsed_lldp"].items()
8080
]
8181

8282

83+
def _normalise_switch_name(name: str) -> str:
84+
suffix = ".rackspace.net"
85+
name = str(name).lower()
86+
name = name if name.endswith(suffix) else name + suffix
87+
return name
88+
89+
8390
def _update_port_attrs(task, ports_by_mac, vlan_groups, node_uuid):
8491
for baremetal_port in ironic_ports_for_node(task.context, task.node.id):
8592
inspected_port = ports_by_mac.get(baremetal_port.address)

0 commit comments

Comments
 (0)