Merge "make glance driver support tag 'latest'"
This commit is contained in:
commit
9e81c6aba8
@ -148,11 +148,14 @@ def allow_all_content_types(f):
|
|||||||
return _do_allow_certain_content_types(f, mimetypes.types_map.values())
|
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_parts = image.split(':', 1)
|
||||||
|
|
||||||
image_repo = image_parts[0]
|
image_repo = image_parts[0]
|
||||||
image_tag = 'latest'
|
if driver == 'glance':
|
||||||
|
image_tag = ''
|
||||||
|
else:
|
||||||
|
image_tag = 'latest'
|
||||||
|
|
||||||
if len(image_parts) > 1:
|
if len(image_parts) > 1:
|
||||||
image_tag = 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):
|
def get_image_pull_policy(image_pull_policy, image_tag):
|
||||||
if not image_pull_policy:
|
if not image_pull_policy:
|
||||||
if image_tag == 'latest':
|
if image_tag == 'latest' or not image_tag:
|
||||||
image_pull_policy = 'always'
|
image_pull_policy = 'always'
|
||||||
else:
|
else:
|
||||||
image_pull_policy = 'ifnotpresent'
|
image_pull_policy = 'ifnotpresent'
|
||||||
|
@ -251,10 +251,10 @@ class Manager(periodic_task.PeriodicTasks):
|
|||||||
requested_volumes, sandbox=None,
|
requested_volumes, sandbox=None,
|
||||||
limits=None):
|
limits=None):
|
||||||
self._update_task_state(context, container, consts.IMAGE_PULLING)
|
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(
|
image_pull_policy = utils.get_image_pull_policy(
|
||||||
container.image_pull_policy, tag)
|
container.image_pull_policy, tag)
|
||||||
image_driver_name = container.image_driver
|
|
||||||
try:
|
try:
|
||||||
image, image_loaded = image_driver.pull_image(
|
image, image_loaded = image_driver.pull_image(
|
||||||
context, repo, tag, image_pull_policy, image_driver_name)
|
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 = CONF.sandbox_image
|
||||||
sandbox_image_driver = CONF.sandbox_image_driver
|
sandbox_image_driver = CONF.sandbox_image_driver
|
||||||
sandbox_image_pull_policy = CONF.sandbox_image_pull_policy
|
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:
|
try:
|
||||||
image, image_loaded = image_driver.pull_image(
|
image, image_loaded = image_driver.pull_image(
|
||||||
context, repo, tag, sandbox_image_pull_policy,
|
context, repo, tag, sandbox_image_pull_policy,
|
||||||
@ -987,7 +988,7 @@ class Manager(periodic_task.PeriodicTasks):
|
|||||||
@translate_exception
|
@translate_exception
|
||||||
def image_search(self, context, image, image_driver_name, exact_match):
|
def image_search(self, context, image, image_driver_name, exact_match):
|
||||||
LOG.debug('Searching image...', image=image)
|
LOG.debug('Searching image...', image=image)
|
||||||
repo, tag = utils.parse_image_name(image)
|
repo, tag = utils.parse_image_name(image, image_driver_name)
|
||||||
try:
|
try:
|
||||||
return image_driver.search_image(context, repo, tag,
|
return image_driver.search_image(context, repo, tag,
|
||||||
image_driver_name, exact_match)
|
image_driver_name, exact_match)
|
||||||
|
@ -39,7 +39,7 @@ def find_image(context, image_ident, tag):
|
|||||||
LOG.debug('Found matches %s ', matches)
|
LOG.debug('Found matches %s ', matches)
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
raise exception.ImageNotFound(image=image_ident)
|
raise exception.ImageNotFound(image=image_ident)
|
||||||
if len(matches) > 1 and tag != 'latest':
|
if len(matches) > 1:
|
||||||
msg = ("Multiple images exist with same name "
|
msg = ("Multiple images exist with same name "
|
||||||
"%(image_ident)s. Please use the image id "
|
"%(image_ident)s. Please use the image id "
|
||||||
"instead.") % {'image_ident': image_ident}
|
"instead.") % {'image_ident': image_ident}
|
||||||
@ -62,7 +62,7 @@ def find_images(context, image_ident, tag, exact_match):
|
|||||||
kwargs = {}
|
kwargs = {}
|
||||||
kwargs['sort-dir'] = 'desc'
|
kwargs['sort-dir'] = 'desc'
|
||||||
kwargs['sort-key'] = 'updated_at'
|
kwargs['sort-key'] = 'updated_at'
|
||||||
if tag == 'latest':
|
if not tag:
|
||||||
filters = {'container_format': 'docker'}
|
filters = {'container_format': 'docker'}
|
||||||
else:
|
else:
|
||||||
filters = {'container_format': 'docker', 'tag': [tag]}
|
filters = {'container_format': 'docker', 'tag': [tag]}
|
||||||
|
@ -187,7 +187,7 @@ class TestManager(base.TestCase):
|
|||||||
self.compute_manager._do_container_create(self.context, container,
|
self.compute_manager._do_container_create(self.context, container,
|
||||||
networks, volumes)
|
networks, volumes)
|
||||||
mock_save.assert_called_with(self.context)
|
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')
|
'always', 'glance')
|
||||||
mock_create.assert_called_once_with(self.context, container, image,
|
mock_create.assert_called_once_with(self.context, container, image,
|
||||||
networks, volumes)
|
networks, volumes)
|
||||||
@ -339,7 +339,7 @@ class TestManager(base.TestCase):
|
|||||||
container=container,
|
container=container,
|
||||||
limits=None, run=True)
|
limits=None, run=True)
|
||||||
mock_save.assert_called_with(self.context)
|
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')
|
'always', 'glance')
|
||||||
mock_create.assert_called_once_with(self.context, container, image,
|
mock_create.assert_called_once_with(self.context, container, image,
|
||||||
networks, volumes)
|
networks, volumes)
|
||||||
@ -560,7 +560,7 @@ class TestManager(base.TestCase):
|
|||||||
mock_save.assert_called_with(self.context)
|
mock_save.assert_called_with(self.context)
|
||||||
self.assertEqual('Error', container.status)
|
self.assertEqual('Error', container.status)
|
||||||
self.assertEqual('Docker Error occurred', container.status_reason)
|
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')
|
'always', 'glance')
|
||||||
mock_create.assert_called_once_with(
|
mock_create.assert_called_once_with(
|
||||||
self.context, container, image, networks, volumes)
|
self.context, container, image, networks, volumes)
|
||||||
|
Loading…
Reference in New Issue
Block a user