From 9a1015581d59a7a38e1bdb2ff97da1161123e05c Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 7 Sep 2017 16:48:28 -0400 Subject: Add a docker pull retry to docker-puppet.py Co-Authored-By: Ian Main Change-Id: Iad6d38690340f4a064a4527c58ed439d91fa5188 Closes-bug: #1715136 (cherry picked from commit d3b3361a76c2e8b188fa8e586d9fb7f3c60bb66f) --- docker/docker-puppet.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'docker/docker-puppet.py') diff --git a/docker/docker-puppet.py b/docker/docker-puppet.py index 0451ed51..cc247031 100755 --- a/docker/docker-puppet.py +++ b/docker/docker-puppet.py @@ -26,6 +26,7 @@ import sys import subprocess import sys import tempfile +import time import multiprocessing logger = None @@ -59,10 +60,23 @@ def short_hostname(): def pull_image(name): log.info('Pulling image: %s' % name) - subproc = subprocess.Popen(['/usr/bin/docker', 'pull', name], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - cmd_stdout, cmd_stderr = subproc.communicate() + retval = -1 + count = 0 + while retval != 0: + count += 1 + subproc = subprocess.Popen(['/usr/bin/docker', 'pull', name], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + cmd_stdout, cmd_stderr = subproc.communicate() + retval = subproc.returncode + if retval != 0: + time.sleep(3) + log.warning('docker pull failed: %s' % cmd_stderr) + log.warning('retrying pulling image: %s' % name) + if count >= 5: + log.error('Failed to pull image: %s' % name) + break if cmd_stdout: log.debug(cmd_stdout) if cmd_stderr: -- cgit 1.2.3-korg