From 8fcbe5bd6449e4b4242960396cfa8993c79c8c41 Mon Sep 17 00:00:00 2001 From: Madhuri Kumari Date: Thu, 23 Mar 2017 12:33:16 +0530 Subject: [PATCH] Fix issue in image-pull API Currently the image_pull API failed due to paramter mismatch for method pull_image. So this patch fixes the issue mentioned and also adds missing unit test cases for image_pull API. Change-Id: I7d29d06ac91866828bd1c7563863f74ee1d7856c Partially-Implements: blueprint refine-image-api --- zun/image/driver.py | 3 +- .../unit/compute/test_compute_manager.py | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/zun/image/driver.py b/zun/image/driver.py index 945d9f73e..8ec753b7b 100644 --- a/zun/image/driver.py +++ b/zun/image/driver.py @@ -58,7 +58,8 @@ def load_image_driver(image_driver=None): sys.exit(1) -def pull_image(context, repo, tag, image_pull_policy, image_driver): +def pull_image(context, repo, tag, image_pull_policy='always', + image_driver=None): if image_driver: image_driver_list = [image_driver.lower()] else: diff --git a/zun/tests/unit/compute/test_compute_manager.py b/zun/tests/unit/compute/test_compute_manager.py index 1ba034c44..a281ff548 100755 --- a/zun/tests/unit/compute/test_compute_manager.py +++ b/zun/tests/unit/compute/test_compute_manager.py @@ -20,6 +20,7 @@ from zun.compute import manager import zun.conf from zun.objects.container import Container from zun.objects import fields +from zun.objects.image import Image from zun.tests import base from zun.tests.unit.container.fake_driver import FakeDriver as fake_driver from zun.tests.unit.db import utils @@ -465,3 +466,33 @@ class TestManager(base.TestCase): self.assertRaises(exception.DockerError, self.compute_manager.container_resize, self.context, container, "100", "100") + + @mock.patch.object(fake_driver, 'inspect_image') + @mock.patch.object(Image, 'save') + @mock.patch('zun.image.driver.pull_image') + def test_image_pull(self, mock_pull, mock_save, mock_inspect): + image = Image(self.context, **utils.get_test_image()) + ret = {'image': 'repo', 'path': 'out_path', 'driver': 'glance'} + mock_pull.return_value = ret, True + mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512} + self.compute_manager._do_image_pull(self.context, image) + mock_pull.assert_any_call(self.context, image.repo, image.tag) + mock_save.assert_called_once() + mock_inspect.assert_called_once_with(image.repo + ":" + image.tag) + + @mock.patch.object(fake_driver, 'load_image') + @mock.patch.object(fake_driver, 'inspect_image') + @mock.patch.object(Image, 'save') + @mock.patch('zun.image.driver.pull_image') + def test_image_pull_not_loaded(self, mock_pull, mock_save, + mock_inspect, mock_load): + image = Image(self.context, **utils.get_test_image()) + repo_tag = image.repo + ":" + image.tag + ret = {'image': 'repo', 'path': 'out_path', 'driver': 'glance'} + mock_pull.return_value = ret, False + mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512} + self.compute_manager._do_image_pull(self.context, image) + mock_pull.assert_any_call(self.context, image.repo, image.tag) + mock_save.assert_called_once() + mock_inspect.assert_called_once_with(repo_tag) + mock_load.assert_called_once_with(repo_tag, ret['path'])