summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test
diff options
context:
space:
mode:
authorRodolfo Carvalho <rhcarvalho@gmail.com>2017-04-10 19:25:55 +0200
committerjuanvallejo <jvallejo@redhat.com>2017-04-17 13:29:24 -0400
commitc74543f55b14b8153298baa0115f8ab05d2c6961 (patch)
treefe037320939807e307d162f938e63d0af9003147 /roles/openshift_health_checker/test
parent58fdef2696f7f1f0c6f3b5aa404427a2fc5a00f2 (diff)
downloadopenshift-c74543f55b14b8153298baa0115f8ab05d2c6961.tar.gz
openshift-c74543f55b14b8153298baa0115f8ab05d2c6961.tar.bz2
openshift-c74543f55b14b8153298baa0115f8ab05d2c6961.tar.xz
openshift-c74543f55b14b8153298baa0115f8ab05d2c6961.zip
Simplify disk availability check, review tests
- only support a fixed list of recommended values for now, no overwriting via Ansible variables (keep it simple, add features as needed). - implement is_active: run this check only for hosts that have a recommended disk space. - test priority of mount paths / and /var.
Diffstat (limited to 'roles/openshift_health_checker/test')
-rw-r--r--roles/openshift_health_checker/test/disk_availability_test.py205
1 files changed, 127 insertions, 78 deletions
diff --git a/roles/openshift_health_checker/test/disk_availability_test.py b/roles/openshift_health_checker/test/disk_availability_test.py
index e9d1097a1..8054ad25c 100644
--- a/roles/openshift_health_checker/test/disk_availability_test.py
+++ b/roles/openshift_health_checker/test/disk_availability_test.py
@@ -3,104 +3,153 @@ import pytest
from openshift_checks.disk_availability import DiskAvailability, OpenShiftCheckException
-def test_exception_raised_on_empty_ansible_mounts():
+@pytest.mark.parametrize('group_names,is_containerized,is_active', [
+ (['masters'], False, True),
+ # ensure check is skipped on containerized installs
+ (['masters'], True, False),
+ (['nodes'], False, True),
+ (['etcd'], False, True),
+ (['masters', 'nodes'], False, True),
+ (['masters', 'etcd'], False, True),
+ ([], False, False),
+ (['lb'], False, False),
+ (['nfs'], False, False),
+])
+def test_is_active(group_names, is_containerized, is_active):
+ task_vars = dict(
+ group_names=group_names,
+ openshift=dict(common=dict(is_containerized=is_containerized)),
+ )
+ assert DiskAvailability.is_active(task_vars=task_vars) == is_active
+
+
+@pytest.mark.parametrize('ansible_mounts,extra_words', [
+ ([], ['none']), # empty ansible_mounts
+ ([{'mount': '/mnt'}], ['/mnt']), # missing relevant mount paths
+ ([{'mount': '/var'}], ['/var']), # missing size_available
+])
+def test_cannot_determine_available_disk(ansible_mounts, extra_words):
+ task_vars = dict(
+ group_names=['masters'],
+ ansible_mounts=ansible_mounts,
+ )
+ check = DiskAvailability(execute_module=fake_execute_module)
+
with pytest.raises(OpenShiftCheckException) as excinfo:
- DiskAvailability(execute_module=NotImplementedError).get_openshift_disk_availability([])
+ check.run(tmp=None, task_vars=task_vars)
- assert "existing volume mounts from ansible_mounts" in str(excinfo.value)
+ for word in 'determine available disk'.split() + extra_words:
+ assert word in str(excinfo.value)
-@pytest.mark.parametrize("group_name,size_available", [
+@pytest.mark.parametrize('group_names,ansible_mounts', [
+ (
+ ['masters'],
+ [{
+ 'mount': '/',
+ 'size_available': 40 * 10**9 + 1,
+ }],
+ ),
(
- "masters",
- 41110980608,
+ ['nodes'],
+ [{
+ 'mount': '/',
+ 'size_available': 15 * 10**9 + 1,
+ }],
),
(
- "nodes",
- 21110980608,
+ ['etcd'],
+ [{
+ 'mount': '/',
+ 'size_available': 20 * 10**9 + 1,
+ }],
),
(
- "etcd",
- 21110980608,
+ ['etcd'],
+ [{
+ # not enough space on / ...
+ 'mount': '/',
+ 'size_available': 0,
+ }, {
+ # ... but enough on /var
+ 'mount': '/var',
+ 'size_available': 20 * 10**9 + 1,
+ }],
),
])
-def test_volume_check_with_recommended_diskspace(group_name, size_available):
- result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict(
- openshift=dict(common=dict(
- service_type='origin',
- is_containerized=False,
- )),
- group_names=[group_name],
- ansible_mounts=[{
- "mount": "/",
- "size_available": size_available,
- }]
- ))
-
- assert not result['failed']
- assert not result['msg']
-
-
-@pytest.mark.parametrize("group_name,size_available", [
+def test_succeeds_with_recommended_disk_space(group_names, ansible_mounts):
+ task_vars = dict(
+ group_names=group_names,
+ ansible_mounts=ansible_mounts,
+ )
+
+ check = DiskAvailability(execute_module=fake_execute_module)
+ result = check.run(tmp=None, task_vars=task_vars)
+
+ assert not result.get('failed', False)
+
+
+@pytest.mark.parametrize('group_names,ansible_mounts,extra_words', [
+ (
+ ['masters'],
+ [{
+ 'mount': '/',
+ 'size_available': 1,
+ }],
+ ['0.0 GB'],
+ ),
(
- "masters",
- 21110980608,
+ ['nodes'],
+ [{
+ 'mount': '/',
+ 'size_available': 1 * 10**9,
+ }],
+ ['1.0 GB'],
),
(
- "nodes",
- 1110980608,
+ ['etcd'],
+ [{
+ 'mount': '/',
+ 'size_available': 1,
+ }],
+ ['0.0 GB'],
),
(
- "etcd",
- 1110980608,
+ ['nodes', 'masters'],
+ [{
+ 'mount': '/',
+ # enough space for a node, not enough for a master
+ 'size_available': 15 * 10**9 + 1,
+ }],
+ ['15.0 GB'],
+ ),
+ (
+ ['etcd'],
+ [{
+ # enough space on / ...
+ 'mount': '/',
+ 'size_available': 20 * 10**9 + 1,
+ }, {
+ # .. but not enough on /var
+ 'mount': '/var',
+ 'size_available': 0,
+ }],
+ ['0.0 GB'],
),
])
-def test_volume_check_with_insufficient_diskspace(group_name, size_available):
- result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict(
- openshift=dict(common=dict(
- service_type='origin',
- is_containerized=False,
- )),
- group_names=[group_name],
- ansible_mounts=[{
- "mount": "/",
- "size_available": size_available,
- }]
- ))
+def test_fails_with_insufficient_disk_space(group_names, ansible_mounts, extra_words):
+ task_vars = dict(
+ group_names=group_names,
+ ansible_mounts=ansible_mounts,
+ )
- assert result['failed']
- assert "is below recommended storage" in result['msg']
-
-
-def test_volume_check_with_unsupported_mountpaths():
- result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict(
- openshift=dict(common=dict(
- service_type='origin',
- is_containerized=False,
- )),
- group_names=["masters", "nodes"],
- ansible_mounts=[{
- "mount": "/unsupported",
- "size_available": 12345,
- }]
- ))
+ check = DiskAvailability(execute_module=fake_execute_module)
+ result = check.run(tmp=None, task_vars=task_vars)
assert result['failed']
- assert "0 GB" in result['msg']
+ for word in 'below recommended'.split() + extra_words:
+ assert word in result['msg']
-def test_volume_check_with_invalid_groupname():
- with pytest.raises(OpenShiftCheckException) as excinfo:
- result = DiskAvailability(execute_module=NotImplementedError).run(tmp=None, task_vars=dict(
- openshift=dict(common=dict(
- service_type='origin',
- is_containerized=False,
- )),
- group_names=["invalid"],
- ansible_mounts=[{
- "mount": "/unsupported",
- "size_available": 12345,
- }]
- ))
-
- assert "'invalid'" in str(excinfo.value)
+def fake_execute_module(*args):
+ raise AssertionError('this function should not be called')