Skip to content

Commit b7e1488

Browse files
all changes
Signed-off-by: Hanwen <[email protected]>
1 parent 7c47acc commit b7e1488

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed

cli/src/pcluster/config/config_patch.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,26 @@ def _compare_section(self, base_section: dict, target_section: dict, section_sch
137137
)
138138
else:
139139
# Simple param
140-
target_value = target_section.get(data_key, None) if target_section else None
141-
base_value = base_section.get(data_key, None) if base_section else None
140+
target_value, data_key = self._get_value_from_section(data_key, target_section)
141+
base_value, data_key = self._get_value_from_section(data_key, base_section)
142142

143143
if target_value != base_value:
144144
# Add param change information
145145
self.changes.append(
146146
Change(param_path, data_key, base_value, target_value, change_update_policy, is_list=False)
147147
)
148148

149+
def _get_value_from_section(self, data_key, target_section):
150+
target_value = None
151+
if target_section:
152+
target_value = target_section.get(data_key, None)
153+
if data_key == "Script" and target_value is None:
154+
# This handles special case when multiple installation scripts are provided.
155+
# The schema of script sequence is customized. The following code correctly detect changes.
156+
target_value = target_section.get("Sequence", None)
157+
data_key = "Sequence"
158+
return target_value, data_key
159+
149160
def _compare_nested_section(self, param_path, data_key, base_value, target_value, field_obj):
150161
# Compare nested sections and params
151162
nested_path = copy.deepcopy(param_path)

cli/tests/pcluster/config/test_config_patch.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,35 @@ def _test_no_updatable_custom_actions(base_conf, target_conf):
439439
)
440440

441441

442+
def _test_no_updatable_custom_actions_sequence(base_conf, target_conf):
443+
base_conf["HeadNode"].update(
444+
{
445+
"CustomActions": {
446+
"OnNodeConfigured": {"Sequence": [{"Script": "test-to-edit.sh", "Args": ["1", "2"]}]},
447+
}
448+
}
449+
)
450+
target_conf["HeadNode"].update(
451+
{"CustomActions": {"OnNodeConfigured": {"Sequence": [{"Script": "test-to-edit.sh", "Args": ["2"]}]}}}
452+
)
453+
454+
_check_patch(
455+
base_conf,
456+
target_conf,
457+
[
458+
Change(
459+
["HeadNode", "CustomActions", "OnNodeConfigured"],
460+
"Sequence",
461+
[{"Script": "test-to-edit.sh", "Args": ["1", "2"]}],
462+
[{"Script": "test-to-edit.sh", "Args": ["2"]}],
463+
UpdatePolicy.UNSUPPORTED,
464+
is_list=False,
465+
),
466+
],
467+
UpdatePolicy.UNSUPPORTED,
468+
)
469+
470+
442471
def _test_updatable_custom_actions_attributes(base_conf, target_conf):
443472
base_conf["HeadNode"].update(
444473
{"CustomActions": {"OnNodeUpdated": {"Script": "test-to-edit.sh", "Args": ["1", "2"]}}}
@@ -491,6 +520,71 @@ def _test_updatable_custom_actions(base_conf, target_conf):
491520
)
492521

493522

523+
def _test_updatable_custom_actions_sequence_add(base_conf, target_conf):
524+
target_conf["HeadNode"].update(
525+
{"CustomActions": {"OnNodeUpdated": {"Sequence": [{"Script": "test-to-remove.sh"}]}}}
526+
)
527+
528+
_check_patch(
529+
base_conf,
530+
target_conf,
531+
[
532+
Change(
533+
["HeadNode", "CustomActions"],
534+
"OnNodeUpdated",
535+
"-",
536+
{"Sequence": [{"Script": "test-to-remove.sh"}]},
537+
UpdatePolicy.SUPPORTED,
538+
is_list=False,
539+
),
540+
],
541+
UpdatePolicy.SUPPORTED,
542+
)
543+
544+
545+
def _test_updatable_custom_actions_sequence_change(base_conf, target_conf):
546+
base_conf["HeadNode"].update({"CustomActions": {"OnNodeUpdated": {"Sequence": [{"Script": "test-to-remove.sh"}]}}})
547+
target_conf["HeadNode"].update(
548+
{"CustomActions": {"OnNodeUpdated": {"Sequence": [{"Script": "another-script.sh"}]}}}
549+
)
550+
551+
_check_patch(
552+
base_conf,
553+
target_conf,
554+
[
555+
Change(
556+
["HeadNode", "CustomActions", "OnNodeUpdated"],
557+
"Sequence",
558+
[{"Script": "test-to-remove.sh"}],
559+
[{"Script": "another-script.sh"}],
560+
UpdatePolicy.SUPPORTED,
561+
is_list=False,
562+
),
563+
],
564+
UpdatePolicy.SUPPORTED,
565+
)
566+
567+
568+
def _test_updatable_custom_actions_sequence_remove(base_conf, target_conf):
569+
base_conf["HeadNode"].update({"CustomActions": {"OnNodeUpdated": {"Sequence": [{"Script": "test-to-remove.sh"}]}}})
570+
571+
_check_patch(
572+
base_conf,
573+
target_conf,
574+
[
575+
Change(
576+
["HeadNode", "CustomActions"],
577+
"OnNodeUpdated",
578+
{"Sequence": [{"Script": "test-to-remove.sh"}]},
579+
"-",
580+
UpdatePolicy.SUPPORTED,
581+
is_list=False,
582+
),
583+
],
584+
UpdatePolicy.SUPPORTED,
585+
)
586+
587+
494588
def _test_less_target_sections(base_conf, target_conf):
495589
# Remove an ebs section in the target conf
496590
assert_that(_get_storage_by_name(target_conf, "ebs1")).is_not_none()
@@ -905,8 +999,12 @@ def _test_iam(base_conf, target_conf):
905999
_test_compute_resources,
9061000
_test_queues,
9071001
_test_no_updatable_custom_actions,
1002+
_test_no_updatable_custom_actions_sequence,
9081003
_test_updatable_custom_actions,
9091004
_test_updatable_custom_actions_attributes,
1005+
_test_updatable_custom_actions_sequence_add,
1006+
_test_updatable_custom_actions_sequence_change,
1007+
_test_updatable_custom_actions_sequence_remove,
9101008
_test_storage,
9111009
_test_iam,
9121010
],

0 commit comments

Comments
 (0)