Ejemplo n.º 1
0
def test_bootstrap_cloudwatch_log_create_log_stream_failed(mocker):
    config = _get_mock_config(DEFAULT_CLOUDWATCH_ENABLED,
                              DEFAULT_CLOUDWATCH_LOG_GROUP,
                              DEFAULT_RETENTION_DAYS)
    mocker.patch(
        "mount_efs.get_instance_identity_info_from_instance_metadata",
        return_value=INSTANCE,
    )
    get_botocore_client_mock = mocker.patch("mount_efs.get_botocore_client",
                                            return_value="fake-agent")
    create_log_group_mock = mocker.patch(
        "mount_efs.create_cloudwatch_log_group", return_value=True)
    put_retention_policy_mock = mocker.patch(
        "mount_efs.put_cloudwatch_log_retention_policy", return_value=True)
    create_log_stream_mock = mocker.patch(
        "mount_efs.create_cloudwatch_log_stream", return_value=False)

    cloudwatchlog_agent = mount_efs.bootstrap_cloudwatch_logging(
        config, {}, FS_ID)
    utils.assert_called_once(get_botocore_client_mock)
    utils.assert_called_once(create_log_group_mock)
    utils.assert_called_once(put_retention_policy_mock)
    utils.assert_called_once(create_log_stream_mock)

    assert cloudwatchlog_agent == None
Ejemplo n.º 2
0
def test_bootstrap_cloudwatch_log_with_fs_id_template(mocker):
    log_group = DEFAULT_CLOUDWATCH_LOG_GROUP + "/{fs_id}"
    expected_agent = {
        "client": "fake-agent",
        "log_group_name": log_group.format(fs_id=FS_ID),
        "log_stream_name": "%s - %s - mount.log" % (FS_ID, INSTANCE),
    }

    config = _get_mock_config(DEFAULT_CLOUDWATCH_ENABLED, log_group,
                              DEFAULT_RETENTION_DAYS)
    mocker.patch(
        "mount_efs.get_instance_identity_info_from_instance_metadata",
        return_value=INSTANCE,
    )
    get_botocore_client_mock = mocker.patch("mount_efs.get_botocore_client",
                                            return_value="fake-agent")
    create_log_group_mock = mocker.patch(
        "mount_efs.create_cloudwatch_log_group", return_value=True)
    put_retention_policy_mock = mocker.patch(
        "mount_efs.put_cloudwatch_log_retention_policy", return_value=True)
    create_log_stream_mock = mocker.patch(
        "mount_efs.create_cloudwatch_log_stream", return_value=True)
    cloudwatchlog_agent = mount_efs.bootstrap_cloudwatch_logging(
        config, {}, FS_ID)
    utils.assert_called_once(get_botocore_client_mock)
    utils.assert_called_once(create_log_group_mock)
    utils.assert_called_once(put_retention_policy_mock)
    utils.assert_called_once(create_log_stream_mock)

    assert cloudwatchlog_agent == expected_agent
Ejemplo n.º 3
0
def test_cloudwatchlog_agent_none_when_botocore_agent_is_none(mocker):
    config = _get_mock_config(DEFAULT_CLOUDWATCH_ENABLED,
                              DEFAULT_CLOUDWATCH_LOG_GROUP,
                              DEFAULT_RETENTION_DAYS)
    get_botocore_client_mock = mocker.patch('mount_efs.get_botocore_client',
                                            return_value=None)
    cloudwatchlog_agent = mount_efs.bootstrap_cloudwatch_logging(config, FS_ID)
    utils.assert_called_once(get_botocore_client_mock)

    assert cloudwatchlog_agent == None
Ejemplo n.º 4
0
def test_botocore_not_called_when_feature_not_enabled(mocker):
    config = _get_mock_config(DEFAULT_CLOUDWATCH_DISABLED,
                              DEFAULT_CLOUDWATCH_LOG_GROUP,
                              DEFAULT_RETENTION_DAYS)
    enabled = mount_efs.check_if_cloudwatch_log_enabled(config)
    assert enabled == False

    get_botocore_client_mock = mocker.patch('mount_efs.get_botocore_client')
    cloudwatchlog_agent = mount_efs.bootstrap_cloudwatch_logging(config, FS_ID)
    utils.assert_not_called(get_botocore_client_mock)
    assert cloudwatchlog_agent == None