Skip to content

Commit 807ed39

Browse files
committed
Fix inspection hook trait handling for adding node traits
1 parent beefed9 commit 807ed39

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def test_with_valid_data(mocker, caplog):
102102

103103
mock_traits.get_trait_names.assert_called_once()
104104
mock_traits.destroy.assert_called_once_with("CUSTOM_BMC_SWITCH")
105-
ironic_understack.update_baremetal_port.objects.TraitList.create.assert_called_once_with(
106-
mock_context, 1234, ["CUSTOM_NETWORK_SWITCH", "CUSTOM_STORAGE_SWITCH"]
107-
)
105+
mock_traits.append.assert_any_call("CUSTOM_NETWORK_SWITCH")
106+
mock_traits.append.assert_any_call("CUSTOM_STORAGE_SWITCH")
108107
mock_node.save.assert_called_once()

python/ironic-understack/ironic_understack/update_baremetal_port.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any
22

3-
import openstack
43
from ironic import objects
54
from ironic.common import exception
65
from ironic.drivers.modules.inspector.hooks import base
@@ -174,31 +173,14 @@ def _set_node_traits(task, vlan_groups: set[str]):
174173
required_traits = {_trait_name(x) for x in vlan_groups if x}
175174
existing_traits = set(node.traits.get_trait_names()).intersection(our_traits)
176175

177-
traits_to_remove = sorted(existing_traits.difference(required_traits))
178-
traits_to_add = sorted(required_traits.difference(existing_traits))
179-
180176
LOG.debug(
181177
"Checking traits for node %s: existing=%s required=%s",
182178
node.uuid,
183179
existing_traits,
184180
required_traits,
185181
)
186-
187-
for trait in traits_to_remove:
188-
LOG.debug("Removing trait %s from node %s", trait, node.uuid)
189-
try:
190-
node.traits.destroy(trait)
191-
except openstack.exceptions.NotFoundException:
192-
pass
193-
194-
if traits_to_add:
195-
LOG.debug("Adding traits %s to node %s", traits_to_add, node.uuid)
196-
197-
node.traits = objects.TraitList.create(
198-
task.context, node.id, list(traits_to_add)
199-
)
200-
201-
if traits_to_add or traits_to_remove:
182+
if existing_traits != required_traits:
183+
objects.TraitList.create(task.context, task.node.id, required_traits)
202184
node.save()
203185

204186

0 commit comments

Comments
 (0)