Beispiel #1
0
def test_check_results_sets_summary_when_status_false(state, check_result):
    time_diff = render.timespan(state * MINUTE)
    expected_prefixes = [
        f"{k.upper()}: False ({REASON}: {DETAIL}) for {time_diff}"
        for k in kube_pod_conditions.LOGICAL_ORDER
    ]
    for expected_prefix, result in zip(expected_prefixes, check_result):
        assert result.summary.startswith(expected_prefix)
Beispiel #2
0
def test_check_results_sets_summary_when_status_false(state, check_result):
    time_diff = render.timespan(state * MINUTE)
    expected_prefixes = [
        f"{k8s_pod_conditions.ADDITIONAL_SERVICE_TEXT[k].not_passed} ({REASON}: {DETAIL}) for {time_diff}"
        for k in k8s_pod_conditions.LOGICAL_ORDER
    ]
    for expected_prefix, result in zip(expected_prefixes, check_result):
        assert result.summary.startswith(expected_prefix)
Beispiel #3
0
def check_terminated(params: Mapping[str, int],
                     state: ContainerTerminatedState) -> CheckResult:
    result_state = State.OK
    status = "Succeeded"
    if state.exit_code != 0:
        result_state = State(params["failed_state"])
        status = "Failed"
    summary = f"Status: {status} ({state.reason}: {state.detail})"
    yield Result(state=result_state, summary=summary)
    end_time = render.datetime(state.end_time)
    duration = render.timespan(state.end_time - state.start_time)
    summary = f"End time: {end_time} Run duration: {duration}"
    yield Result(state=State.OK, summary=summary)
Beispiel #4
0
def _check_individual_files(
    params: Mapping[str, Any],
    file_name: str,
    file_size: int,
    file_age: int,
    skip_ok_files: bool,
) -> CheckResult:
    '''
        This function checks individual files against levels defined for the file group.
        This is done to generate information for the long output.
    '''

    for key, value in [
        ("age_oldest", file_age),
        ("age_newest", file_age),
        ("size_smallest", file_size),
        ("size_largest", file_size),
    ]:
        levels_upper = params.get("max" + key, (None, None))
        levels_lower = params.get("min" + key, (None, None))
        results = check_levels(
            value,
            metric_name=key,
            levels_upper=levels_upper,
            levels_lower=levels_lower,
        )

    overall_state = max(r.state.value for r in results
                        if isinstance(r, Result))
    if skip_ok_files and State(overall_state) == State.OK:
        return

    age = render.timespan(file_age)
    size = render.filesize(file_size)

    yield Result(
        state=State.OK,
        notice=f"[{file_name}] Age: {age}, Size: {size}",
    )
def test_check_results_sets_summary_when_status_false(state, check_result):
    time_diff = render.timespan(state * MINUTE)
    expected_content = f"condition not passed ({REASON}: {DETAIL}) for {time_diff}"
    assert all(expected_content in r.summary for r in check_result)
def test_check_result_terminated_end_time(start_time, check_result):
    expected_end_time = render.datetime(start_time + MINUTE)
    expected_duration = render.timespan(MINUTE)
    _, result, _, _ = check_result
    assert result.state == State.OK
    assert result.summary == f"End time: {expected_end_time} Run duration: {expected_duration}"
def test_check_result_summary_start_time(timespan, check_result):
    expected_timespan = render.timespan(timespan)
    result, _, _ = check_result
    assert result.summary == f"Status: Running for {expected_timespan}"