def test_multiple_param_changes(mocker, pcluster_config_reader, test_datadir, src_cluster_label, dst_cluster_label): _do_mocking_for_tests(mocker) dst_config_file = "pcluster.config.dst.ini" duplicate_config_file(dst_config_file, test_datadir) src_dict = {} src_dict.update(default_cluster_params) src_dict["cluster_label"] = src_cluster_label src_dict["master_subnet_id"] = "subnet-12345678" src_dict["compute_subnet_id"] = "subnet-12345678" src_dict["additional_sg"] = "sg-12345678" src_config_file = pcluster_config_reader(**src_dict) src_conf = PclusterConfig(config_file=src_config_file, fail_on_file_absence=True) dst_dict = {} dst_dict.update(default_cluster_params) dst_dict["cluster_label"] = dst_cluster_label dst_dict["master_subnet_id"] = "subnet-1234567a" dst_dict["compute_subnet_id"] = "subnet-1234567a" dst_dict["additional_sg"] = "sg-1234567a" dst_config_file = pcluster_config_reader(dst_config_file, **dst_dict) dst_conf = PclusterConfig(config_file=dst_config_file) expected_changes = [ Change("vpc", "default", "master_subnet_id", "subnet-12345678", "subnet-1234567a", UpdatePolicy.UNSUPPORTED), Change( "vpc", "default", "compute_subnet_id", "subnet-12345678", "subnet-1234567a", UpdatePolicy.COMPUTE_FLEET_STOP ), Change("vpc", "default", "additional_sg", "sg-12345678", "sg-1234567a", UpdatePolicy.SUPPORTED), ] _check_patch(src_conf, dst_conf, expected_changes, UpdatePolicy.UNSUPPORTED)
def _test_more_target_sections(base_conf, target_conf): # Remove an ebs section into the base conf assert_that(base_conf.get_section("ebs", "ebs-1")).is_not_none() base_conf.remove_section("ebs", "ebs-1") assert_that(base_conf.get_section("ebs", "ebs-1")).is_none() # The patch must show 2 differences: one for ebs_settings and one for missing ebs section in base conf _check_patch( base_conf, target_conf, [ Change( "cluster", "default", "ebs_settings", "ebs-2", "ebs-1,ebs-2", UpdatePolicy( UpdatePolicy.UNSUPPORTED, fail_reason="EBS sections cannot be added or removed during a 'pcluster update' operation", ), ), Change("ebs", "ebs-1", "shared_dir", "-", "vol1", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-1", "volume_size", "-", 20, UpdatePolicy(UpdatePolicy.SUPPORTED)), ], UpdatePolicy.UNSUPPORTED, )
def _test_more_target_sections(base_conf, target_conf): # Remove an ebs section into the base conf assert_that(_get_storage_by_name(base_conf, "ebs1")).is_not_none() _remove_storage_by_name(base_conf, "ebs1") assert_that(_get_storage_by_name(base_conf, "ebs1")).is_none() # update some values in the target config for the remaining ebs target_storage = _get_storage_by_name(target_conf, "ebs2") target_storage["MountDir"] = "vol1" target_storage["EbsSettings"]["Iops"] = 20 target_storage["EbsSettings"]["VolumeType"] = "gp2" # The patch must show multiple differences: changes for EBS settings and one for missing ebs section in base conf _check_patch( base_conf, target_conf, [ Change( [], "SharedStorage", None, _get_storage_by_name(target_conf, "ebs1"), UpdatePolicy( UpdatePolicy.UNSUPPORTED, fail_reason= ("Shared Storage cannot be added or removed during a 'pcluster update-cluster' operation" ), ), is_list=True, ), Change(["SharedStorage[ebs2]"], "MountDir", "vol2", "vol1", UpdatePolicy.UNSUPPORTED, is_list=False), Change(["SharedStorage[ebs2]", "EbsSettings"], "Iops", None, 20, UpdatePolicy.SUPPORTED, is_list=False), Change( ["SharedStorage[ebs2]", "EbsSettings"], "VolumeType", "gp3", "gp2", UpdatePolicy.UNSUPPORTED, is_list=False, ), ], UpdatePolicy.UNSUPPORTED, )
def test_multiple_param_changes(mocker, pcluster_config_reader, test_datadir): mock_aws_api(mocker) dst_config_file = "pcluster.config.dst.yaml" _duplicate_config_file(dst_config_file, test_datadir) src_dict = {} src_dict.update(default_cluster_params) src_dict["head_node_subnet_id"] = "subnet-12345678" src_dict["compute_subnet_id"] = "subnet-12345678" src_dict["additional_sg"] = "sg-12345678" src_config_file = pcluster_config_reader(**src_dict) src_conf = _load_config(src_config_file) dst_dict = {} dst_dict.update(default_cluster_params) dst_dict["head_node_subnet_id"] = "subnet-1234567a" dst_dict["compute_subnet_id"] = "subnet-1234567a" dst_dict["additional_sg"] = "sg-1234567a" dst_config_file = pcluster_config_reader(dst_config_file, **dst_dict) dst_conf = _load_config(dst_config_file) expected_changes = [ Change( ["HeadNode", "Networking"], "SubnetId", "subnet-12345678", "subnet-1234567a", UpdatePolicy.UNSUPPORTED, is_list=False, ), Change( ["Scheduling", "SlurmQueues[queue1]", "Networking"], "SubnetIds", ["subnet-12345678"], ["subnet-1234567a"], UpdatePolicy.COMPUTE_FLEET_STOP, is_list=False, ), Change( ["HeadNode", "Networking"], "AdditionalSecurityGroups", ["sg-12345678"], ["sg-1234567a"], UpdatePolicy.SUPPORTED, is_list=False, ), ] _check_patch(src_conf.source_config, dst_conf.source_config, expected_changes, UpdatePolicy.UNSUPPORTED)
def test_single_param_change( test_datadir, pcluster_config_reader, mocker, section_key, section_label, param_key, src_param_value, dst_param_value, change_update_policy, ): _do_mocking_for_tests(mocker) dst_config_file = "pcluster.config.dst.ini" duplicate_config_file(dst_config_file, test_datadir) src_dict = {} src_dict.update(default_cluster_params) src_dict[param_key] = src_param_value src_config_file = pcluster_config_reader(**src_dict) src_conf = PclusterConfig(config_file=src_config_file, fail_on_file_absence=True) dst_dict = {} dst_dict.update(default_cluster_params) dst_dict[param_key] = dst_param_value dst_config_file = pcluster_config_reader(dst_config_file, **dst_dict) dst_conf = PclusterConfig(config_file=dst_config_file) expected_change = Change( section_key, section_label, param_key, src_param_value, dst_param_value, change_update_policy ) _check_patch(src_conf, dst_conf, [expected_change], change_update_policy)
def test_single_param_change( mocker, test_datadir, pcluster_config_reader, change_path, template_rendering_key, param_key, src_param_value, dst_param_value, change_update_policy, is_list, ): mock_aws_api(mocker) dst_config_file = "pcluster.config.dst.yaml" _duplicate_config_file(dst_config_file, test_datadir) src_dict = {} src_dict.update(default_cluster_params) src_dict[template_rendering_key] = src_param_value src_config_file = pcluster_config_reader(**src_dict) src_conf = _load_config(src_config_file) dst_dict = {} dst_dict.update(default_cluster_params) dst_dict[template_rendering_key] = dst_param_value dst_config_file = pcluster_config_reader(dst_config_file, **dst_dict) dst_conf = _load_config(dst_config_file) if is_list: expected_change = Change(change_path, param_key, [src_param_value], [dst_param_value], change_update_policy, is_list=False) else: expected_change = Change(change_path, param_key, src_param_value, dst_param_value, change_update_policy, is_list=False) _check_patch(src_conf.source_config, dst_conf.source_config, [expected_change], change_update_policy)
def _test_different_labels(base_conf, target_conf): # First make sure sections are present with original labels base_ebs_1_section = base_conf.get_section("ebs", "ebs-1") base_ebs_2_section = base_conf.get_section("ebs", "ebs-2") assert_that(base_ebs_1_section).is_not_none() assert_that(base_ebs_2_section).is_not_none() # Now update section labels and make sure they're not more present with original labels base_ebs_1_section.label = "ebs-1_updated" base_ebs_2_section.label = "ebs-2_updated" assert_that(base_conf.get_section("ebs", "ebs-1_updated")).is_not_none() assert_that(base_conf.get_section("ebs", "ebs-2_updated")).is_not_none() assert_that(base_conf.get_section("ebs", "ebs-1")).is_none() assert_that(base_conf.get_section("ebs", "ebs-2")).is_none() # The patch should contain 5 differences: # - 2 volumes in target conf not matched in base conf # - 2 volumes in base conf not matched in target conf # - 1 ebs_settings changed in cluster section _check_patch( base_conf, target_conf, [ Change("ebs", "ebs-1", "shared_dir", "-", "vol1", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-1_updated", "shared_dir", "vol1", "-", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-2", "shared_dir", "-", "vol2", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-2_updated", "shared_dir", "vol2", "-", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-1", "volume_size", "-", 20, UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-1_updated", "volume_size", 20, "-", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-2", "volume_size", "-", 20, UpdatePolicy(UpdatePolicy.SUPPORTED)), Change("ebs", "ebs-2_updated", "volume_size", 20, "-", UpdatePolicy(UpdatePolicy.SUPPORTED)), Change( "cluster", "default", "ebs_settings", "ebs-1_updated,ebs-2_updated", "ebs-1,ebs-2", UpdatePolicy( UpdatePolicy.UNSUPPORTED, fail_reason="EBS sections cannot be added or removed during a 'pcluster update' operation", ), ), ], UpdatePolicy.UNSUPPORTED, )
def _test_incompatible_ebs_sections(base_conf, target_conf): # Change shared_dir param value in target conf target_conf.get_section("ebs", "ebs-1").get_param("shared_dir").value = "new_value" # The patch must show the updated shared_dir for ebs-1 section _check_patch( base_conf, target_conf, [Change("ebs", "ebs-1", "shared_dir", "vol1", "new_value", UpdatePolicy(UpdatePolicy.UNSUPPORTED))], UpdatePolicy.UNSUPPORTED, )
def _test_incompatible_ebs_sections(base_conf, target_conf): # Change MountDir param value in target conf _get_storage_by_name(target_conf, "ebs1")["MountDir"] = "new_value" # The patch must show the updated MountDir for ebs1 section _check_patch( base_conf, target_conf, [ Change(["SharedStorage[ebs1]"], "MountDir", "vol1", "new_value", UpdatePolicy(UpdatePolicy.UNSUPPORTED), False) ], UpdatePolicy.UNSUPPORTED, )
def _test_different_names(base_conf, target_conf): # First make sure sections are present with original names base_ebs_1_section = _get_storage_by_name(base_conf, "ebs1") base_ebs_2_section = _get_storage_by_name(base_conf, "ebs2") assert_that(base_ebs_1_section).is_not_none() assert_that(base_ebs_2_section).is_not_none() target_ebs_1_section = _get_storage_by_name(target_conf, "ebs1") target_ebs_2_section = _get_storage_by_name(target_conf, "ebs2") assert_that(target_ebs_1_section).is_not_none() assert_that(target_ebs_2_section).is_not_none() # Now update section labels and make sure they're not more present with original labels target_ebs_1_section["Name"] = "ebs1_updated" target_ebs_2_section["Name"] = "ebs2_updated" assert_that(_get_storage_by_name(target_conf, "ebs1_updated")).is_not_none() assert_that(_get_storage_by_name(target_conf, "ebs2_updated")).is_not_none() assert_that(_get_storage_by_name(target_conf, "ebs1")).is_none() assert_that(_get_storage_by_name(target_conf, "ebs-")).is_none() unsupported_update_policy = UpdatePolicy( UpdatePolicy.UNSUPPORTED, fail_reason= "Shared Storage cannot be added or removed during a 'pcluster update-cluster' operation", ) # The patch should contain 5 differences: # - 2 volumes in target conf not matched in base conf # - 2 volumes in base conf not matched in target conf _check_patch( base_conf, target_conf, [ Change([], "SharedStorage", None, target_ebs_1_section, unsupported_update_policy, is_list=True), Change([], "SharedStorage", None, target_ebs_2_section, unsupported_update_policy, is_list=True), Change([], "SharedStorage", base_ebs_1_section, None, unsupported_update_policy, is_list=True), Change([], "SharedStorage", base_ebs_2_section, None, unsupported_update_policy, is_list=True), ], UpdatePolicy.UNSUPPORTED, )