From a62594a2188343101d1c0ffa4588745d4a2044b4 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Fri, 10 Mar 2017 19:14:01 -0500 Subject: add etcd volume check --- .../test/etcd_volume_test.py | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 roles/openshift_health_checker/test/etcd_volume_test.py (limited to 'roles/openshift_health_checker/test') diff --git a/roles/openshift_health_checker/test/etcd_volume_test.py b/roles/openshift_health_checker/test/etcd_volume_test.py new file mode 100644 index 000000000..ff8d0d8d7 --- /dev/null +++ b/roles/openshift_health_checker/test/etcd_volume_test.py @@ -0,0 +1,149 @@ +import pytest + +from openshift_checks.etcd_volume import EtcdVolume, OpenShiftCheckException + + +@pytest.mark.parametrize('ansible_mounts,extra_words', [ + ([], ['none']), # empty ansible_mounts + ([{'mount': '/mnt'}], ['/mnt']), # missing relevant mount paths +]) +def test_cannot_determine_available_disk(ansible_mounts, extra_words): + task_vars = dict( + ansible_mounts=ansible_mounts, + ) + check = EtcdVolume(execute_module=fake_execute_module) + + with pytest.raises(OpenShiftCheckException) as excinfo: + check.run(tmp=None, task_vars=task_vars) + + for word in 'determine available disk'.split() + extra_words: + assert word in str(excinfo.value) + + +@pytest.mark.parametrize('size_limit,ansible_mounts', [ + ( + # if no size limit is specified, expect max usage + # limit to default to 90% of size_total + None, + [{ + 'mount': '/', + 'size_available': 40 * 10**9, + 'size_total': 80 * 10**9 + }], + ), + ( + 1, + [{ + 'mount': '/', + 'size_available': 30 * 10**9, + 'size_total': 30 * 10**9, + }], + ), + ( + 20000000000, + [{ + 'mount': '/', + 'size_available': 20 * 10**9, + 'size_total': 40 * 10**9, + }], + ), + ( + 5000000000, + [{ + # not enough space on / ... + 'mount': '/', + 'size_available': 0, + 'size_total': 0, + }, { + # not enough space on /var/lib ... + 'mount': '/var/lib', + 'size_available': 2 * 10**9, + 'size_total': 21 * 10**9, + }, { + # ... but enough on /var/lib/etcd + 'mount': '/var/lib/etcd', + 'size_available': 36 * 10**9, + 'size_total': 40 * 10**9 + }], + ) +]) +def test_succeeds_with_recommended_disk_space(size_limit, ansible_mounts): + task_vars = dict( + etcd_disk_size_limit_percent=size_limit, + ansible_mounts=ansible_mounts, + ) + + if task_vars["etcd_disk_size_limit_percent"] is None: + task_vars.pop("etcd_disk_size_limit_percent") + + check = EtcdVolume(execute_module=fake_execute_module) + result = check.run(tmp=None, task_vars=task_vars) + + assert not result.get('failed', False) + + +@pytest.mark.parametrize('size_limit_percent,ansible_mounts,extra_words', [ + ( + # if no size limit is specified, expect max usage + # limit to default to 90% of size_total + None, + [{ + 'mount': '/', + 'size_available': 1 * 10**9, + 'size_total': 100 * 10**9, + }], + ['90.00 GB'], + ), + ( + 0.7, + [{ + 'mount': '/', + 'size_available': 1 * 10**6, + 'size_total': 5 * 10**9, + }], + ['3.50 GB'], + ), + ( + 0.4, + [{ + 'mount': '/', + 'size_available': 2 * 10**9, + 'size_total': 6 * 10**9, + }], + ['2.40 GB'], + ), + ( + None, + [{ + # enough space on /var ... + 'mount': '/var', + 'size_available': 20 * 10**9, + 'size_total': 20 * 10**9, + }, { + # .. but not enough on /var/lib + 'mount': '/var/lib', + 'size_available': 1 * 10**9, + 'size_total': 20 * 10**9, + }], + ['18.00 GB'], + ), +]) +def test_fails_with_insufficient_disk_space(size_limit_percent, ansible_mounts, extra_words): + task_vars = dict( + etcd_disk_size_limit_percent=size_limit_percent, + ansible_mounts=ansible_mounts, + ) + + if task_vars["etcd_disk_size_limit_percent"] is None: + task_vars.pop("etcd_disk_size_limit_percent") + + check = EtcdVolume(execute_module=fake_execute_module) + result = check.run(tmp=None, task_vars=task_vars) + + assert result['failed'] + for word in extra_words: + assert word in result['msg'] + + +def fake_execute_module(*args): + raise AssertionError('this function should not be called') -- cgit v1.2.3 From 95fd767a8242c66f3d62428cb6fce88e2eca3c13 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Wed, 10 May 2017 17:11:23 +0200 Subject: Update check --- .../test/etcd_volume_test.py | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'roles/openshift_health_checker/test') diff --git a/roles/openshift_health_checker/test/etcd_volume_test.py b/roles/openshift_health_checker/test/etcd_volume_test.py index ff8d0d8d7..917045526 100644 --- a/roles/openshift_health_checker/test/etcd_volume_test.py +++ b/roles/openshift_health_checker/test/etcd_volume_test.py @@ -16,7 +16,7 @@ def test_cannot_determine_available_disk(ansible_mounts, extra_words): with pytest.raises(OpenShiftCheckException) as excinfo: check.run(tmp=None, task_vars=task_vars) - for word in 'determine available disk'.split() + extra_words: + for word in 'Unable to find etcd storage mount point'.split() + extra_words: assert word in str(excinfo.value) @@ -69,12 +69,12 @@ def test_cannot_determine_available_disk(ansible_mounts, extra_words): ]) def test_succeeds_with_recommended_disk_space(size_limit, ansible_mounts): task_vars = dict( - etcd_disk_size_limit_percent=size_limit, + etcd_device_usage_threshold_percent=size_limit, ansible_mounts=ansible_mounts, ) - if task_vars["etcd_disk_size_limit_percent"] is None: - task_vars.pop("etcd_disk_size_limit_percent") + if task_vars["etcd_device_usage_threshold_percent"] is None: + task_vars.pop("etcd_device_usage_threshold_percent") check = EtcdVolume(execute_module=fake_execute_module) result = check.run(tmp=None, task_vars=task_vars) @@ -92,25 +92,25 @@ def test_succeeds_with_recommended_disk_space(size_limit, ansible_mounts): 'size_available': 1 * 10**9, 'size_total': 100 * 10**9, }], - ['90.00 GB'], + ['99.0%'], ), ( - 0.7, + 70.0, [{ 'mount': '/', 'size_available': 1 * 10**6, 'size_total': 5 * 10**9, }], - ['3.50 GB'], + ['100.0%'], ), ( - 0.4, + 40.0, [{ 'mount': '/', 'size_available': 2 * 10**9, 'size_total': 6 * 10**9, }], - ['2.40 GB'], + ['66.7%'], ), ( None, @@ -125,17 +125,17 @@ def test_succeeds_with_recommended_disk_space(size_limit, ansible_mounts): 'size_available': 1 * 10**9, 'size_total': 20 * 10**9, }], - ['18.00 GB'], + ['95.0%'], ), ]) def test_fails_with_insufficient_disk_space(size_limit_percent, ansible_mounts, extra_words): task_vars = dict( - etcd_disk_size_limit_percent=size_limit_percent, + etcd_device_usage_threshold_percent=size_limit_percent, ansible_mounts=ansible_mounts, ) - if task_vars["etcd_disk_size_limit_percent"] is None: - task_vars.pop("etcd_disk_size_limit_percent") + if task_vars["etcd_device_usage_threshold_percent"] is None: + task_vars.pop("etcd_device_usage_threshold_percent") check = EtcdVolume(execute_module=fake_execute_module) result = check.run(tmp=None, task_vars=task_vars) -- cgit v1.2.3