コード例 #1
0
def test_integrations_uninstall(cli_runner):
    """
    Assert that 'newrelic-lambda integrations uninstall' uninstall the log ingestion
    function/role if present
    """
    register_groups(cli)
    result = cli_runner.invoke(
        cli,
        [
            "integrations",
            "uninstall",
            "--no-aws-permissions-check",
            "--nr-account-id",
            "12345678",
        ],
        env={"AWS_DEFAULT_REGION": "us-east-1"},
        input="y\ny",
    )

    assert result.exit_code == 0
    assert result.stdout == (
        "This will uninstall the New Relic AWS Lambda integration role. Are you sure you want to proceed? [y/N]: y\n"  # noqa
        "No New Relic AWS Lambda Integration found, skipping\n"
        "This will uninstall the New Relic AWS Lambda log ingestion function and role. Are you sure you want to proceed? [y/N]: y\n"  # noqa
        "No New Relic AWS Lambda log ingestion found in region us-east-1, skipping\n"
        "✨ Uninstall Complete ✨\n"
    )

    session = boto3.Session(region_name="us-east-1")
    create_integration_role(session, None, 12345678)
    create_log_ingestion_function(session, "mock-nr-license-key")

    result2 = cli_runner.invoke(
        cli,
        [
            "integrations",
            "uninstall",
            "--no-aws-permissions-check",
            "--nr-account-id",
            "12345678",
        ],
        env={"AWS_DEFAULT_REGION": "us-east-1"},
        input="y\ny",
    )

    assert result2.exit_code == 0
    assert result2.stdout == (
        "This will uninstall the New Relic AWS Lambda integration role. Are you sure you want to proceed? [y/N]: y\n"  # noqa
        "Deleting New Relic AWS Lambda Integration stack 'NewRelicLambdaIntegrationRole-12345678'\n"  # noqa
        "Waiting for stack deletion to complete, this may take a minute... ✔️ Done\n"
        "This will uninstall the New Relic AWS Lambda log ingestion function and role. Are you sure you want to proceed? [y/N]: y\n"  # noqa
        "Deleting New Relic log ingestion stack 'NewRelicLogIngestion'\n"
        "Waiting for stack deletion to complete, this may take a minute... ✔️ Done\n"
        "✨ Uninstall Complete ✨\n"
    )
コード例 #2
0
def test_check_for_ingest_stack(aws_credentials):
    """
    Asserts that check_for_ingestion_stack returns the ingestion stack if present;
    None if not.
    """
    session = boto3.Session(region_name="us-east-1")
    assert check_for_ingest_stack(session) is None

    create_log_ingestion_function(session, "mock-nr-license-key")
    assert check_for_ingest_stack(session) == "CREATE_COMPLETE"

    remove_log_ingestion_function(session)
    assert check_for_ingest_stack(session) is None
コード例 #3
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(
            session,
            "test_key",
            enable_logs=True,
            memory_size=256,
            timeout=60,
            role_name="CustomExecRole",
        )

        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=[],
                ChangeSetType="CREATE",
                ChangeSetName=ANY,
            )
        ])
        cf_client.assert_has_calls(
            [call.execute_change_set(ChangeSetName="arn:something")])
        success_mock.assert_called_once()
コード例 #4
0
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()