Esempio n. 1
0
def _test_build(
    mocker,
    resource,
    ami_response,
    ami_side_effect,
    instance_response,
    supported_architecture,
    expected_failure_messages,
    expected_failure_levels,
):
    mocker.patch("pcluster.imagebuilder_utils.get_ami_id",
                 return_value="ami-0185634c5a8a37250")
    mocker.patch(
        "pcluster.utils.get_supported_architectures_for_instance_type",
        return_value=supported_architecture)
    mock_aws_api(mocker)
    mocker.patch("pcluster.aws.ec2.Ec2Client.describe_image",
                 return_value=ami_response,
                 side_effect=ami_side_effect)
    mocker.patch("pcluster.aws.ec2.Ec2Client.list_instance_types",
                 return_value=instance_response)

    build = imagebuilder_factory(resource).get("build")
    validation_failures = build.validate()
    for validation_failure, expected_failure_level, expected_failure_message in zip(
            validation_failures, expected_failure_levels,
            expected_failure_messages):
        assert_validation_result(validation_failure, expected_failure_level,
                                 expected_failure_message)
Esempio n. 2
0
def _test_image(resource, expected_failure_messages, expected_failure_levels):
    image = imagebuilder_factory(resource).get("image")
    validation_failures = image.validate()
    for validation_failure, expected_failure_level, expected_failure_message in zip(
            validation_failures, expected_failure_levels,
            expected_failure_messages):
        assert_validation_result(validation_failure, expected_failure_level,
                                 expected_failure_message)
Esempio n. 3
0
def _test_dev_settings(
    mocker,
    resource,
    url_response,
    url_side_effect,
    url_open_side_effect,
    expected_failure_messages,
    expected_failure_levels,
):
    mock_aws_api(mocker)
    mocker.patch("pcluster.aws.s3.S3Client.head_object",
                 return_value=url_response,
                 side_effect=url_side_effect)
    mocker.patch("pcluster.validators.s3_validators.urlopen",
                 side_effect=url_open_side_effect)

    dev_settings = imagebuilder_factory(resource).get("dev_settings")
    validation_failures = dev_settings.validate()
    for validation_failure, expected_failure_level, expected_failure_message in zip(
            validation_failures, expected_failure_levels,
            expected_failure_messages):
        assert_validation_result(validation_failure, expected_failure_level,
                                 expected_failure_message)
Esempio n. 4
0
def _test_imagebuilder(
    mocker,
    resource,
    ami_response,
    ami_side_effect,
    instance_response,
    url_response,
    url_side_effect,
    url_open_side_effect,
    supported_architecture,
    expected_failure_messages,
    expected_failure_levels,
):
    mocker.patch("pcluster.imagebuilder_utils.get_ami_id",
                 return_value="ami-0185634c5a8a37250")
    mock_aws_api(mocker)
    mocker.patch("pcluster.aws.ec2.Ec2Client.get_supported_architectures",
                 return_value=supported_architecture)
    mocker.patch("pcluster.aws.ec2.Ec2Client.describe_image",
                 return_value=ImageInfo(ami_response),
                 side_effect=ami_side_effect)
    mocker.patch("pcluster.aws.ec2.Ec2Client.list_instance_types",
                 return_value=instance_response)
    mocker.patch("pcluster.aws.s3.S3Client.head_object",
                 return_value=url_response,
                 side_effect=url_side_effect)
    mocker.patch("pcluster.validators.s3_validators.urlopen",
                 side_effect=url_open_side_effect)
    mocker.patch("pcluster.aws.kms.KmsClient.describe_key", return_value=None)

    imagebuilder = imagebuilder_factory(resource).get("imagebuilder")
    validation_failures = imagebuilder.validate()
    for validation_failure, expected_failure_level, expected_failure_message in zip(
            validation_failures, expected_failure_levels,
            expected_failure_messages):
        assert_validation_result(validation_failure, expected_failure_level,
                                 expected_failure_message)
Esempio n. 5
0
def test_imagebuilder_extra_chef_attributes(resource, dna_json):
    dev_settings = imagebuilder_factory(resource).get("dev_settings")
    chef_attributes = ImageBuilderExtraChefAttributes(dev_settings).dump_json()
    assert_that(chef_attributes).is_equal_to(json.dumps(dna_json))