Skip to content

Commit d58bcc5

Browse files
committed
Fix inspection hook "category" logic in baremetal-ports
Today we have only two possible categories: network and storage. This code was saying "if it isn't network then it is storage" which happens to be correct today, but will stop being correct if we add a third category. The category will be set correctly because it is determined from the suffix of the "physical network" value, which on a storage port will have a value ending in "-storage")
1 parent f83b76f commit d58bcc5

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

python/ironic-understack/ironic_understack/inspect_hook_update_baremetal_ports.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def _set_port_attributes(
134134

135135
if physical_network and not physical_network.endswith("-network"):
136136
physical_network = None
137-
category = "storage"
138137

139138
if port.physical_network != physical_network:
140139
LOG.debug(

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

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
}
6464

6565

66-
def test_with_valid_data(mocker, caplog):
66+
def test_with_valid_network_port(mocker, caplog):
6767
caplog.set_level(logging.DEBUG)
6868

6969
node_uuid = uuidutils.generate_uuid()
@@ -88,10 +88,9 @@ def test_with_valid_data(mocker, caplog):
8888
"ironic_understack.inspect_hook_update_baremetal_ports.CONF.ironic_understack.switch_name_vlan_group_mapping",
8989
MAPPING,
9090
)
91-
trait_create = mocker.patch(
91+
mocker.patch(
9292
"ironic_understack.inspect_hook_update_baremetal_ports.objects.TraitList.create"
9393
)
94-
9594
mock_traits.get_trait_names.return_value = ["CUSTOM_BMC_SWITCH", "bar"]
9695

9796
InspectHookUpdateBaremetalPorts().__call__(mock_task, _INVENTORY, _PLUGIN_DATA)
@@ -104,8 +103,75 @@ def test_with_valid_data(mocker, caplog):
104103
assert mock_port.physical_network == "f20-3-network"
105104
assert mock_port.category == "network"
106105
mock_port.save.assert_called()
107-
mock_node.save.assert_called_once()
108106

107+
108+
def test_with_valid_storage_port(mocker, caplog):
109+
caplog.set_level(logging.DEBUG)
110+
111+
node_uuid = uuidutils.generate_uuid()
112+
mock_traits = mocker.Mock()
113+
mock_context = mocker.Mock()
114+
mock_node = mocker.Mock(id=1234, traits=mock_traits)
115+
mock_task = mocker.Mock(node=mock_node, context=mock_context)
116+
mock_port = mocker.Mock(
117+
uuid=uuidutils.generate_uuid(),
118+
node_id=node_uuid,
119+
address="33:33:33:33:33:33",
120+
local_link_connection={},
121+
physical_network="original_value",
122+
category=None,
123+
)
124+
125+
mocker.patch(
126+
"ironic_understack.inspect_hook_update_baremetal_ports.ironic_ports_for_node",
127+
return_value=[mock_port],
128+
)
129+
mocker.patch(
130+
"ironic_understack.inspect_hook_update_baremetal_ports.CONF.ironic_understack.switch_name_vlan_group_mapping",
131+
MAPPING,
132+
)
133+
mocker.patch(
134+
"ironic_understack.inspect_hook_update_baremetal_ports.objects.TraitList.create"
135+
)
136+
mock_traits.get_trait_names.return_value = ["CUSTOM_BMC_SWITCH", "bar"]
137+
138+
InspectHookUpdateBaremetalPorts().__call__(mock_task, _INVENTORY, _PLUGIN_DATA)
139+
140+
assert mock_port.local_link_connection == {
141+
"port_id": "Ethernet1/18",
142+
"switch_id": "88:5a:92:ec:54:59",
143+
"switch_info": "f20-3-1f.iad3.rackspace.net",
144+
}
145+
assert mock_port.physical_network is None
146+
assert mock_port.category == "storage"
147+
mock_port.save.assert_called()
148+
149+
150+
def test_node_traits_updated(mocker, caplog):
151+
caplog.set_level(logging.DEBUG)
152+
153+
mock_traits = mocker.Mock()
154+
mock_context = mocker.Mock()
155+
mock_node = mocker.Mock(id=1234, traits=mock_traits)
156+
mock_task = mocker.Mock(node=mock_node, context=mock_context)
157+
158+
mocker.patch(
159+
"ironic_understack.inspect_hook_update_baremetal_ports.ironic_ports_for_node",
160+
return_value=[],
161+
)
162+
mocker.patch(
163+
"ironic_understack.inspect_hook_update_baremetal_ports.CONF.ironic_understack.switch_name_vlan_group_mapping",
164+
MAPPING,
165+
)
166+
trait_create = mocker.patch(
167+
"ironic_understack.inspect_hook_update_baremetal_ports.objects.TraitList.create"
168+
)
169+
170+
mock_traits.get_trait_names.return_value = ["CUSTOM_BMC_SWITCH", "bar"]
171+
172+
InspectHookUpdateBaremetalPorts().__call__(mock_task, _INVENTORY, _PLUGIN_DATA)
173+
174+
mock_node.save.assert_called_once()
109175
trait_create.assert_called_once_with(
110176
mock_context, 1234, {"CUSTOM_STORAGE_SWITCH", "CUSTOM_NETWORK_SWITCH", "bar"}
111177
)

0 commit comments

Comments
 (0)