diff options
author | Luke Meyer <lmeyer@redhat.com> | 2017-09-20 21:35:57 -0400 |
---|---|---|
committer | Luke Meyer <lmeyer@redhat.com> | 2017-09-21 13:43:47 -0400 |
commit | 9698f76b641b7cc5964d2f4f318ea71702aa2245 (patch) | |
tree | 04f9ec59ae00ce8b79c82dd0526051ed6a0a3192 /roles/openshift_health_checker/test/diagnostics_test.py | |
parent | 4f5839e585a78243eae2d215176047299c52a1eb (diff) | |
download | openshift-9698f76b641b7cc5964d2f4f318ea71702aa2245.tar.gz openshift-9698f76b641b7cc5964d2f4f318ea71702aa2245.tar.bz2 openshift-9698f76b641b7cc5964d2f4f318ea71702aa2245.tar.xz openshift-9698f76b641b7cc5964d2f4f318ea71702aa2245.zip |
health checks: add diagnostics check
Also, moved is_first_master method into superclass for reuse. And look
at oo_first_master and ansible_host instead of masters and
ansible_ssh_host.
Diffstat (limited to 'roles/openshift_health_checker/test/diagnostics_test.py')
-rw-r--r-- | roles/openshift_health_checker/test/diagnostics_test.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/roles/openshift_health_checker/test/diagnostics_test.py b/roles/openshift_health_checker/test/diagnostics_test.py new file mode 100644 index 000000000..800889fa7 --- /dev/null +++ b/roles/openshift_health_checker/test/diagnostics_test.py @@ -0,0 +1,50 @@ +import pytest + +from openshift_checks.diagnostics import DiagnosticCheck, OpenShiftCheckException + + +@pytest.fixture() +def task_vars(): + return dict( + openshift=dict( + common=dict(config_base="/etc/origin/") + ) + ) + + +def test_module_succeeds(task_vars): + check = DiagnosticCheck(lambda *_: {"result": "success"}, task_vars) + check.is_first_master = lambda: True + assert check.is_active() + check.exec_diagnostic("spam") + assert not check.failures + + +def test_oc_not_there(task_vars): + def exec_module(*_): + return {"failed": True, "result": "[Errno 2] No such file or directory"} + + check = DiagnosticCheck(exec_module, task_vars) + with pytest.raises(OpenShiftCheckException) as excinfo: + check.exec_diagnostic("spam") + assert excinfo.value.name == "OcNotFound" + + +def test_module_fails(task_vars): + def exec_module(*_): + return {"failed": True, "result": "something broke"} + + check = DiagnosticCheck(exec_module, task_vars) + check.exec_diagnostic("spam") + assert check.failures and check.failures[0].name == "OcDiagFailed" + + +def test_names_executed(task_vars): + task_vars["openshift_check_diagnostics"] = diagnostics = "ConfigContexts,spam,,eggs" + + def exec_module(module, args, *_): + assert "extra_args" in args + assert args["extra_args"][0] in diagnostics + return {"result": "success"} + + DiagnosticCheck(exec_module, task_vars).run() |