Przeglądaj źródła

Merge pull request #5401 from sosiouxme/20170913-retries-subset

add retries on repoquery
Luke Meyer 7 lat temu
rodzic
commit
51837924d8

+ 2 - 0
roles/docker/tasks/package_docker.yml

@@ -3,6 +3,8 @@
   command: "{{ repoquery_cmd }} --installed --qf '%{version}' docker"
   when: not openshift.common.is_atomic | bool
   register: curr_docker_version
+  retries: 4
+  until: not curr_docker_version | failed
   changed_when: false
 
 - name: Error out if Docker pre-installed but too old

+ 12 - 6
roles/lib_utils/library/repoquery.py

@@ -35,6 +35,7 @@ import os  # noqa: F401
 import re  # noqa: F401
 import shutil  # noqa: F401
 import tempfile  # noqa: F401
+import time  # noqa: F401
 
 try:
     import ruamel.yaml as yaml  # noqa: F401
@@ -618,17 +619,22 @@ def main():
             show_duplicates=dict(default=False, required=False, type='bool'),
             match_version=dict(default=None, required=False, type='str'),
             ignore_excluders=dict(default=False, required=False, type='bool'),
+            retries=dict(default=4, required=False, type='int'),
+            retry_interval=dict(default=5, required=False, type='int'),
         ),
         supports_check_mode=False,
         required_if=[('show_duplicates', True, ['name'])],
     )
 
-    rval = Repoquery.run_ansible(module.params, module.check_mode)
-
-    if 'failed' in rval:
-        module.fail_json(**rval)
-
-    module.exit_json(**rval)
+    tries = 1
+    while True:
+        rval = Repoquery.run_ansible(module.params, module.check_mode)
+        if 'failed' not in rval:
+            module.exit_json(**rval)
+        elif tries > module.params['retries']:
+            module.fail_json(**rval)
+        tries += 1
+        time.sleep(module.params['retry_interval'])
 
 
 if __name__ == "__main__":

+ 1 - 0
roles/lib_utils/library/yedit.py

@@ -35,6 +35,7 @@ import os  # noqa: F401
 import re  # noqa: F401
 import shutil  # noqa: F401
 import tempfile  # noqa: F401
+import time  # noqa: F401
 
 try:
     import ruamel.yaml as yaml  # noqa: F401

+ 11 - 6
roles/lib_utils/src/ansible/repoquery.py

@@ -19,17 +19,22 @@ def main():
             show_duplicates=dict(default=False, required=False, type='bool'),
             match_version=dict(default=None, required=False, type='str'),
             ignore_excluders=dict(default=False, required=False, type='bool'),
+            retries=dict(default=4, required=False, type='int'),
+            retry_interval=dict(default=5, required=False, type='int'),
         ),
         supports_check_mode=False,
         required_if=[('show_duplicates', True, ['name'])],
     )
 
-    rval = Repoquery.run_ansible(module.params, module.check_mode)
-
-    if 'failed' in rval:
-        module.fail_json(**rval)
-
-    module.exit_json(**rval)
+    tries = 1
+    while True:
+        rval = Repoquery.run_ansible(module.params, module.check_mode)
+        if 'failed' not in rval:
+            module.exit_json(**rval)
+        elif tries > module.params['retries']:
+            module.fail_json(**rval)
+        tries += 1
+        time.sleep(module.params['retry_interval'])
 
 
 if __name__ == "__main__":

+ 1 - 0
roles/lib_utils/src/lib/import.py

@@ -10,6 +10,7 @@ import os  # noqa: F401
 import re  # noqa: F401
 import shutil  # noqa: F401
 import tempfile  # noqa: F401
+import time  # noqa: F401
 
 try:
     import ruamel.yaml as yaml  # noqa: F401