summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test
diff options
context:
space:
mode:
authorOpenShift Bot <eparis+openshiftbot@redhat.com>2017-03-28 07:54:59 -0500
committerGitHub <noreply@github.com>2017-03-28 07:54:59 -0500
commite9a4e751bc28f43583087ce6502a36c5d83cf30d (patch)
tree9a5f816d8dd5c40d6b682fe514ce41fd4435d4cb /roles/openshift_health_checker/test
parent0d38f04595fc2098cf8304faf20e15e62f43955c (diff)
parentd6cf72a4f488d8c275bfbaf27620ff716da1ae5d (diff)
downloadopenshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.tar.gz
openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.tar.bz2
openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.tar.xz
openshift-e9a4e751bc28f43583087ce6502a36c5d83cf30d.zip
Merge pull request #3745 from rhcarvalho/checks-unit-tests
Merged by openshift-bot
Diffstat (limited to 'roles/openshift_health_checker/test')
-rw-r--r--roles/openshift_health_checker/test/docker_image_availability_test.py28
-rw-r--r--roles/openshift_health_checker/test/mixins_test.py23
-rw-r--r--roles/openshift_health_checker/test/openshift_check_test.py61
-rw-r--r--roles/openshift_health_checker/test/package_availability_test.py49
-rw-r--r--roles/openshift_health_checker/test/package_update_test.py16
-rw-r--r--roles/openshift_health_checker/test/package_version_test.py21
6 files changed, 197 insertions, 1 deletions
diff --git a/roles/openshift_health_checker/test/docker_image_availability_test.py b/roles/openshift_health_checker/test/docker_image_availability_test.py
new file mode 100644
index 000000000..2a9c32f77
--- /dev/null
+++ b/roles/openshift_health_checker/test/docker_image_availability_test.py
@@ -0,0 +1,28 @@
+import pytest
+
+from openshift_checks.docker_image_availability import DockerImageAvailability
+
+
+@pytest.mark.xfail(strict=True) # TODO: remove this once this test is fully implemented.
+@pytest.mark.parametrize('task_vars,expected_result', [
+ (
+ dict(
+ openshift=dict(common=dict(
+ service_type='origin',
+ is_containerized=False,
+ )),
+ openshift_release='v3.5',
+ deployment_type='origin',
+ openshift_image_tag='', # FIXME: should not be required
+ ),
+ {'changed': False},
+ ),
+ # TODO: add more parameters here to test the multiple possible inputs that affect behavior.
+])
+def test_docker_image_availability(task_vars, expected_result):
+ def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
+ return {'info': {}} # TODO: this will vary depending on input parameters.
+
+ check = DockerImageAvailability(execute_module=execute_module)
+ result = check.run(tmp=None, task_vars=task_vars)
+ assert result == expected_result
diff --git a/roles/openshift_health_checker/test/mixins_test.py b/roles/openshift_health_checker/test/mixins_test.py
new file mode 100644
index 000000000..2d83e207d
--- /dev/null
+++ b/roles/openshift_health_checker/test/mixins_test.py
@@ -0,0 +1,23 @@
+import pytest
+
+from openshift_checks import OpenShiftCheck, OpenShiftCheckException
+from openshift_checks.mixins import NotContainerizedMixin
+
+
+class NotContainerizedCheck(NotContainerizedMixin, OpenShiftCheck):
+ name = "not_containerized"
+ run = NotImplemented
+
+
+@pytest.mark.parametrize('task_vars,expected', [
+ (dict(openshift=dict(common=dict(is_containerized=False))), True),
+ (dict(openshift=dict(common=dict(is_containerized=True))), False),
+])
+def test_is_active(task_vars, expected):
+ assert NotContainerizedCheck.is_active(task_vars) == expected
+
+
+def test_is_active_missing_task_vars():
+ with pytest.raises(OpenShiftCheckException) as excinfo:
+ NotContainerizedCheck.is_active(task_vars={})
+ assert 'is_containerized' in str(excinfo.value)
diff --git a/roles/openshift_health_checker/test/openshift_check_test.py b/roles/openshift_health_checker/test/openshift_check_test.py
index c4c8cd1c2..e3153979c 100644
--- a/roles/openshift_health_checker/test/openshift_check_test.py
+++ b/roles/openshift_health_checker/test/openshift_check_test.py
@@ -1,6 +1,7 @@
import pytest
-from openshift_checks import get_var, OpenShiftCheckException
+from openshift_checks import OpenShiftCheck, OpenShiftCheckException
+from openshift_checks import load_checks, get_var
# Fixtures
@@ -22,6 +23,64 @@ def missing_keys(request):
# Tests
+def test_OpenShiftCheck_init():
+ class TestCheck(OpenShiftCheck):
+ name = "test_check"
+ run = NotImplemented
+
+ # initialization requires at least one argument (apart from self)
+ with pytest.raises(TypeError) as excinfo:
+ TestCheck()
+ assert 'execute_module' in str(excinfo.value)
+ assert 'module_executor' in str(excinfo.value)
+
+ execute_module = object()
+
+ # initialize with positional argument
+ check = TestCheck(execute_module)
+ # new recommended name
+ assert check.execute_module == execute_module
+ # deprecated attribute name
+ assert check.module_executor == execute_module
+
+ # initialize with keyword argument, recommended name
+ check = TestCheck(execute_module=execute_module)
+ # new recommended name
+ assert check.execute_module == execute_module
+ # deprecated attribute name
+ assert check.module_executor == execute_module
+
+ # initialize with keyword argument, deprecated name
+ check = TestCheck(module_executor=execute_module)
+ # new recommended name
+ assert check.execute_module == execute_module
+ # deprecated attribute name
+ assert check.module_executor == execute_module
+
+
+def test_subclasses():
+ """OpenShiftCheck.subclasses should find all subclasses recursively."""
+ class TestCheck1(OpenShiftCheck):
+ pass
+
+ class TestCheck2(OpenShiftCheck):
+ pass
+
+ class TestCheck1A(TestCheck1):
+ pass
+
+ local_subclasses = set([TestCheck1, TestCheck1A, TestCheck2])
+ known_subclasses = set(OpenShiftCheck.subclasses())
+
+ assert local_subclasses - known_subclasses == set(), "local_subclasses should be a subset of known_subclasses"
+
+
+def test_load_checks():
+ """Loading checks should load and return Python modules."""
+ modules = load_checks()
+ assert modules
+
+
@pytest.mark.parametrize("keys,expected", [
(("foo",), 42),
(("bar", "baz"), "openshift"),
diff --git a/roles/openshift_health_checker/test/package_availability_test.py b/roles/openshift_health_checker/test/package_availability_test.py
new file mode 100644
index 000000000..25385339a
--- /dev/null
+++ b/roles/openshift_health_checker/test/package_availability_test.py
@@ -0,0 +1,49 @@
+import pytest
+
+from openshift_checks.package_availability import PackageAvailability
+
+
+@pytest.mark.parametrize('task_vars,must_have_packages,must_not_have_packages', [
+ (
+ dict(openshift=dict(common=dict(service_type='openshift'))),
+ set(),
+ set(['openshift-master', 'openshift-node']),
+ ),
+ (
+ dict(
+ openshift=dict(common=dict(service_type='origin')),
+ group_names=['masters'],
+ ),
+ set(['origin-master']),
+ set(['origin-node']),
+ ),
+ (
+ dict(
+ openshift=dict(common=dict(service_type='atomic-openshift')),
+ group_names=['nodes'],
+ ),
+ set(['atomic-openshift-node']),
+ set(['atomic-openshift-master']),
+ ),
+ (
+ dict(
+ openshift=dict(common=dict(service_type='atomic-openshift')),
+ group_names=['masters', 'nodes'],
+ ),
+ set(['atomic-openshift-master', 'atomic-openshift-node']),
+ set(),
+ ),
+])
+def test_package_availability(task_vars, must_have_packages, must_not_have_packages):
+ return_value = object()
+
+ def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
+ assert module_name == 'check_yum_update'
+ assert 'packages' in module_args
+ assert set(module_args['packages']).issuperset(must_have_packages)
+ assert not set(module_args['packages']).intersection(must_not_have_packages)
+ return return_value
+
+ check = PackageAvailability(execute_module=execute_module)
+ result = check.run(tmp=None, task_vars=task_vars)
+ assert result is return_value
diff --git a/roles/openshift_health_checker/test/package_update_test.py b/roles/openshift_health_checker/test/package_update_test.py
new file mode 100644
index 000000000..5e000cff5
--- /dev/null
+++ b/roles/openshift_health_checker/test/package_update_test.py
@@ -0,0 +1,16 @@
+from openshift_checks.package_update import PackageUpdate
+
+
+def test_package_update():
+ return_value = object()
+
+ def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
+ assert module_name == 'check_yum_update'
+ assert 'packages' in module_args
+ # empty list of packages means "generic check if 'yum update' will work"
+ assert module_args['packages'] == []
+ return return_value
+
+ check = PackageUpdate(execute_module=execute_module)
+ result = check.run(tmp=None, task_vars=None)
+ assert result is return_value
diff --git a/roles/openshift_health_checker/test/package_version_test.py b/roles/openshift_health_checker/test/package_version_test.py
new file mode 100644
index 000000000..cc1d263bc
--- /dev/null
+++ b/roles/openshift_health_checker/test/package_version_test.py
@@ -0,0 +1,21 @@
+from openshift_checks.package_version import PackageVersion
+
+
+def test_package_version():
+ task_vars = dict(
+ openshift=dict(common=dict(service_type='origin')),
+ openshift_release='v3.5',
+ )
+ return_value = object()
+
+ def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
+ assert module_name == 'aos_version'
+ assert 'prefix' in module_args
+ assert 'version' in module_args
+ assert module_args['prefix'] == task_vars['openshift']['common']['service_type']
+ assert module_args['version'] == task_vars['openshift_release']
+ return return_value
+
+ check = PackageVersion(execute_module=execute_module)
+ result = check.run(tmp=None, task_vars=task_vars)
+ assert result is return_value