From ad80bfd0693f61df5bf46a4ba2dbb0a87d3fe6f9 Mon Sep 17 00:00:00 2001 From: Jianghua Wang Date: Thu, 1 Feb 2018 10:19:40 +0000 Subject: [PATCH] Remove the unsupported 'insecure_registry' for >=docker 3.0.0 The argument of 'insecure_registry' for image push has been removed by this commit (in docker 3.0.0): https://github.com/docker/docker-py/commit/b180b8770a265e33099bd6da76c3e556a1028491 Actually this argument was marked as deprecated and unfunctional before this removing. This commit is to remove this parameter at invoking the push() function when docker version >= 3.0.0. Change-Id: Ifa7d304d08a4073dcb1dff751d5a443c112cd377 Closes-Bug: #1746703 --- kolla/image/build.py | 13 ++++++++++--- kolla/tests/test_build.py | 13 ++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/kolla/image/build.py b/kolla/image/build.py index e1ecc33900..cfe802fedf 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -29,6 +29,7 @@ import tempfile import threading import time +from distutils.version import StrictVersion import docker import git import jinja2 @@ -328,9 +329,15 @@ class PushTask(DockerTask): self.success = False def push_image(self, image): - for response in self.dc.push(image.canonical_name, - stream=True, - insecure_registry=True): + kwargs = dict(stream=True) + + # Since docker 3.0.0, the argument of 'insecure_registry' is removed. + # To be compatible, set 'insecure_registry=True' for old releases. + dc_running_ver = StrictVersion(docker.version) + if dc_running_ver < StrictVersion('3.0.0'): + kwargs['insecure_registry'] = True + + for response in self.dc.push(image.canonical_name, **kwargs): stream = json.loads(response) if 'stream' in stream: self.logger.info(stream['stream']) diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index b7aa0c29e8..be2dce7e94 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -57,6 +57,17 @@ class TasksTest(base.TestCase): self.imageChild.parent = self.image self.imageChild.path = self.useFixture(fixtures.TempDir()).path + @mock.patch('docker.version', '2.7.0') + @mock.patch.dict(os.environ, clear=True) + @mock.patch('docker.APIClient') + def test_push_image_before_v3_0_0(self, mock_client): + self.dc = mock_client + pusher = build.PushTask(self.conf, self.image) + pusher.run() + mock_client().push.assert_called_once_with( + self.image.canonical_name, stream=True, insecure_registry=True) + + @mock.patch('docker.version', '3.0.0') @mock.patch.dict(os.environ, clear=True) @mock.patch('docker.APIClient') def test_push_image(self, mock_client): @@ -64,7 +75,7 @@ class TasksTest(base.TestCase): pusher = build.PushTask(self.conf, self.image) pusher.run() mock_client().push.assert_called_once_with( - self.image.canonical_name, stream=True, insecure_registry=True) + self.image.canonical_name, stream=True) @mock.patch.dict(os.environ, clear=True) @mock.patch('docker.APIClient')