diff --git a/roles/openshift_health_checker/openshift_checks/diskspace_availability.py b/roles/openshift_health_checker/openshift_checks/diskspace_availability.py new file mode 100644 index 00000000000..d0779df5048 --- /dev/null +++ b/roles/openshift_health_checker/openshift_checks/diskspace_availability.py @@ -0,0 +1,60 @@ +# pylint: disable=missing-docstring +from openshift_checks import OpenShiftCheck, get_var +from openshift_checks.mixins import NotContainerizedMixin + +import json + + +class DiskAvailability(OpenShiftCheck): + """Check that recommended disk space is available.""" + + name = "disk_availability" + tags = ["preflight"] + + recommended_node_diskspace_gb = 15.0 + recommended_master_diskspace_gb = 40.0 + + def run(self, tmp, task_vars): + is_containerized = get_var(task_vars, "openshift", "common", "is_containerized") + group_names = get_var(task_vars, "group_names", default=[]) + ansible_mounts = get_var(task_vars, "ansible_mounts") + diskfree = self.to_gigabytes(self.get_disk_space(ansible_mounts, is_containerized)) + + return {"failed": True, "msg": "ansible mounts %s" % json.dumps(ansible_mounts)} + + recommended_diskspace_gb = self.recommended_master_diskspace_gb + + if "nodes" in group_names: + recommended_diskspace_gb = self.recommended_node_diskspace_gb + + if float(diskfree) < recommended_diskspace_gb: + return {"failed": True, "msg": "Available disk space for %s (%s) below recommended storage. Minimum required disk space: %s GB" % ("node" if "nodes" in group_names else "master", str(diskfree) + " GB", recommended_diskspace_gb)} + + # if filesystem containing /var meets recommended diskspace, + # iterate through remaining mounted filesystems and output + # a warning if any are more than 90% full + check_mountpoints(ansible_mounts) + + return {"changed": False} + + @staticmethod + def get_disk_space(ansible_mounts, is_containerized): + if len(ansible_mounts): + for mnt in ansible_mounts: + if mnt.get("mount") == "/": + return mnt.get("size_available") + + return None + + @staticmethod + def check_mountpoints(ansible_mounts): + if len(ansible_mounts): + for mnt in ansible_mounts: + if mnt.get("mount") == "/": + return mnt.get("size_available") + + return None + + @staticmethod + def to_gigabytes(total_bytes): + return total_bytes / 1073741824 diff --git a/roles/openshift_health_checker/openshift_checks/memory_availability.py b/roles/openshift_health_checker/openshift_checks/memory_availability.py new file mode 100644 index 00000000000..16c2cb26388 --- /dev/null +++ b/roles/openshift_health_checker/openshift_checks/memory_availability.py @@ -0,0 +1,31 @@ +# pylint: disable=missing-docstring +from openshift_checks import OpenShiftCheck, get_var +from openshift_checks.mixins import NotContainerizedMixin + + +class MemoryAvailability(OpenShiftCheck): + """Check that recommended memory is available.""" + + name = "memory_availability" + tags = ["preflight"] + + recommended_node_memory_gb = 8.0 + recommended_master_memory_gb = 16.0 + + def run(self, tmp, task_vars): + group_names = get_var(task_vars, "group_names", default=[]) + memoryfree = get_var(task_vars, "facter_memoryfree") + + recommended_memory_gb = self.recommended_master_memory_gb + + if "nodes" in group_names: + recommended_memory_gb = self.recommended_node_memory_gb + + if self.mem_to_float(memoryfree) < recommended_memory_gb: + return {"failed": True, "msg": "Available memory for %s (%s) below recommended storage. Minimum required memory: %s GB" % ("node" if "nodes" in group_names else "master", memoryfree, recommended_memory_gb)} + + return {"changed": False} + + @staticmethod + def mem_to_float(mem): + return float(mem.rstrip(" GB")) diff --git a/roles/openshift_health_checker/openshift_checks/ram_diskspace_availability.py b/roles/openshift_health_checker/openshift_checks/ram_diskspace_availability.py deleted file mode 100644 index 1f306b51bb3..00000000000 --- a/roles/openshift_health_checker/openshift_checks/ram_diskspace_availability.py +++ /dev/null @@ -1,42 +0,0 @@ -# pylint: disable=missing-docstring -from openshift_checks import OpenShiftCheck, get_var -from openshift_checks.mixins import NotContainerizedMixin - - -class RamDiskspaceAvailability(NotContainerizedMixin, OpenShiftCheck): - """Check that recommended memory and disk-space are available.""" - - name = "ram_diskspace_availability" - tags = ["preflight"] - - # attempt to pull required docker images and fail if - # any images are missing, or error occurs during pull - def run(self, tmp, task_vars): - ansible_mounts = get_var(task_vars, "ansible_mounts") - diskfree = self.to_gigabytes(self.get_disk_space(ansible_mounts)) - memoryfree = get_var(task_vars, "facter_memoryfree") - - recommended_memory = get_var(task_vars, "min_memory_gb") - recommended_storage = get_var(task_vars, "min_diskspace_gb") - - if self.mem_to_float(memoryfree) < float(recommended_memory) or float(diskfree) < float(recommended_storage): - return {"failed": True, "msg": "Available memory (%s) or disk space (%s) below recommended storage. Minimum required memory: %s GB, Minimum required disk space: %s GB" % (memoryfree, str(diskfree) + " GB", recommended_memory, recommended_storage)} - - return {"changed": False} - - @staticmethod - def get_disk_space(ansible_mounts): - if len(ansible_mounts): - for mnt in ansible_mounts: - if mnt.get("mount") == "/": - return mnt.get("size_available") - - return None - - @staticmethod - def to_gigabytes(total_bytes): - return total_bytes / 1073741824 - - @staticmethod - def mem_to_float(mem): - return float(mem.rstrip(" GB"))