diff options
author | Rodolfo Carvalho <rhcarvalho@gmail.com> | 2017-01-31 18:15:19 +0100 |
---|---|---|
committer | Rodolfo Carvalho <rhcarvalho@gmail.com> | 2017-02-10 14:46:40 +0100 |
commit | c838e0f0b79b1471c47addf50c46fdb12281812c (patch) | |
tree | f677cb7bc70bb42167264b88f6ca1103ca370a71 /roles | |
parent | bb38413fcec7fb2640939782d57e494b40e3b41e (diff) | |
download | openshift-c838e0f0b79b1471c47addf50c46fdb12281812c.tar.gz openshift-c838e0f0b79b1471c47addf50c46fdb12281812c.tar.bz2 openshift-c838e0f0b79b1471c47addf50c46fdb12281812c.tar.xz openshift-c838e0f0b79b1471c47addf50c46fdb12281812c.zip |
Introduce tag notation for checks
This allows us to refer to a group of checks using a single handle.
Diffstat (limited to 'roles')
5 files changed, 34 insertions, 1 deletions
diff --git a/roles/openshift_health_checker/action_plugins/openshift_health_check.py b/roles/openshift_health_checker/action_plugins/openshift_health_check.py index 36defde0a..0411797b1 100644 --- a/roles/openshift_health_checker/action_plugins/openshift_health_check.py +++ b/roles/openshift_health_checker/action_plugins/openshift_health_check.py @@ -41,7 +41,7 @@ class ActionModule(ActionBase): return result args = self._task.args - requested_checks = set(args.get("checks", [])) + requested_checks = resolve_checks(args.get("checks", []), known_checks.values()) unknown_checks = requested_checks - set(known_checks) if unknown_checks: @@ -93,3 +93,24 @@ class ActionModule(ActionBase): known_checks[check_name] = cls(module_executor=self._execute_module) return known_checks + + +def resolve_checks(names, all_checks): + """Returns a set of resolved check names. + + Resolving a check name involves expanding tag references (e.g., '@tag') with + all the checks that contain the given tag. + + names should be a sequence of strings. + + all_checks should be a sequence of check classes/instances. + """ + resolved = set() + for name in names: + if name.startswith("@"): + for check in all_checks: + if name[1:] in check.tags: + resolved.add(check.name) + else: + resolved.add(name) + return resolved diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py index d893ba591..ff99e7b4c 100644 --- a/roles/openshift_health_checker/openshift_checks/__init__.py +++ b/roles/openshift_health_checker/openshift_checks/__init__.py @@ -26,6 +26,15 @@ class OpenShiftCheck(object): """The name of this check, usually derived from the class name.""" return "openshift_check" + @property + def tags(self): + """A list of tags that this check satisfy. + + Tags are used to reference multiple checks with a single '@tagname' + special check name. + """ + return [] + @classmethod def is_active(cls, task_vars): # pylint: disable=unused-argument """Returns true if this check applies to the ansible-playbook run.""" diff --git a/roles/openshift_health_checker/openshift_checks/package_availability.py b/roles/openshift_health_checker/openshift_checks/package_availability.py index 4260cbf7c..31277a3b9 100644 --- a/roles/openshift_health_checker/openshift_checks/package_availability.py +++ b/roles/openshift_health_checker/openshift_checks/package_availability.py @@ -7,6 +7,7 @@ class PackageAvailability(NotContainerized, OpenShiftCheck): """Check that required RPM packages are available.""" name = "package_availability" + tags = ["preflight"] def run(self, tmp, task_vars): try: diff --git a/roles/openshift_health_checker/openshift_checks/package_update.py b/roles/openshift_health_checker/openshift_checks/package_update.py index 316a776f5..86b7b6245 100644 --- a/roles/openshift_health_checker/openshift_checks/package_update.py +++ b/roles/openshift_health_checker/openshift_checks/package_update.py @@ -7,6 +7,7 @@ class PackageUpdate(NotContainerized, OpenShiftCheck): """Check that there are no conflicts in RPM packages.""" name = "package_update" + tags = ["preflight"] def run(self, tmp, task_vars): args = {"packages": []} diff --git a/roles/openshift_health_checker/openshift_checks/package_version.py b/roles/openshift_health_checker/openshift_checks/package_version.py index a473119f3..9394466f2 100644 --- a/roles/openshift_health_checker/openshift_checks/package_version.py +++ b/roles/openshift_health_checker/openshift_checks/package_version.py @@ -7,6 +7,7 @@ class PackageVersion(NotContainerized, OpenShiftCheck): """Check that available RPM packages match the required versions.""" name = "package_version" + tags = ["preflight"] @classmethod def is_active(cls, task_vars): |