diff --git a/docker/docker-puppet.py b/docker/docker-puppet.py index 26b59d1908..55ab9b9f9a 100755 --- a/docker/docker-puppet.py +++ b/docker/docker-puppet.py @@ -25,6 +25,7 @@ import os 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: