diff options
| -rwxr-xr-x | kolla/image/build.py | 13 | ||||
| -rw-r--r-- | 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 e1ecc3390..cfe802fed 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 b7aa0c29e..be2dce7e9 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -57,15 +57,26 @@ 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(self, mock_client): + 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): + 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) + @mock.patch.dict(os.environ, clear=True) @mock.patch('docker.APIClient') def test_build_image(self, mock_client): |
