From ae34973d350433ea22d7f0467100193832e6de0f Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Mon, 1 Aug 2016 13:35:25 +0800 Subject: [PATCH] Fix the kolla_docker issue with docker 1.12 After docker 1.12, the RepoTags will be None rather than [] in the image list API. This PS will handle the both case. Change-Id: Ie2da44b44229c2f190550755b50876f607f9cc0c Closes-Bug: #1608358 --- ansible/library/kolla_docker.py | 5 ++++- tests/test_kolla_docker.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py index dc542aece4..8a079e0f29 100644 --- a/ansible/library/kolla_docker.py +++ b/ansible/library/kolla_docker.py @@ -242,7 +242,10 @@ class DockerWorker(object): def check_image(self): find_image = ':'.join(self.parse_image()) for image in self.dc.images(): - for image_name in image['RepoTags']: + repo_tags = image.get('RepoTags') + if not repo_tags: + continue + for image_name in repo_tags: if image_name == find_image: return image diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py index a05d91edb2..f62bb603a6 100644 --- a/tests/test_kolla_docker.py +++ b/tests/test_kolla_docker.py @@ -388,6 +388,28 @@ class TestImage(base.BaseTestCase): self.dw.dc.images.assert_called_once_with() self.assertEqual(self.fake_data['images'][0], return_data) + def test_check_image_before_docker_1_12(self): + self.dw = get_DockerWorker( + {'image': 'myregistrydomain.com:5000/centos:7.0'}) + self.fake_data['images'][0]['RepoTags'] = [] + self.dw.dc.images.return_value = self.fake_data['images'] + + return_data = self.dw.check_image() + self.assertFalse(self.dw.changed) + self.dw.dc.images.assert_called_once_with() + self.assertEqual(self.fake_data['images'][1], return_data) + + def test_check_image_docker_1_12(self): + self.dw = get_DockerWorker( + {'image': 'myregistrydomain.com:5000/centos:7.0'}) + self.fake_data['images'][0]['RepoTags'] = None + self.dw.dc.images.return_value = self.fake_data['images'] + + return_data = self.dw.check_image() + self.assertFalse(self.dw.changed) + self.dw.dc.images.assert_called_once_with() + self.assertEqual(self.fake_data['images'][1], return_data) + def test_compare_image(self): self.dw = get_DockerWorker( {'image': 'myregistrydomain.com:5000/ubuntu:16.04'})