Fix the docker may return a empty dict when pull images

Closes-Bug: #1530649
Change-Id: I74191c711d1e5c27d33011be4d5528fe08c14273
This commit is contained in:
Jeffrey Zhang 2016-01-03 21:38:08 +08:00
parent b32df7300c
commit 7fe22629ab

View File

@ -211,28 +211,32 @@ 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
self.changed = True # registries and when that happens we can remove this.
elif "Image is up to date for" in status[search].get('status'): if 'legacy registry' in status.get('status'):
# No new layer was pulled, no change continue
pass elif "Downloaded newer image for" in status.get('status'):
else: self.changed = True
self.module.fail_json( return
msg="Invalid status returned from pull", elif "Image is up to date for" in status.get('status'):
changed=True, return
failed=True else:
) self.module.fail_json(
msg="Invalid status returned from pull",
changed=True,
failed=True
)
def remove_container(self): def remove_container(self):
if self.check_container(): if self.check_container():