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_node="no_levels",
                       free_cluster="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
def test_schemata_did_not_diverge() -> None:
    assert ClusterInfoA.schema() == ClusterInfoC.schema()
    assert agent.CollectorProcessingLogs.schema(
    ) == check.CollectorProcessingLogs.schema()
    assert agent.CollectorComponentsMetadata.schema(
    ) == check.CollectorComponentsMetadata.schema()
    assert ContainerCountA.schema() == ContainerCountC.schema()
    assert ContainerRunningStateA.schema() == ContainerRunningStateC.schema()
    assert ContainerTerminatedStateA.schema(
    ) == ContainerTerminatedStateC.schema()
    assert ContainerWaitingStateA.schema() == ContainerWaitingStateC.schema()
    assert agent.DeploymentConditions.schema(
    ) == check.DeploymentConditions.schema()
    assert KubeletInfoA.schema() == KubeletInfoC.schema()
    assert NodeCountA.schema() == NodeCountC.schema()
    assert NodeInfoA.schema() == NodeInfoC.schema()
    assert PodConditionA.schema() == PodConditionC.schema()
    assert PodConditionsA.schema() == PodConditionsC.schema()
    assert PodContainersA.schema() == PodContainersC.schema()
    assert PodResourcesA.schema() == PodResourcesC.schema()
    assert PodLifeCycleA.schema() == PodLifeCycleC.schema()
    assert AllocatablePodsA.schema() == AllocatablePodsC.schema()
    assert ResourcesA.schema() == ResourcesC.schema()
    assert StartTimeA.schema() == StartTimeC.schema()
    assert PodInfoA.schema() == PodInfoC.schema()
    assert ReplicasA.schema() == ReplicasC.schema()
    assert agent.DeploymentStrategy.schema(
    ) == k8s_check.DeploymentStrategy.schema()
    assert agent.NodeConditions.schema() == check.NodeConditions.schema()
    assert agent.PerformanceUsage.schema(
    ) == k8s_check.PerformanceUsage.schema()
Beispiel #4
0
def test_schemata_did_not_diverge() -> None:
    assert ClusterInfoA.schema() == ClusterInfoC.schema()
    assert agent.CollectorLogs.schema() == check.CollectorLogs.schema()
    assert ContainerCountA.schema() == ContainerCountC.schema()
    assert ContainerInfoA.schema() == ContainerInfoC.schema()
    assert ContainerRunningStateA.schema() == ContainerRunningStateC.schema()
    assert ContainerTerminatedStateA.schema(
    ) == ContainerTerminatedStateC.schema()
    assert ContainerWaitingStateA.schema() == ContainerWaitingStateC.schema()
    assert agent.DeploymentConditions.schema(
    ) == check.DeploymentConditions.schema()
    assert KubeletInfoA.schema() == KubeletInfoC.schema()
    assert MemoryA.schema() == MemoryC.schema()
    assert NodeCountA.schema() == NodeCountC.schema()
    assert NodeInfoA.schema() == NodeInfoC.schema()
    assert PodConditionA.schema() == PodConditionC.schema()
    assert PodConditionsA.schema() == PodConditionsC.schema()
    assert PodContainersA.schema() == PodContainersC.schema()
    assert PodResourcesA.schema() == PodResourcesC.schema()
    assert PodLifeCycleA.schema() == PodLifeCycleC.schema()
    assert AllocatablePodsA.schema() == AllocatablePodsC.schema()
    assert ResourcesA.schema() == ResourcesC.schema()
    assert StartTimeA.schema() == StartTimeC.schema()
    assert PodInfoA.schema() == PodInfoC.schema()
    assert ReplicasA.schema() == ReplicasC.schema()
    assert DeploymentSpecA.schema() == DeploymentSpecC.schema()
Beispiel #5
0
def parse_kube_pod_resources(string_table: StringTable):
    """
    >>> parse_kube_pod_resources([[
    ...     '{"running": ["checkmk-cluster-agent", "storage-provisioner"],'
    ...     ' "pending": ["success2"], "succeeded":'
    ...     ' ["hello-27303194--1-9vtft"],'
    ...     ' "failed": [], '
    ...     '"unknown": []}'
    ... ]])
    PodResources(running=['checkmk-cluster-agent', 'storage-provisioner'], pending=['success2'], succeeded=['hello-27303194--1-9vtft'], failed=[], unknown=[])
    """
    return PodResources(**json.loads(string_table[0][0]))
Beispiel #6
0
def test_check_matches_what_valuespec_promises(
        param: VSResultPercent, expected_result: Sequence[Result]) -> None:
    """The rule set for free pods looks like this:
    Warning below x %
    Crit below y %
    These percentual values need to be converted to absolute levels such that, what the rule set
    promises, is true.
    """
    result, _ = check_free_pods(
        param,
        PodResources(pending=["pod_1"]),
        allocatable_pods=2,
    )
    assert result == expected_result
Beispiel #7
0
def test_check_levels_free_pods(
    pending_pods_in_each_check_call: Tuple[PodSequence, ...],
    param: VSResultPercent,
    expected_result_in_each_check_call: Sequence[Result],
) -> None:
    for pending_pods, expected_result in zip(
            pending_pods_in_each_check_call,
            expected_result_in_each_check_call,
    ):
        result, _ = check_free_pods(
            param,
            PodResources(pending=pending_pods),
            allocatable_pods=2,
        )
        assert result == expected_result
def test_check_kube_pod_resources_overall_look(
    pending_pods_in_each_check_call: Tuple[PodSequence, ...],
    params_in_each_check_call: Tuple[Params, ...],
    expected_result,
    time_time,
    get_value_store,
) -> None:
    for pod_names, params in zip(pending_pods_in_each_check_call,
                                 params_in_each_check_call):
        result = tuple(
            check_kube_pod_resources(
                params=params,
                section=PodResources(pending=pod_names),
            ))
    assert result == expected_result[:9]
Beispiel #9
0
def test_check_kube_pod_resources_with_capacity_overall_look(
    pending_pods_in_each_check_call: Tuple[PodSequence, ...],
    params_in_each_check_call: Tuple[Params, ...],
    expected_result,
    time_time,
    get_value_store,
) -> None:
    for pod_names, params in zip(pending_pods_in_each_check_call,
                                 params_in_each_check_call):
        result = tuple(
            check_kube_pod_resources(
                params=params,
                section_kube_pod_resources=PodResources(pending=pod_names),
                section_kube_allocatable_pods=AllocatablePods(allocatable=110,
                                                              capacity=110),
            ))
    assert result == expected_result
Beispiel #10
0
def test_check_phase_duration_with_changing_params(
    params_in_each_check_call: Tuple[Params, ...],
    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 activating/deactivating rules.
    """
    for params, expected_result in zip(
            params_in_each_check_call,
            expected_result_in_each_check_call,
            # strict=True, would be nice
    ):
        assert (tuple(
            check_kube_pod_resources(params, PodResources(pending=["pod"]),
                                     None))[2] == expected_result)
def test_schemata_did_not_diverge() -> None:
    assert ClusterInfoA.schema() == ClusterInfoC.schema()
    assert ContainerCountA.schema() == ContainerCountC.schema()
    assert ContainerInfoA.schema() == ContainerInfoC.schema()
    assert ContainerRunningStateA.schema() == ContainerRunningStateC.schema()
    assert ContainerTerminatedStateA.schema(
    ) == ContainerTerminatedStateC.schema()
    assert ContainerWaitingStateA.schema() == ContainerWaitingStateC.schema()
    assert KubeletInfoA.schema() == KubeletInfoC.schema()
    assert MemoryA.schema() == MemoryC.schema()
    assert NodeCountA.schema() == NodeCountC.schema()
    assert NodeInfoA.schema() == NodeInfoC.schema()
    assert PodConditionA.schema() == PodConditionC.schema()
    assert PodConditionsA.schema() == PodConditionsC.schema()
    assert PodContainersA.schema() == PodContainersC.schema()
    assert PodResourcesA.schema() == PodResourcesC.schema()
    assert PodLifeCycleA.schema() == PodLifeCycleC.schema()
    assert PodResourcesWithCapacityA.schema(
    ) == PodResourcesWithCapacityC.schema()
    assert ResourcesA.schema() == ResourcesC.schema()
    assert StartTimeA.schema() == StartTimeC.schema()
    assert PodInfoA.schema() == PodInfoC.schema()