From 44fef0996a68418dca2937ae00662365b6179450 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 21 Jun 2017 14:11:32 -0400 Subject: [PATCH] lower disk requirement on "upgrade" context --- .../openshift_checks/disk_availability.py | 18 ++++++ .../test/disk_availability_test.py | 57 ++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/roles/openshift_health_checker/openshift_checks/disk_availability.py b/roles/openshift_health_checker/openshift_checks/disk_availability.py index 962148cb8b7..42ace3a0cc0 100644 --- a/roles/openshift_health_checker/openshift_checks/disk_availability.py +++ b/roles/openshift_health_checker/openshift_checks/disk_availability.py @@ -33,6 +33,24 @@ def run(self, tmp, task_vars): configured_min = int(get_var(task_vars, "openshift_check_min_host_disk_gb", default=0)) * 10**9 min_free_bytes = configured_min or recommended_min + # if an "upgrade" context is set, lower the minimum disk requirement + # as this signifies an in-place upgrade - the node might have the + # required total disk space, but some of that space may already be + # in use by the existing OpenShift deployment. + context = get_var(task_vars, "r_openshift_health_checker_playbook_context", default="") + if context == "upgrade": + upgrade_min_required_diskspace = 5.0 * 10**9 + if free_bytes < upgrade_min_required_diskspace: + return { + 'failed': True, + 'msg': ( + 'Available disk space ({:.1f} GB) for the volume containing ' + '"/var" is below minimum recommended space for an upgrade ({:.1f} GB).' + ).format(float(free_bytes) / 10**9, float(upgrade_min_required_diskspace) / 10**9) + } + + return {} + if free_bytes < min_free_bytes: return { 'failed': True, diff --git a/roles/openshift_health_checker/test/disk_availability_test.py b/roles/openshift_health_checker/test/disk_availability_test.py index b353fa61001..45f9e9ebdd3 100644 --- a/roles/openshift_health_checker/test/disk_availability_test.py +++ b/roles/openshift_health_checker/test/disk_availability_test.py @@ -176,7 +176,62 @@ def test_fails_with_insufficient_disk_space(group_names, configured_min, ansible assert result['failed'] for word in 'below recommended'.split() + extra_words: - assert word in result['msg'] + assert word in result.get('msg', '') + + +@pytest.mark.parametrize('group_names,context,ansible_mounts,failed,extra_words', [ + ( + ['nodes', 'masters'], + "upgrade", + [{ + 'mount': '/', + # not enough space for a master + # even under an "upgrade" context + 'size_available': 1 * 10**9 + 1, + 'size_total': 21 * 10**9 + 1, + }], + True, + ["1.0 GB"], + ), + ( + ['nodes', 'masters'], + "upgrade", + [{ + 'mount': '/', + # not enough space for a master, + # but enough under "upgrade" context + 'size_available': 10 * 10**9 + 1, + 'size_total': 21 * 10**9 + 1, + }], + False, + [], + ), + ( + ['nodes', 'masters'], + "health", + [{ + 'mount': '/', + # not enough space for a master, + # "health" context should not lower requirement + 'size_available': 20 * 10**9 + 1, + }], + True, + ["20.0 GB", "below minimum"], + ), +]) +def test_min_required_space_decreases_with_upgrade_context(group_names, context, ansible_mounts, failed, extra_words): + task_vars = dict( + r_openshift_health_checker_playbook_context=context, + 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 result.get("failed", False) == failed + for word in extra_words: + assert word in result.get('msg', '') def fake_execute_module(*args):