Ejemplo n.º 1
0
def test_defaults_consistency():
    """Verifies that the defaults values for the CFN parameters used in the tests are the same in the CFN template."""
    template_num_of_params = _get_pcluster_cfn_num_of_params()

    # verify that the number of parameters in the template is lower than the limit of 60 parameters
    # https://docs.aws.amazon.com/en_us/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
    assert_that(template_num_of_params).is_less_than_or_equal_to(60)

    # verify number of parameters used for tests with number of parameters in CFN template
    total_number_of_params = CFN_CONFIG_NUM_OF_PARAMS + len(
        CFN_CLI_RESERVED_PARAMS)
    assert_that(total_number_of_params).is_equal_to(template_num_of_params)

    # The EC2IAMPoicies parameter is expected to differ by default from the default value in the
    # CFN template. This is because CloudWatch logging is enabled by default, and the appropriate
    # policy is added to this parameter in a transparent fashion.
    ignored_params = CFN_CLI_RESERVED_PARAMS + ["EC2IAMPolicies"]

    cfn_params = [
        section_cfn_params.value for section_cfn_params in DefaultCfnParams
    ]
    default_cfn_values = utils.merge_dicts(*cfn_params)

    # verify default parameter values used for tests with default values in CFN template
    pcluster_cfn_json = _get_pcluster_cfn_json()
    for param_key, param in pcluster_cfn_json["Parameters"].items():
        if param_key not in ignored_params:
            default_value = param.get("Default", None)
            if default_value:
                assert_that(default_value, description=param_key).is_equal_to(
                    default_cfn_values.get(param_key, None))
Ejemplo n.º 2
0
def test_defaults_consistency():
    """Verifies that the defaults values for the CFN parameters used in the tests are the same in the CFN template."""
    template_num_of_params = _get_pcluster_cfn_num_of_params()

    # verify that the number of parameters in the template is lower than the limit of 60 parameters
    # https://docs.aws.amazon.com/en_us/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
    assert_that(template_num_of_params).is_less_than_or_equal_to(60)

    # verify number of parameters used for tests with number of parameters in CFN template
    total_number_of_params = CFN_CONFIG_NUM_OF_PARAMS + len(
        CFN_CLI_RESERVED_PARAMS)
    assert_that(total_number_of_params).is_equal_to(template_num_of_params)

    cfn_params = [
        section_cfn_params.value for section_cfn_params in DefaultCfnParams
    ]
    default_cfn_values = utils.merge_dicts(*cfn_params)

    # verify default parameter values used for tests with default values in CFN template
    pcluster_cfn_json = _get_pcluster_cfn_json()
    for param_key, param in pcluster_cfn_json["Parameters"].items():
        if param_key not in CFN_CLI_RESERVED_PARAMS:
            default_value = param.get("Default", None)
            if default_value:
                assert_that(default_value, description=param_key).is_equal_to(
                    default_cfn_values.get(param_key, None))
)
def test_cw_log_settings_section_from_cfn(mocker, cfn_params_dict,
                                          expected_section_dict):
    """Verify expected cw_log_settings config file section results from given CFN params."""
    utils.assert_section_from_cfn(mocker, CW_LOG, cfn_params_dict,
                                  expected_section_dict)


@pytest.mark.parametrize(
    "settings_label, expected_cfn_params",
    [
        ("defaults", DefaultCfnParams["cluster_sit"].value),
        (
            "disabled",
            utils.merge_dicts(DefaultCfnParams["cluster_sit"].value, {
                "EC2IAMPolicies": "NONE",
                "CWLogOptions": "false,14"
            }),
        ),
        ("one_day_retention",
         utils.merge_dicts(DefaultCfnParams["cluster_sit"].value,
                           {"CWLogOptions": "true,1"})),
        ("bad_retention_val", SystemExit()),
        ("bad_enable_val", SystemExit()),
        ("empty_enable_val", SystemExit()),
        ("empty_retention_days", SystemExit()),
        ("nonexistent", SystemExit()),
    ],
)
def test_cw_log_from_file_to_cfn(mocker, pcluster_config_reader,
                                 settings_label, expected_cfn_params):
    """Verify various cw_log sections results in expected CFN parameters."""
Ejemplo n.º 4
0
     },
     DefaultDict["fsx"].value,
 ),
 (
     {
         "FSXOptions":
         "NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE"
     },
     DefaultDict["fsx"].value,
 ),
 (
     {
         "FSXOptions":
         "test,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE,NONE"
     },
     utils.merge_dicts(DefaultDict["fsx"].value,
                       {"shared_dir": "test"}),
 ),
 (
     {
         "FSXOptions":
         "test,test1,10,test2,20,test3,test4,test5,SCRATCH_1,"
         "50,01:00,5,false,backup-0a1b2c3d4e5f6a7b8,NEW_CHANGED,HDD,READ"
     },
     {
         "shared_dir": "test",
         "fsx_fs_id": "test1",
         "storage_capacity": 10,
         "fsx_kms_key_id": "test2",
         "imported_file_chunk_size": 20,
         "export_path": "test3",
         "import_path": "test4",
Ejemplo n.º 5
0
    utils.assert_param_from_file(mocker, EBS, param_key, param_value,
                                 expected_value, expected_message)


@pytest.mark.parametrize(
    "settings_label, expected_cfn_params",
    [
        (
            "ebs1",
            utils.merge_dicts(
                DefaultCfnParams["cluster"].value,
                {
                    "NumberOfEBSVol": "1",
                    "SharedDir": "ebs1,NONE,NONE,NONE,NONE",
                    "VolumeType": "io1,gp2,gp2,gp2,gp2",
                    "VolumeSize": "40,20,20,20,20",
                    "VolumeIOPS": "200,100,100,100,100",
                    "EBSEncryption": "true,false,false,false,false",
                    "EBSKMSKeyId": "kms_key,NONE,NONE,NONE,NONE",
                    "EBSVolumeId": "vol-12345678,NONE,NONE,NONE,NONE",
                },
            ),
        ),
        (
            "ebs2",
            utils.merge_dicts(
                DefaultCfnParams["cluster"].value,
                {
                    "NumberOfEBSVol": "1",
                    "SharedDir": "ebs2,NONE,NONE,NONE,NONE",
                    "VolumeType": "standard,gp2,gp2,gp2,gp2",
Ejemplo n.º 6
0
def test_efs_section_to_cfn(mocker, section_dict, expected_cfn_params):
    mocker.patch("pcluster.config.param_types.get_efs_mount_target_id", return_value="valid_mount_target_id")
    mocker.patch(
        "pcluster.config.pcluster_config.PclusterConfig.get_master_availability_zone", return_value="mocked_avail_zone"
    )
    utils.assert_section_to_cfn(mocker, EFS, section_dict, expected_cfn_params)


@pytest.mark.parametrize(
    "settings_label, expected_cfn_params",
    [
        (
            "test1",
            utils.merge_dicts(
                DefaultCfnParams["cluster"].value,
                DefaultCfnParams["efs"].value,
                {"MasterSubnetId": "subnet-12345678", "AvailabilityZone": "mocked_avail_zone"},
            ),
        ),
        (
            "test2",
            utils.merge_dicts(
                DefaultCfnParams["cluster"].value,
                {
                    "MasterSubnetId": "subnet-12345678",
                    "AvailabilityZone": "mocked_avail_zone",
                    "EFSOptions": "efs,NONE,generalPurpose,NONE,NONE,false,bursting,Valid",
                },
            ),
        ),
        (
Ejemplo n.º 7
0
        ("access_from", "11.11.11.11/32", "11.11.11.11/32", None),
        ("access_from", "111.111.111.111/22", "111.111.111.111/22", None),
    ],
)
def test_dcv_param_from_file(mocker, param_key, param_value, expected_value,
                             expected_message):
    utils.assert_param_from_file(mocker, DCV, param_key, param_value,
                                 expected_value, expected_message)


@pytest.mark.parametrize(
    "settings_label, expected_cfn_params",
    [
        ("test1", SystemExit()),
        ("test2",
         utils.merge_dicts(DefaultCfnParams["cluster"].value,
                           {"DCVOptions": "master,8443,0.0.0.0/0"})),
        ("test3",
         utils.merge_dicts(DefaultCfnParams["cluster"].value,
                           {"DCVOptions": "master,8555,10.0.0.0/0"})),
        ("test1,test2", SystemExit()),
        ("test4", SystemExit()),
        ("test5", SystemExit()),
        ("test6", SystemExit()),
    ],
)
def test_dcv_from_file_to_cfn(mocker, pcluster_config_reader, settings_label,
                              expected_cfn_params):
    """Unit tests for parsing EFS related options."""
    mocker.patch("pcluster.config.param_types.get_efs_mount_target_id",
                 return_value="mount_target_id")
    mocker.patch("pcluster.config.param_types.get_avail_zone",
Ejemplo n.º 8
0
        ("weekly_maintenance_start_time", "10:00", "10:00", None),
        ("weekly_maintenance_start_time", "NONE", "NONE", None),
    ],
)
def test_fsx_param_from_file(mocker, param_key, param_value, expected_value, expected_message):
    utils.assert_param_from_file(mocker, FSX, param_key, param_value, expected_value, expected_message)


@pytest.mark.parametrize(
    "settings_label, expected_cfn_params",
    [
        (
            "test1",
            utils.merge_dicts(
                DefaultCfnParams["cluster"].value,
                DefaultCfnParams["fsx"].value,
                {"MasterSubnetId": "subnet-12345678", "AvailabilityZone": "mocked_avail_zone"},
            ),
        ),
        (
            "test2",
            utils.merge_dicts(
                DefaultCfnParams["cluster"].value,
                {
                    "MasterSubnetId": "subnet-12345678",
                    "AvailabilityZone": "mocked_avail_zone",
                    "FSXOptions": "fsx,NONE,NONE,NONE,NONE,NONE,NONE,NONE",
                },
            ),
        ),
        (