summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/openshift_checks/mixins.py
diff options
context:
space:
mode:
authorLuke Meyer <lmeyer@redhat.com>2017-06-01 19:24:31 -0400
committerLuke Meyer <lmeyer@redhat.com>2017-06-07 19:27:31 -0400
commita092dff53070c4eaa942dae36fc8742a7d53959d (patch)
tree332bd39ce6938982317c7054c48e239e242f71e5 /roles/openshift_health_checker/openshift_checks/mixins.py
parent055082c1679cb253758bc16e0a6ca37f70d0bc65 (diff)
downloadopenshift-a092dff53070c4eaa942dae36fc8742a7d53959d.tar.gz
openshift-a092dff53070c4eaa942dae36fc8742a7d53959d.tar.bz2
openshift-a092dff53070c4eaa942dae36fc8742a7d53959d.tar.xz
openshift-a092dff53070c4eaa942dae36fc8742a7d53959d.zip
docker checks: finish and refactor
Incorporated docker_storage_driver into docker_storage as both need driver info. Corrected storage calculation to include VG free space, not just the current amount in the LV pool. Now makes no assumptions about pool name. Improved user messaging. Factored out some methods that can be shared with docker_image_availability.
Diffstat (limited to 'roles/openshift_health_checker/openshift_checks/mixins.py')
-rw-r--r--roles/openshift_health_checker/openshift_checks/mixins.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/roles/openshift_health_checker/openshift_checks/mixins.py b/roles/openshift_health_checker/openshift_checks/mixins.py
index 20d160eaf..1181784ab 100644
--- a/roles/openshift_health_checker/openshift_checks/mixins.py
+++ b/roles/openshift_health_checker/openshift_checks/mixins.py
@@ -1,4 +1,3 @@
-# pylint: disable=missing-docstring,too-few-public-methods
"""
Mixin classes meant to be used with subclasses of OpenShiftCheck.
"""
@@ -8,8 +7,47 @@ from openshift_checks import get_var
class NotContainerizedMixin(object):
"""Mixin for checks that are only active when not in containerized mode."""
+ # permanent # pylint: disable=too-few-public-methods
+ # Reason: The mixin is not intended to stand on its own as a class.
@classmethod
def is_active(cls, task_vars):
+ """Only run on non-containerized hosts."""
is_containerized = get_var(task_vars, "openshift", "common", "is_containerized")
return super(NotContainerizedMixin, cls).is_active(task_vars) and not is_containerized
+
+
+class DockerHostMixin(object):
+ """Mixin for checks that are only active on hosts that require Docker."""
+
+ dependencies = []
+
+ @classmethod
+ def is_active(cls, task_vars):
+ """Only run on hosts that depend on Docker."""
+ is_containerized = get_var(task_vars, "openshift", "common", "is_containerized")
+ is_node = "nodes" in get_var(task_vars, "group_names", default=[])
+ return super(DockerHostMixin, cls).is_active(task_vars) and (is_containerized or is_node)
+
+ def ensure_dependencies(self, task_vars):
+ """
+ Ensure that docker-related packages exist, but not on atomic hosts
+ (which would not be able to install but should already have them).
+ Returns: msg, failed, changed
+ """
+ if get_var(task_vars, "openshift", "common", "is_atomic"):
+ return "", False, False
+
+ # NOTE: we would use the "package" module but it's actually an action plugin
+ # and it's not clear how to invoke one of those. This is about the same anyway:
+ pkg_manager = get_var(task_vars, "ansible_pkg_mgr", default="yum")
+ result = self.module_executor(pkg_manager, {"name": self.dependencies, "state": "present"}, task_vars)
+ msg = result.get("msg", "")
+ if result.get("failed"):
+ if "No package matching" in msg:
+ msg = "Ensure that all required dependencies can be installed via `yum`.\n"
+ msg = (
+ "Unable to install required packages on this host:\n"
+ " {deps}\n{msg}"
+ ).format(deps=',\n '.join(self.dependencies), msg=msg)
+ return msg, result.get("failed") or result.get("rc", 0) != 0, result.get("changed")