Merge "Fix the docker may return a empty dict when pull images"

This commit is contained in:
Jenkins 2016-01-04 12:30:43 +00:00 committed by Gerrit Code Review
commit e355132bfc

View File

@ -211,22 +211,26 @@ class DockerWorker(object):
image, tag = self.parse_image() image, tag = self.parse_image()
status = [ statuses = [
json.loads(line.strip()) for line in self.dc.pull( json.loads(line.strip()) for line in self.dc.pull(
repository=image, tag=tag, stream=True repository=image, tag=tag, stream=True
) )
] ]
# NOTE(SamYaple): This allows us to use v1 and v2 docker registries. for status in reversed(statuses):
# Eventually docker will stop supporting v1 registries and when # NOTE(jeffrey4l): Get the last not empty status with status
# that happens we can remove this. # property
search = -2 if 'legacy registry' in status[-1].get('status') else -1 if status and status.get('status'):
# NOTE(SamYaple): This allows us to use v1 and v2 docker
if "Downloaded newer image for" in status[search].get('status'): # registries. Eventually docker will stop supporting v1
# registries and when that happens we can remove this.
if 'legacy registry' in status.get('status'):
continue
elif "Downloaded newer image for" in status.get('status'):
self.changed = True self.changed = True
elif "Image is up to date for" in status[search].get('status'): return
# No new layer was pulled, no change elif "Image is up to date for" in status.get('status'):
pass return
else: else:
self.module.fail_json( self.module.fail_json(
msg="Invalid status returned from pull", msg="Invalid status returned from pull",