Beispiel #1
0
def test_check_bevaviour_if_there_are_unknown_pods(
    pending_pods_in_each_check_call: Tuple[PodSequence, ...],
    expected_result_in_each_check_call: Tuple[Result, ...],
    time_time,
    get_value_store,
) -> None:
    """
    We simulate multiple calls to check function at different points in time.
    expected_result_in_each_check_call corresponds to the Results returned at different points in
    time, which are relevant to the behaviour of unknown pods, i.e., check_kube_pod_resources will
    return other Results/Metrics, but will only return one Result, which is related to unknown.
    """
    for pending_pods, expected_result in zip(
        pending_pods_in_each_check_call,
        expected_result_in_each_check_call,
        # strict=True, would be nice
    ):
        assert (
            tuple(
                check_kube_pod_resources(
                    Params(pending="no_levels", free="no_levels"),
                    PodResources(unknown=pending_pods),
                    None,
                )
            )[8]
            == expected_result
        )
Beispiel #2
0
def test_check_phase_duration_with_different_pods(
    pending_pods_in_each_check_call: Tuple[PodSequence, ...],
    expected_result_in_each_check_call: Tuple[Result, ...],
    time_time,
    get_value_store,
) -> None:
    """
    We simulate multiple calls to check function at different points in time.
    expected_result_in_each_check_call corresponds to the Results returned at different points in
    time, which are relevant to the behaviour of pending pods, i.e., check_kube_pod_resources will
    return other Results/Metrics, but will only return one Result, which is related to pending.

    Here we focus on different sequences of pending pods.
    """
    params = Params(pending=("levels", (60, 120)),
                    free_node="no_levels",
                    free_cluster="no_levels")
    for pending_pods, expected_result in zip(
            pending_pods_in_each_check_call,
            expected_result_in_each_check_call,
            # strict=True, would be nice
    ):
        assert (tuple(
            check_kube_pod_resources(params,
                                     PodResources(pending=pending_pods),
                                     None))[2] == expected_result)
Beispiel #3
0
        # strict=True, would be nice
    ):
        assert (
            tuple(check_kube_pod_resources(params, PodResources(pending=pending_pods), None))[2]
            == expected_result
        )


@pytest.mark.parametrize(
    "params_in_each_check_call, expected_result_in_each_check_call",
    [
        pytest.param(
            # If the user deactivates a rule and then later activates it again, the phase duration
            # should be persistent.
            (
                Params(pending=("levels", (60, 120)), free="no_levels"),
                Params(pending="no_levels", free="no_levels"),
                Params(pending=("levels", (60, 120)), free="no_levels"),
            ),
            (
                Result(state=State.OK, summary="Pending: 1"),
                Result(state=State.OK, summary="Pending: 1"),
                Result(
                    state=State.CRIT,
                    summary="Pending: 1, thereof 1 (pod) for longer than 2 minutes 0 seconds",
                ),
            ),
            id="deactivate_levels_and_turn_on_again",
        ),
        pytest.param(
            (
Beispiel #4
0
    ):
        assert (tuple(
            check_kube_pod_resources(params,
                                     PodResources(pending=pending_pods),
                                     None))[2] == expected_result)


@pytest.mark.parametrize(
    "params_in_each_check_call, expected_result_in_each_check_call",
    [
        pytest.param(
            # If the user deactivates a rule and then later activates it again, the phase duration
            # should be persistent.
            (
                Params(pending=("levels", (60, 120)),
                       free_node="no_levels",
                       free_cluster="no_levels"),
                Params(pending="no_levels",
                       free_node="no_levels",
                       free_cluster="no_levels"),
                Params(pending=("levels", (60, 120)),
                       free_node="no_levels",
                       free_cluster="no_levels"),
            ),
            (
                Result(state=State.OK, summary="Pending: 1"),
                Result(state=State.OK, summary="Pending: 1"),
                Result(
                    state=State.CRIT,
                    summary=
                    "Pending: 1, thereof 1 (pod) for longer than 2 minutes 0 seconds",