From 17ec0f62f40fff55bf42af4b2fa8afd599979132 Mon Sep 17 00:00:00 2001 From: Paul Bourke Date: Fri, 25 Nov 2016 10:49:28 +0000 Subject: [PATCH] Fix python3 compatibility in kolla_docker When using stream=True with docker-py it returns byte arrays rather than strings. Change-Id: I8eb6707ba2b122cf779135173abafe874b7223d2 Closes-Bug: #1643740 --- ansible/library/kolla_docker.py | 2 +- tests/test_kolla_docker.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py index 28f752a2e7..b124af959d 100644 --- a/ansible/library/kolla_docker.py +++ b/ansible/library/kolla_docker.py @@ -426,7 +426,7 @@ class DockerWorker(object): image, tag = self.parse_image() statuses = [ - json.loads(line.strip()) for line in self.dc.pull( + json.loads(line.strip().decode('utf-8')) for line in self.dc.pull( repository=image, tag=tag, stream=True ) ] diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py index efcf16c0d1..2bcb781185 100644 --- a/tests/test_kolla_docker.py +++ b/tests/test_kolla_docker.py @@ -433,9 +433,9 @@ class TestImage(base.BaseTestCase): 'auth_email': 'fake_mail@foogle.com' }) self.dw.dc.pull.return_value = [ - '{"status":"Pull complete","progressDetail":{},"id":"22f7"}\r\n', - '{"status":"Digest: sha256:47c3bdbcf99f0c1a36e4db"}\r\n', - '{"status":"Downloaded newer image for ubuntu:16.04"}\r\n' + b'{"status":"Pull complete","progressDetail":{},"id":"22f7"}\r\n', + b'{"status":"Digest: sha256:47c3bdbcf99f0c1a36e4db"}\r\n', + b'{"status":"Downloaded newer image for ubuntu:16.04"}\r\n' ] self.dw.pull_image() @@ -449,9 +449,9 @@ class TestImage(base.BaseTestCase): self.dw = get_DockerWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04'}) self.dw.dc.pull.return_value = [ - '{"status":"Pull complete","progressDetail":{},"id":"22f7"}\r\n', - '{"status":"Digest: sha256:47c3bdbf0c1a36e4db"}\r\n', - '{"status":"mage is up to date for ubuntu:16.04"}\r\n' + b'{"status":"Pull complete","progressDetail":{},"id":"22f7"}\r\n', + b'{"status":"Digest: sha256:47c3bdbf0c1a36e4db"}\r\n', + b'{"status":"mage is up to date for ubuntu:16.04"}\r\n' ] self.dw.pull_image() @@ -465,7 +465,7 @@ class TestImage(base.BaseTestCase): self.dw = get_DockerWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04'}) self.dw.dc.pull.return_value = [ - '{"status": "some random message"}\r\n'] + b'{"status": "some random message"}\r\n'] self.dw.pull_image() self.dw.dc.pull.assert_called_once_with( @@ -481,7 +481,7 @@ class TestImage(base.BaseTestCase): self.dw = get_DockerWorker( {'image': 'unknown:16.04'}) self.dw.dc.pull.return_value = [ - '{"error": "image unknown not found"}\r\n'] + b'{"error": "image unknown not found"}\r\n'] self.dw.pull_image() self.dw.dc.pull.assert_called_once_with( @@ -497,7 +497,7 @@ class TestImage(base.BaseTestCase): self.dw = get_DockerWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04'}) self.dw.dc.pull.return_value = [ - '{"error": "unexpected error"}\r\n'] + b'{"error": "unexpected error"}\r\n'] self.dw.pull_image() self.dw.dc.pull.assert_called_once_with(