diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 4d5f506d1..e3c0c1c67 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -1017,15 +1017,33 @@ class Manager(periodic_task.PeriodicTasks): def _do_image_pull(self, context, image): LOG.debug('Creating image...') + image_driver_name = CONF.default_image_driver repo_tag = image.repo if image.tag: repo_tag += ":" + image.tag + if uuidutils.is_uuid_like(image.repo): + image.tag = '' + image_driver_name = 'glance' try: pulled_image, image_loaded = self.driver.pull_image( - context, image.repo, image.tag) + context, image.repo, image.tag, driver_name=image_driver_name) if not image_loaded: self.driver.load_image(pulled_image['path']) + + if pulled_image['driver'] == 'glance': + self.driver.read_tar_image(pulled_image) + if pulled_image['tag'] not in pulled_image['tags']: + LOG.warning("The glance image tag %(glance_tag)s is " + "different from %(tar_tag) the tag in tar", + {'glance_tag': pulled_image['tags'], + 'tar_tag': pulled_image['tag']}) + repo_tag = ':'.join([pulled_image['repo'], pulled_image['tag']]) \ + if pulled_image['tag'] else pulled_image['repo'] image_dict = self.driver.inspect_image(repo_tag) + + image_parts = image_dict['RepoTags'][0].split(":", 1) + image.repo = image_parts[0] + image.tag = image_parts[1] image.image_id = image_dict['Id'] image.size = image_dict['Size'] image.save() diff --git a/zun/image/glance/driver.py b/zun/image/glance/driver.py index fe3c5cde0..703114468 100644 --- a/zun/image/glance/driver.py +++ b/zun/image/glance/driver.py @@ -109,7 +109,9 @@ class GlanceDriver(driver.ContainerImageDriver): raise exception.ZunException(msg.format(e)) LOG.debug('Image %(repo)s was downloaded to path : %(path)s', {'repo': repo, 'path': out_path}) - return {'image': repo, 'path': out_path}, image_loaded + image = {'image': image_meta.name, 'tags': image_meta.tags, + 'path': out_path} + return image, image_loaded def search_image(self, context, repo, tag, exact_match): LOG.debug('Searching image in glance %s', repo) diff --git a/zun/tests/unit/compute/test_compute_manager.py b/zun/tests/unit/compute/test_compute_manager.py index e34892d76..b1dc42694 100644 --- a/zun/tests/unit/compute/test_compute_manager.py +++ b/zun/tests/unit/compute/test_compute_manager.py @@ -1134,11 +1134,13 @@ class TestManager(base.TestCase): @mock.patch.object(fake_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'} + ret = {'image': 'repo', 'path': 'out_path', 'driver': 'docker'} mock_pull.return_value = ret, True - mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512} + mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512, + 'RepoTags': ['image1:latest']} self.compute_manager._do_image_pull(self.context, image) - mock_pull.assert_any_call(self.context, image.repo, image.tag) + mock_pull.assert_any_call(self.context, image.repo, image.tag, + driver_name='docker') mock_save.assert_called_once() mock_inspect.assert_called_once_with(image.repo + ":" + image.tag) @@ -1150,11 +1152,14 @@ class TestManager(base.TestCase): 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'} + ret = {'image': 'repo', 'path': 'out_path', 'driver': 'docker', + 'tags': ['latest']} mock_pull.return_value = ret, False - mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512} + mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512, + 'RepoTags': ['image1:latest']} self.compute_manager._do_image_pull(self.context, image) - mock_pull.assert_any_call(self.context, image.repo, image.tag) + mock_pull.assert_any_call(self.context, image.repo, image.tag, + driver_name='docker') mock_save.assert_called_once() mock_inspect.assert_called_once_with(repo_tag) mock_load.assert_called_once_with(ret['path']) @@ -1164,11 +1169,13 @@ class TestManager(base.TestCase): @mock.patch.object(fake_driver, 'pull_image') def test_image_pull_tag_is_none(self, mock_pull, mock_save, mock_inspect): image = Image(self.context, **utils.get_test_image(tag=None)) - ret = {'image': 'repo', 'path': 'out_path', 'driver': 'glance'} + ret = {'image': 'repo', 'path': 'out_path', 'driver': 'docker'} mock_pull.return_value = ret, True - mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512} + mock_inspect.return_value = {'Id': 'fake-id', 'Size': 512, + 'RepoTags': ['image1:latest']} self.compute_manager._do_image_pull(self.context, image) - mock_pull.assert_any_call(self.context, image.repo, image.tag) + mock_pull.assert_any_call(self.context, image.repo, None, + driver_name='docker') mock_save.assert_called_once() mock_inspect.assert_called_once_with(image.repo) diff --git a/zun/tests/unit/image/glance/test_driver.py b/zun/tests/unit/image/glance/test_driver.py index b213842aa..6a1a32966 100644 --- a/zun/tests/unit/image/glance/test_driver.py +++ b/zun/tests/unit/image/glance/test_driver.py @@ -89,6 +89,8 @@ class TestDriver(base.BaseTestCase): 'checksum': 'xxx'} image_meta = mock.MagicMock() image_meta.id = '1234' + image_meta.name = 'image' + image_meta.tags = ['latest'] mock_find_image.return_value = image_meta mock_download_image.return_value = 'content' CONF.set_override('images_directory', self.test_dir, group='glance') @@ -101,7 +103,8 @@ class TestDriver(base.BaseTestCase): self.assertTrue(mock_should_pull_image.called) self.assertTrue(mock_find_image.called) self.assertTrue(mock_download_image.called) - self.assertEqual(({'image': 'image', 'path': out_path}, False), ret) + self.assertEqual(({'image': 'image', 'path': out_path, + 'tags': ['latest']}, False), ret) @mock.patch('zun.common.utils.should_pull_image') def test_pull_image_not_found(self, mock_should_pull_image):