Merge "make glance driver support tag 'latest'"

This commit is contained in:
Zuul 2018-03-26 02:05:47 +00:00 committed by Gerrit Code Review
commit 9e81c6aba8
4 changed files with 16 additions and 12 deletions

View File

@ -148,11 +148,14 @@ def allow_all_content_types(f):
return _do_allow_certain_content_types(f, mimetypes.types_map.values())
def parse_image_name(image):
def parse_image_name(image, driver=None):
image_parts = image.split(':', 1)
image_repo = image_parts[0]
image_tag = 'latest'
if driver == 'glance':
image_tag = ''
else:
image_tag = 'latest'
if len(image_parts) > 1:
image_tag = image_parts[1]
@ -221,7 +224,7 @@ def check_container_id(function):
def get_image_pull_policy(image_pull_policy, image_tag):
if not image_pull_policy:
if image_tag == 'latest':
if image_tag == 'latest' or not image_tag:
image_pull_policy = 'always'
else:
image_pull_policy = 'ifnotpresent'

View File

@ -251,10 +251,10 @@ class Manager(periodic_task.PeriodicTasks):
requested_volumes, sandbox=None,
limits=None):
self._update_task_state(context, container, consts.IMAGE_PULLING)
repo, tag = utils.parse_image_name(container.image)
image_driver_name = container.image_driver
repo, tag = utils.parse_image_name(container.image, image_driver_name)
image_pull_policy = utils.get_image_pull_policy(
container.image_pull_policy, tag)
image_driver_name = container.image_driver
try:
image, image_loaded = image_driver.pull_image(
context, repo, tag, image_pull_policy, image_driver_name)
@ -398,7 +398,8 @@ class Manager(periodic_task.PeriodicTasks):
sandbox_image = CONF.sandbox_image
sandbox_image_driver = CONF.sandbox_image_driver
sandbox_image_pull_policy = CONF.sandbox_image_pull_policy
repo, tag = utils.parse_image_name(sandbox_image)
repo, tag = utils.parse_image_name(sandbox_image,
sandbox_image_driver)
try:
image, image_loaded = image_driver.pull_image(
context, repo, tag, sandbox_image_pull_policy,
@ -987,7 +988,7 @@ class Manager(periodic_task.PeriodicTasks):
@translate_exception
def image_search(self, context, image, image_driver_name, exact_match):
LOG.debug('Searching image...', image=image)
repo, tag = utils.parse_image_name(image)
repo, tag = utils.parse_image_name(image, image_driver_name)
try:
return image_driver.search_image(context, repo, tag,
image_driver_name, exact_match)

View File

@ -39,7 +39,7 @@ def find_image(context, image_ident, tag):
LOG.debug('Found matches %s ', matches)
if len(matches) == 0:
raise exception.ImageNotFound(image=image_ident)
if len(matches) > 1 and tag != 'latest':
if len(matches) > 1:
msg = ("Multiple images exist with same name "
"%(image_ident)s. Please use the image id "
"instead.") % {'image_ident': image_ident}
@ -62,7 +62,7 @@ def find_images(context, image_ident, tag, exact_match):
kwargs = {}
kwargs['sort-dir'] = 'desc'
kwargs['sort-key'] = 'updated_at'
if tag == 'latest':
if not tag:
filters = {'container_format': 'docker'}
else:
filters = {'container_format': 'docker', 'tag': [tag]}

View File

@ -187,7 +187,7 @@ class TestManager(base.TestCase):
self.compute_manager._do_container_create(self.context, container,
networks, volumes)
mock_save.assert_called_with(self.context)
mock_pull.assert_any_call(self.context, container.image, 'latest',
mock_pull.assert_any_call(self.context, container.image, '',
'always', 'glance')
mock_create.assert_called_once_with(self.context, container, image,
networks, volumes)
@ -339,7 +339,7 @@ class TestManager(base.TestCase):
container=container,
limits=None, run=True)
mock_save.assert_called_with(self.context)
mock_pull.assert_any_call(self.context, container.image, 'latest',
mock_pull.assert_any_call(self.context, container.image, '',
'always', 'glance')
mock_create.assert_called_once_with(self.context, container, image,
networks, volumes)
@ -560,7 +560,7 @@ class TestManager(base.TestCase):
mock_save.assert_called_with(self.context)
self.assertEqual('Error', container.status)
self.assertEqual('Docker Error occurred', container.status_reason)
mock_pull.assert_any_call(self.context, container.image, 'latest',
mock_pull.assert_any_call(self.context, container.image, '',
'always', 'glance')
mock_create.assert_called_once_with(
self.context, container, image, networks, volumes)