in cli/src/pcluster/config/config_patch.py [0:0]
def _compare_section(self, base_section: dict, target_section: dict, section_schema: BaseSchema, param_path: List):
"""
Compare the provided base and target sections and append the detected changes to the internal changes list.
:param base_section: The section in the base configuration
:param target_section: The corresponding section in the target configuration
:param section_schema: schema corresponding to the section to be analyzed (contains all the resources/params)
:param param_path: A list on which the items correspond to the path of the param in the configuration schema
"""
for _, field_obj in section_schema.declared_fields.items():
data_key = field_obj.data_key
is_nested_section = hasattr(field_obj, "nested")
is_list = hasattr(field_obj, "many") and field_obj.many
change_update_policy = field_obj.metadata.get("update_policy", UpdatePolicy.UNSUPPORTED)
if is_nested_section:
if is_list:
self._compare_list(
base_section, target_section, param_path, data_key, field_obj, change_update_policy
)
else:
# Single nested section
target_value = target_section.get(data_key, None) if target_section else None
base_value = base_section.get(data_key, None) if base_section else None
if target_value and base_value:
self._compare_nested_section(param_path, data_key, base_value, target_value, field_obj)
elif target_value or base_value:
# One section has been added or removed
if change_update_policy is UpdatePolicy.IGNORED:
# Traverse config if UpdatePolicy is IGNORED
self._compare_nested_section(param_path, data_key, base_value, target_value, field_obj)
else:
# Add section change information
self.changes.append(
Change(
param_path,
data_key,
base_value if base_value else "-",
target_value if target_value else "-",
change_update_policy,
is_list=False,
)
)
else:
# Simple param
target_value, target_data_key = self._get_value_from_section(data_key, target_section)
base_value, base_data_key = self._get_value_from_section(data_key, base_section)
if target_data_key != base_data_key:
# So far, this only happens when custom actions scripts are changed across simple and sequence.
data_key = param_path.pop()
base_value = {base_data_key: base_value}
target_value = {target_data_key: target_value}
else:
# So far, target_data_key is different from data_key only when
# custom actions scripts are in sequence.
data_key = target_data_key
if target_value != base_value:
# Add param change information
self.changes.append(
Change(param_path, data_key, base_value, target_value, change_update_policy, is_list=False)
)