summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test/curator_test.py
blob: 62c680b74eb03fc03e9355f87c8ab0b5fba9e47b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pytest

from openshift_checks.logging.curator import Curator, OpenShiftCheckException


plain_curator_pod = {
    "metadata": {
        "labels": {"component": "curator", "deploymentconfig": "logging-curator"},
        "name": "logging-curator-1",
    },
    "status": {
        "containerStatuses": [{"ready": True}],
        "conditions": [{"status": "True", "type": "Ready"}],
        "podIP": "10.10.10.10",
    }
}

not_running_curator_pod = {
    "metadata": {
        "labels": {"component": "curator", "deploymentconfig": "logging-curator"},
        "name": "logging-curator-2",
    },
    "status": {
        "containerStatuses": [{"ready": False}],
        "conditions": [{"status": "False", "type": "Ready"}],
        "podIP": "10.10.10.10",
    }
}


def test_get_curator_pods():
    check = Curator()
    check.get_pods_for_component = lambda *_: [plain_curator_pod]
    result = check.run()
    assert "failed" not in result or not result["failed"]


@pytest.mark.parametrize('pods, expect_error', [
    (
        [],
        'MissingComponentPods',
    ),
    (
        [not_running_curator_pod],
        'CuratorNotRunning',
    ),
    (
        [plain_curator_pod, plain_curator_pod],
        'TooManyCurators',
    ),
])
def test_get_curator_pods_fail(pods, expect_error):
    check = Curator()
    check.get_pods_for_component = lambda *_: pods
    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.run()
    assert excinfo.value.name == expect_error