From c74543f55b14b8153298baa0115f8ab05d2c6961 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Mon, 10 Apr 2017 19:25:55 +0200 Subject: 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. --- .../openshift_checks/disk_availability.py | 84 ++++++++++------------ 1 file changed, 38 insertions(+), 46 deletions(-) (limited to 'roles/openshift_health_checker/openshift_checks/disk_availability.py') diff --git a/roles/openshift_health_checker/openshift_checks/disk_availability.py b/roles/openshift_health_checker/openshift_checks/disk_availability.py index ecf5147fd..c2792a0fe 100644 --- a/roles/openshift_health_checker/openshift_checks/disk_availability.py +++ b/roles/openshift_health_checker/openshift_checks/disk_availability.py @@ -9,65 +9,57 @@ class DiskAvailability(NotContainerizedMixin, OpenShiftCheck): name = "disk_availability" tags = ["preflight"] - # all values are base-10 as they are taken, as is, from - # the latest requirements for an OpenShift installation + # Values taken from the official installation documentation: # https://docs.openshift.org/latest/install_config/install/prerequisites.html#system-requirements - recommended_diskspace = { - "nodes": 15 * 10 ** 9, - "masters": 40 * 10 ** 9, - "etcd": 20 * 10 ** 9, + recommended_disk_space_bytes = { + "masters": 40 * 10**9, + "nodes": 15 * 10**9, + "etcd": 20 * 10**9, } - def run(self, tmp, task_vars): - ansible_mounts = get_var(task_vars, "ansible_mounts") - self.recommended_diskspace["nodes"] = get_var(task_vars, - "min_recommended_diskspace_node", - default=self.recommended_diskspace["nodes"]) - self.recommended_diskspace["masters"] = get_var(task_vars, - "min_recommended_diskspace_master", - default=self.recommended_diskspace["masters"]) - self.recommended_diskspace["etcd"] = get_var(task_vars, - "min_recommended_diskspace_etcd", - default=self.recommended_diskspace["etcd"]) - - failed, msg = self.volume_check(ansible_mounts, task_vars) - return {"failed": failed, "msg": msg} - - def volume_check(self, ansible_mounts, task_vars): + @classmethod + def is_active(cls, task_vars): + """Skip hosts that do not have recommended disk space requirements.""" group_names = get_var(task_vars, "group_names", default=[]) + has_disk_space_recommendation = bool(set(group_names).intersection(cls.recommended_disk_space_bytes)) + return super(DiskAvailability, cls).is_active(task_vars) and has_disk_space_recommendation - if not set(self.recommended_diskspace).intersection(group_names): - msg = "Unable to determine recommended volume size for group_name {group_name}" - raise OpenShiftCheckException(msg.format(group_name=group_names)) + def run(self, tmp, task_vars): + group_names = get_var(task_vars, "group_names") + ansible_mounts = get_var(task_vars, "ansible_mounts") - recommended_diskspace_bytes = max(self.recommended_diskspace.get(group, 0) for group in group_names) - openshift_diskfree_bytes = self.get_openshift_disk_availability(ansible_mounts) + min_free_bytes = max(self.recommended_disk_space_bytes.get(name, 0) for name in group_names) + free_bytes = self.openshift_available_disk(ansible_mounts) - if openshift_diskfree_bytes < recommended_diskspace_bytes: - msg = ("Available disk space ({diskfree} GB) for the volume containing \"/var\" is " - "below recommended storage. Minimum required disk space: {recommended} GB") - return True, msg.format(diskfree=self.to_gigabytes(openshift_diskfree_bytes), - recommended=self.to_gigabytes(recommended_diskspace_bytes)) + if free_bytes < min_free_bytes: + return { + 'failed': True, + 'msg': ( + 'Available disk space ({:.1f} GB) for the volume containing ' + '"/var" is below minimum recommended space ({:.1f} GB)' + ).format(float(free_bytes) / 10**9, float(min_free_bytes) / 10**9) + } - return False, "" + return {} @staticmethod - def get_openshift_disk_availability(ansible_mounts): - """Iterates through a map of mounted volumes to determine space remaining on the OpenShift volume""" - if not ansible_mounts: - msg = "Unable to determine existing volume mounts from ansible_mounts" - raise OpenShiftCheckException(msg) + def openshift_available_disk(ansible_mounts): + """Determine the available disk space for an OpenShift installation. + ansible_mounts should be a list of dicts like the 'setup' Ansible module + returns. + """ # priority list in descending order supported_mnt_paths = ["/var", "/"] available_mnts = {mnt.get("mount"): mnt for mnt in ansible_mounts} - for path in supported_mnt_paths: - if path in available_mnts: - return available_mnts[path].get("size_available") + try: + for path in supported_mnt_paths: + if path in available_mnts: + return available_mnts[path]["size_available"] + except KeyError: + pass - return 0 - - @staticmethod - def to_gigabytes(total_bytes): - return total_bytes / 10**9 + paths = ''.join(sorted(available_mnts)) or 'none' + msg = "Unable to determine available disk space. Paths mounted: {}.".format(paths) + raise OpenShiftCheckException(msg) -- cgit v1.2.3