From edde1f2bf0fa180fc69d905ce2aa27e68f7295dd Mon Sep 17 00:00:00 2001 From: Michael Gugino Date: Wed, 3 Jan 2018 13:55:29 -0500 Subject: Fix docker_image_availability checks This commit ensures that oreg_url is properly templated by ansible before being consumed in the logic. This commit also adds a method to the base health check class to detect if self._templar is none, and return the appropriate templated/untemplated version of the variable. This is mostly for unit tests. --- roles/openshift_health_checker/openshift_checks/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py') diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py index b7b16e0ea..83e551b5d 100644 --- a/roles/openshift_health_checker/openshift_checks/__init__.py +++ b/roles/openshift_health_checker/openshift_checks/__init__.py @@ -95,6 +95,13 @@ class OpenShiftCheck(object): # These are intended to be a sequential record of what the check observed and determined. self.logs = [] + def template_var(self, var_to_template): + """Return a templated variable if self._templar is not None, else + just return the variable as-is""" + if self._templar is not None: + return self._templar.template(var_to_template) + return var_to_template + @abstractproperty def name(self): """The name of this check, usually derived from the class name.""" -- cgit v1.2.3 From 9f461f2ad2b11ca87ef1ce6ee381ccf31b703fc8 Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Wed, 17 Jan 2018 09:18:36 -0500 Subject: package_version check: reuse get_major_minor_version --- .../openshift_checks/__init__.py | 25 ++++++++-------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py') diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py index 83e551b5d..8c3d71ca9 100644 --- a/roles/openshift_health_checker/openshift_checks/__init__.py +++ b/roles/openshift_health_checker/openshift_checks/__init__.py @@ -5,6 +5,7 @@ Health checks for OpenShift clusters. import json import operator import os +import re import time import collections @@ -309,28 +310,20 @@ class OpenShiftCheck(object): name_list = name_list.split(',') return [name.strip() for name in name_list if name.strip()] - @staticmethod - def get_major_minor_version(openshift_image_tag): + def get_major_minor_version(self, openshift_image_tag=None): """Parse and return the deployed version of OpenShift as a tuple.""" - if openshift_image_tag and openshift_image_tag[0] == 'v': - openshift_image_tag = openshift_image_tag[1:] - # map major release versions across releases - # to a common major version - openshift_major_release_version = { - "1": "3", - } + version = openshift_image_tag or self.get_var("openshift_image_tag") + components = [int(component) for component in re.findall(r'\d+', version)] - components = openshift_image_tag.split(".") - if not components or len(components) < 2: + if len(components) < 2: msg = "An invalid version of OpenShift was found for this host: {}" - raise OpenShiftCheckException(msg.format(openshift_image_tag)) + raise OpenShiftCheckException(msg.format(version)) - if components[0] in openshift_major_release_version: - components[0] = openshift_major_release_version[components[0]] + # map major release version across releases to OCP major version + components[0] = {1: 3}.get(components[0], components[0]) - components = tuple(int(x) for x in components[:2]) - return components + return tuple(int(x) for x in components[:2]) def find_ansible_mount(self, path): """Return the mount point for path from ansible_mounts.""" -- cgit v1.2.3 From b4b5b685581a6c4b35953bf32d56c1f96b12ff51 Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Wed, 17 Jan 2018 10:24:14 -0500 Subject: health checks: factor out get_required_version --- .../openshift_checks/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py') diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py index 8c3d71ca9..b9c41d1b4 100644 --- a/roles/openshift_health_checker/openshift_checks/__init__.py +++ b/roles/openshift_health_checker/openshift_checks/__init__.py @@ -325,6 +325,24 @@ class OpenShiftCheck(object): return tuple(int(x) for x in components[:2]) + def get_required_version(self, name, version_map): + """Return the correct required version(s) for the current (or nearest) OpenShift version.""" + openshift_version = self.get_major_minor_version() + + earliest = min(version_map) + latest = max(version_map) + if openshift_version < earliest: + return version_map[earliest] + if openshift_version > latest: + return version_map[latest] + + required_version = version_map.get(openshift_version) + if not required_version: + msg = "There is no recommended version of {} for the current version of OpenShift ({})" + raise OpenShiftCheckException(msg.format(name, ".".join(str(comp) for comp in openshift_version))) + + return required_version + def find_ansible_mount(self, path): """Return the mount point for path from ansible_mounts.""" -- cgit v1.2.3