make "zun pull" support Glance uuid
Current progress of "zun pull" does not support image uuid of glance. The bp is to make "zun pull" support uuid. We can use it like this: zun pull glance_image_uuid host When use uuid to pull image from glance, some rules should be noted: 1.The name of glance image should be repo. Because it is required when "inspect_image" is called. 2.It is better if the glance image has tag. If not, the progress will use "latest" as tag to call inspect_image. And we can use "glance image-tag-update uuid tag" to set tag for glance image. Partial-Implements: blueprint make-zun-pull-support-uuid Change-Id: I5daf45d2a7e49887b333ec78f04f4fef7dbb5eb6
This commit is contained in:
parent
285ce733ab
commit
04f3b9cbe0
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue