Esempio n. 1
0
def test__create_log_ingestion_function__opts(success_mock):
    session = MagicMock()
    with patch.object(session, "client") as mock_client_factory:
        cf_mocks = {"create_change_set.return_value": {"Id": "arn:something"}}
        sar_client = MagicMock(name="serverlessrepo")
        cf_client = MagicMock(name="cloudformation", **cf_mocks)
        mock_client_factory.side_effect = [cf_client, sar_client]

        _create_log_ingestion_function(
            integration_install(
                session=session,
                enable_logs=True,
                memory_size=256,
                role_name="CustomExecRole",
                timeout=60,
            ),
            "test_key",
        )

        cf_client.assert_has_calls([
            call.create_change_set(
                StackName="NewRelicLogIngestion",
                TemplateURL=ANY,
                Parameters=[
                    {
                        "ParameterKey": "MemorySize",
                        "ParameterValue": str(256)
                    },
                    {
                        "ParameterKey": "NRLicenseKey",
                        "ParameterValue": "test_key"
                    },
                    {
                        "ParameterKey": "NRLoggingEnabled",
                        "ParameterValue": "True"
                    },
                    {
                        "ParameterKey": "Timeout",
                        "ParameterValue": str(60)
                    },
                    {
                        "ParameterKey": "FunctionRole",
                        "ParameterValue": "CustomExecRole",
                    },
                ],
                Capabilities=[],
                Tags=[],
                ChangeSetType="CREATE",
                ChangeSetName=ANY,
            )
        ])
        cf_client.assert_has_calls(
            [call.execute_change_set(ChangeSetName="arn:something")])
        success_mock.assert_called_once()
def test_create_log_ingestion_function_defaults(success_mock):
    session = MagicMock()
    with patch.object(session, "client") as mock_client_factory:
        cf_mocks = {"create_change_set.return_value": {"Id": "arn:something"}}
        sar_client = MagicMock(name="serverlessrepo")
        cf_client = MagicMock(name="cloudformation", **cf_mocks)
        mock_client_factory.side_effect = [cf_client, sar_client]

        create_log_ingestion_function(session, "test_key", False, 128, 30,
                                      None)

        cf_client.assert_has_calls([
            call.create_change_set(
                StackName="NewRelicLogIngestion",
                TemplateURL=ANY,
                Parameters=[
                    {
                        "ParameterKey": "MemorySize",
                        "ParameterValue": str(128)
                    },
                    {
                        "ParameterKey": "NRLicenseKey",
                        "ParameterValue": "test_key"
                    },
                    {
                        "ParameterKey": "NRLoggingEnabled",
                        "ParameterValue": "False"
                    },
                    {
                        "ParameterKey": "Timeout",
                        "ParameterValue": str(30)
                    },
                ],
                Capabilities=["CAPABILITY_IAM"],
                ChangeSetType="CREATE",
                ChangeSetName=ANY,
            )
        ])
        cf_client.assert_has_calls(
            [call.execute_change_set(ChangeSetName="arn:something")])
        success_mock.assert_called_once()
Esempio n. 3
0
def test_install_license_key(success_mock):
    session = MagicMock()
    with patch.object(session, "client") as mock_client_factory:
        cf_mocks = {
            "describe_stacks.side_effect":
            botocore.exceptions.ClientError(
                {"ResponseMetadata": {
                    "HTTPStatusCode": 404
                }}, "test"),
            "create_change_set.return_value": {
                "Id": "arn:something"
            },
        }
        cf_client = MagicMock(name="cloudformation", **cf_mocks)
        mock_client_factory.side_effect = [cf_client, cf_client]

        result = install_license_key(integration_install(session=session),
                                     "1234abcd")
        assert result is True

        cf_client.assert_has_calls(
            [
                call.create_change_set(
                    StackName="NewRelicLicenseKeySecret",
                    TemplateBody=ANY,
                    Parameters=[
                        {
                            "ParameterKey": "LicenseKey",
                            "ParameterValue": "1234abcd"
                        },
                    ],
                    Capabilities=["CAPABILITY_NAMED_IAM"],
                    Tags=[],
                    ChangeSetType="CREATE",
                    ChangeSetName=ANY,
                ),
                call.execute_change_set(ChangeSetName="arn:something"),
            ],
            any_order=True,
        )
        success_mock.assert_called_once()