Example #1
0
    def test_create_stack_calls_cloudformation_api_properly_with_defined_failure_action(self, _, cloudformation_mock):
        stack = Mock(spec=CloudFormationStack)
        stack.name = "stack-name"
        stack.get_parameters_list.return_value = [("a", "b")]
        stack.get_tags_list.return_value = [("any-tag", "any-tag-value")]
        stack.parameters = {}
        stack.template = Mock(spec=CloudFormationTemplate)
        stack.template.name = "template-name"
        stack.template.get_template_json.return_value = {"key": "value"}
        stack.service_role = None
        stack.stack_policy = "{foo:baa}"
        stack.failure_action = "DO_NOTHING"
        stack.timeout = 42

        cfn = CloudFormation()
        cfn.create_stack(stack)

        cloudformation_mock.return_value.create_stack.assert_called_once_with(
            Capabilities=["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"],
            OnFailure="DO_NOTHING",
            Parameters=[("a", "b")],
            StackName="stack-name",
            Tags=[("any-tag", "any-tag-value")],
            TemplateBody={"key": "value"},
            StackPolicyBody='"{foo:baa}"',
        )
Example #2
0
    def test_create_stack_calls_cloudformation_api_properly_with_service_role(self, _, cloudformation_mock):
        stack = Mock(spec=CloudFormationStack)
        stack.name = "stack-name"
        stack.get_parameters_list.return_value = [("a", "b")]
        stack.get_tags_list.return_value = [("any-tag", "any-tag-value")]
        stack.parameters = {}
        stack.template = Mock(spec=CloudFormationTemplate)
        stack.template.name = "template-name"
        stack.template.get_template_json.return_value = {"key": "value"}
        stack.service_role = "arn:aws:iam::1234567890:role/my-role"
        stack.stack_policy = None
        stack.failure_action = None
        stack.timeout = 42

        cfn = CloudFormation()
        cfn.create_stack(stack)

        cloudformation_mock.return_value.create_stack.assert_called_once_with(
            Capabilities=["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"],
            Parameters=[("a", "b")],
            StackName="stack-name",
            Tags=[("any-tag", "any-tag-value")],
            TemplateBody={"key": "value"},
            RoleARN="arn:aws:iam::1234567890:role/my-role",
        )
def test_resolve_value_from_file(self, get_file_mock):
    get_file_mock.return_value = "line1\nline2"

    stack_config = Mock()
    stack_config.parameters = {"foo": "|file|abc.txt"}

    result = ParameterResolver().resolve_parameter_values("foo", stack_config)
    self.assertEqual({"foo": "line1\nline2"}, result)
    def test_resolve_parameter_values_returns_decrypted_value(self):
        self.kms_mock.return_value.decrypt.return_value = "decryptedValue"

        stack_config = Mock()
        stack_config.parameters = {"foo": "|kms|encryptedValue"}

        result = ParameterResolver().resolve_parameter_values("foo", stack_config)
        self.assertEqual(result, {"foo": "decryptedValue"})
    def test_resolve_parameters_with_cli_parameters_(self):
        cli_parameters = {"stack1": {"foo": "foobar"}, "stack2": {"foo": "foofoo"}}

        stack_config = Mock()
        stack_config.parameters = {"foo": "bar"}

        result = ParameterResolver().resolve_parameter_values("stack1", stack_config, cli_parameters)

        self.assertEqual({"foo": "foobar"}, result)
    def test_get_stack_parameters_dict_returns_empty_dict_for_empty_parameters(self, _, get_stack_mock):
        cfn = CloudFormation()

        stack_mock = Mock()
        stack_mock.parameters = []
        get_stack_mock.return_value = stack_mock

        result = cfn.get_stack_parameters_dict("foo")

        self.assertDictEqual({}, result)
    def test_resolve_parameter_values_returns_ref_list_value(self, cfn_mock, get_output_value_mock):
        cfn_mock.return_value.get_stacks_outputs.return_value = None
        get_output_value_mock.return_value = "bar"

        stack_config = Mock()
        stack_config.parameters = {"foo": ["|Ref|stack.output", "|Ref|stack.output"]}

        result = ParameterResolver().resolve_parameter_values("foo", stack_config)

        get_output_value_mock.assert_called_with(None, "stack", "output")
        self.assertEqual({"foo": "bar,bar"}, result)
Example #8
0
    def test_get_stack_parameters_dict_returns_proper_dict(self, _, get_stack_mock):
        cfn = CloudFormation()

        stack_mock = Mock()
        stack_mock.parameters = [
            {"ParameterKey": "myKey1", "ParameterValue": "myValue1"},
            {"ParameterKey": "myKey2", "ParameterValue": "myValue2"},
        ]
        get_stack_mock.return_value = stack_mock

        result = cfn.get_stack_parameters_dict("foo")

        self.assertDictEqual({"myKey1": "myValue1", "myKey2": "myValue2"}, result)
    def test_update_stack_calls_cloudformation_api_properly(self, _, cloudformation_mock):
        stack = Mock(spec=CloudFormationStack)
        stack.name = "stack-name"
        stack.get_parameters_list.return_value = [("a", "b")]
        stack.parameters = {}
        stack.template = Mock(spec=CloudFormationTemplate)
        stack.template.name = "template-name"
        stack.template.get_template_json.return_value = {"key": "value"}
        stack.timeout = 42

        cfn = CloudFormation()
        cfn.update_stack(stack)

        cloudformation_mock.return_value.update_stack.assert_called_once_with(
            "stack-name", capabilities=["CAPABILITY_IAM"], parameters=[("a", "b")], template_body={"key": "value"}
        )
Example #10
0
    def test_get_stack_parameters_dict_returns_proper_dict(self, _, get_stack_mock):
        cfn = CloudFormation()

        parameter_1 = Mock()
        parameter_1.key = "myKey1"
        parameter_1.value = "myValue1"
        parameter_2 = Mock()
        parameter_2.key = "myKey2"
        parameter_2.value = "myValue2"

        stack_mock = Mock()
        stack_mock.parameters = [parameter_1, parameter_2]
        get_stack_mock.return_value = stack_mock

        result = cfn.get_stack_parameters_dict("foo")

        self.assertDictEqual({"myKey1": "myValue1", "myKey2": "myValue2"}, result)
Example #11
0
    def test_create_stack_calls_cloudformation_api_properly(self, _, cloudformation_mock):
        stack = Mock(spec=CloudFormationStack)
        stack.name = "stack-name"
        stack.get_parameters_list.return_value = [("a", "b")]
        stack.get_tags_list.return_value = [("any-tag", "any-tag-value")]
        stack.parameters = {}
        stack.template = Mock(spec=CloudFormationTemplate)
        stack.template.name = "template-name"
        stack.template.get_template_json.return_value = {"key": "value"}
        stack.timeout = 42

        cfn = CloudFormation()
        cfn.create_stack(stack)

        cloudformation_mock.return_value.create_stack.assert_called_once_with(
            Capabilities=["CAPABILITY_IAM"],
            OnFailure="DELETE",
            Parameters=[("a", "b")],
            StackName="stack-name",
            Tags=[("any-tag", "any-tag-value")],
            TemplateBody={"key": "value"},
            TimeoutInMinutes=42,
        )
 def test_resolve_parameter_values_returns_str_representation_of_float(self):
     stack_config = Mock()
     stack_config.parameters = {"foo": 5.555}
     result = ParameterResolver().resolve_parameter_values("foo", stack_config)
     self.assertEqual({"foo": "5.555"}, result)
    def test_resolve_parameter_values_returns_list_with_string_value(self):
        stack_config = Mock()
        stack_config.parameters = {"foo": "baa"}

        result = ParameterResolver().resolve_parameter_values("foo", stack_config)
        self.assertEqual({"foo": "baa"}, result)
    def test_resolve_parameter_values_raises_exception_on_none_value(self):
        stack_config = Mock()
        stack_config.parameters = {"foo": None}

        with self.assertRaises(NotImplementedError):
            ParameterResolver().resolve_parameter_values("foo", stack_config)
    def test_resolve_parameter_values_calls_convert_list_to_string_on_list_value(self, convert_list_to_string_mock):
        stack_config = Mock()
        stack_config.parameters = {"foo": ["a", "b"]}

        ParameterResolver().resolve_parameter_values("foo", stack_config)
        convert_list_to_string_mock.assert_called_once_with(["a", "b"])