Skip to content

Commit 8360d5d

Browse files
committed
Use list of dict to remove duplicate nodes in _find_active_nodes()
Signed-off-by: Jacopo De Amicis <jdamicis@amazon.it>
1 parent 6ce409b commit 8360d5d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/slurm_plugin/clustermgtd.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,12 +1123,11 @@ def _find_bootstrap_failure_nodes(slurm_nodes):
11231123

11241124
@staticmethod
11251125
def _find_active_nodes(partitions_name_map):
1126-
active_nodes = set()
1126+
active_nodes = []
11271127
for partition in partitions_name_map.values():
11281128
if partition.state != "INACTIVE":
1129-
active_nodes |= set(partition.slurm_nodes)
1130-
# TODO: Returning the set breaks some unit tests (I believe the unit test should be revised though).
1131-
return sorted(list(active_nodes), key=str)
1129+
active_nodes += partition.slurm_nodes
1130+
return list(dict.fromkeys(active_nodes))
11321131

11331132
def _is_node_in_replacement_valid(self, node, check_node_is_valid):
11341133
"""

tests/slurm_plugin/test_clustermgtd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,14 +1314,13 @@ def test_maintain_nodes(
13141314
# Run test
13151315
cluster_manager._maintain_nodes(partitions, {})
13161316
# Check function calls
1317-
active_nodes_sorted = sorted(active_nodes, key=str)
1318-
mock_update_replacement.assert_called_with(active_nodes_sorted)
1317+
mock_update_replacement.assert_called_with(active_nodes)
13191318
mock_handle_dynamic.assert_called_with(expected_unhealthy_dynamic_nodes)
13201319
mock_handle_static.assert_called_with(expected_unhealthy_static_nodes)
1321-
mock_handle_powering_down_nodes.assert_called_with(active_nodes_sorted)
1322-
mock_handle_failed_health_check_nodes_in_replacement.assert_called_with(active_nodes_sorted)
1320+
mock_handle_powering_down_nodes.assert_called_with(active_nodes)
1321+
mock_handle_failed_health_check_nodes_in_replacement.assert_called_with(active_nodes)
13231322
if _is_protected_mode_enabled:
1324-
mock_handle_protected_mode_process.assert_called_with(active_nodes_sorted, partitions)
1323+
mock_handle_protected_mode_process.assert_called_with(active_nodes, partitions)
13251324
else:
13261325
mock_handle_protected_mode_process.assert_not_called()
13271326

0 commit comments

Comments
 (0)