summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/openshift_checks/__init__.py
diff options
context:
space:
mode:
authorLuke Meyer <lmeyer@redhat.com>2017-08-23 17:44:19 -0400
committerLuke Meyer <lmeyer@redhat.com>2017-09-12 10:31:45 -0400
commita202f1647a28e4d246d0341e37501df44cb1a914 (patch)
tree2dfcfd0dd5f475bff402ea6c8a4e9cc0bda7ac79 /roles/openshift_health_checker/openshift_checks/__init__.py
parentf4a328ad2dc1d1ba93efa15ac0bf4502bad40079 (diff)
downloadopenshift-a202f1647a28e4d246d0341e37501df44cb1a914.tar.gz
openshift-a202f1647a28e4d246d0341e37501df44cb1a914.tar.bz2
openshift-a202f1647a28e4d246d0341e37501df44cb1a914.tar.xz
openshift-a202f1647a28e4d246d0341e37501df44cb1a914.zip
openshift_checks: add retries in python
Diffstat (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py')
-rw-r--r--roles/openshift_health_checker/openshift_checks/__init__.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py
index 02ee1d0f9..987c955b6 100644
--- a/roles/openshift_health_checker/openshift_checks/__init__.py
+++ b/roles/openshift_health_checker/openshift_checks/__init__.py
@@ -4,6 +4,7 @@ Health checks for OpenShift clusters.
import operator
import os
+import time
from abc import ABCMeta, abstractmethod, abstractproperty
from importlib import import_module
@@ -57,6 +58,9 @@ class OpenShiftCheck(object):
self._execute_module = execute_module
self.task_vars = task_vars or {}
self.tmp = tmp
+ # mainly for testing purposes; see execute_module_with_retries
+ self._module_retries = 3
+ self._module_retry_interval = 5 # seconds
# set to True when the check changes the host, for accurate total "changed" count
self.changed = False
@@ -115,6 +119,19 @@ class OpenShiftCheck(object):
)
return self._execute_module(module_name, module_args, self.tmp, self.task_vars)
+ def execute_module_with_retries(self, module_name, module_args):
+ """Run execute_module and retry on failure."""
+ result = {}
+ tries = 0
+ while True:
+ res = self.execute_module(module_name, module_args)
+ if tries > self._module_retries or not res.get("failed"):
+ result.update(res)
+ return result
+ result["last_failed"] = res
+ tries += 1
+ time.sleep(self._module_retry_interval)
+
def get_var(self, *keys, **kwargs):
"""Get deeply nested values from task_vars.