summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Williamson <awilliam@redhat.com>2015-10-13 22:33:46 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2015-10-14 07:31:48 -0700
commitb5419a026796c56df32dbd72569690c60321885b (patch)
tree5eb6fbb80be57fdb5fe05cdd3adeee1dcb5e2c8a
parent0d4d5e044d750c0fe762f01abdf2b31d32dba1d2 (diff)
downloadansible-modules-core-b5419a026796c56df32dbd72569690c60321885b.tar.gz
fix #2043: strip empty dict from end of 'pull' stream
When pulling an image using Docker 1.8, it seems the output JSON stream has an empty dict at the very end. This causes ansible to fail when pulling an image, as it's expecting a status message in that dict which it uses to determine whether it had to download the image or not. As a bit of an ugly hack for that which remains backward compatible, try the last item in the stream, and if it's an empty dict, take the last-but-one item instead. The strip() is needed as the exact value appears to be '{}/r/n'; we could just match that, but it seems like the kind of thing where maybe it'd happen to just be '{}/n' or '{}' or something in some cases, so let's just use strip() in case.
-rw-r--r--cloud/docker/docker.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
index ab9f13f5..f299454f 100644
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -1237,6 +1237,11 @@ class DockerManager(object):
changes = list(self.client.pull(image, tag=tag, stream=True, **extra_params))
try:
last = changes[-1]
+ # seems Docker 1.8 puts an empty dict at the end of the
+ # stream; catch that and get the previous instead
+ # https://github.com/ansible/ansible-modules-core/issues/2043
+ if last.strip() == '{}':
+ last = changes[-2]
except IndexError:
last = '{}'
status = json.loads(last).get('status', '')