Fix handling of default_tag
The previous fix,589ac8ac0d
was not fully working as intended because during the templating of the container image prepare entry, the setting for default_tag was being lost. This fix simplifies the handling by just checking the initial mapping_args for the presence of a tag key to determine if the default_tag flag should be set. Change-Id: Idfebf62e0e10b709367cfcb6977cf18550a4a4b0 Partial-Bug: #1886547 Signed-off-by: James Slagle <jslagle@redhat.com> (cherry picked from commitb4275c7b40
)
This commit is contained in:
parent
6763dc0928
commit
59d58fe58a
|
@ -17,7 +17,6 @@ parameter_defaults:
|
||||||
name_prefix: openstack-
|
name_prefix: openstack-
|
||||||
name_suffix: ''
|
name_suffix: ''
|
||||||
tag: current-tripleo
|
tag: current-tripleo
|
||||||
default_tag: True
|
|
||||||
rhel_containers: false
|
rhel_containers: false
|
||||||
|
|
||||||
# Substitute neutron images based on driver. Can be 'other' or 'ovn'.
|
# Substitute neutron images based on driver. Can be 'other' or 'ovn'.
|
||||||
|
|
|
@ -886,7 +886,11 @@ class BaseImageUploader(object):
|
||||||
tags_r = RegistrySessionHelper.get(session, tags_url, timeout=30)
|
tags_r = RegistrySessionHelper.get(session, tags_url, timeout=30)
|
||||||
tags = tags_r.json()['tags']
|
tags = tags_r.json()['tags']
|
||||||
if default_tag and tag not in tags:
|
if default_tag and tag not in tags:
|
||||||
parts['tag'] = tags[-1]
|
if tags:
|
||||||
|
parts['tag'] = tags[-1]
|
||||||
|
else:
|
||||||
|
raise ImageNotFoundException('Not found image: %s' %
|
||||||
|
image_url.geturl())
|
||||||
|
|
||||||
manifest_url = cls._build_url(
|
manifest_url = cls._build_url(
|
||||||
image_url, CALL_MANIFEST % parts
|
image_url, CALL_MANIFEST % parts
|
||||||
|
|
|
@ -332,10 +332,11 @@ def container_images_prepare(template_file=DEFAULT_TEMPLATE_FILE,
|
||||||
)
|
)
|
||||||
uploader = manager.uploader('python')
|
uploader = manager.uploader('python')
|
||||||
images = [i.get('imagename', '') for i in result]
|
images = [i.get('imagename', '') for i in result]
|
||||||
if result:
|
# set a flag to record whether the default tag is used or not. the
|
||||||
default_tag = result[0].get('default_tag', False)
|
# logic here is that if the tag key is not already in mapping then it
|
||||||
else:
|
# wil be added during the template render, so default_tag is set to
|
||||||
default_tag = False
|
# True.
|
||||||
|
default_tag = 'tag' not in mapping_args
|
||||||
|
|
||||||
if tag_from_label:
|
if tag_from_label:
|
||||||
image_version_tags = uploader.discover_image_tags(
|
image_version_tags = uploader.discover_image_tags(
|
||||||
|
@ -453,11 +454,6 @@ class KollaImageBuilder(base.BaseImageManager):
|
||||||
hyphenated appropriately.
|
hyphenated appropriately.
|
||||||
'''
|
'''
|
||||||
mapping = dict(kwargs)
|
mapping = dict(kwargs)
|
||||||
# set a flag to record whether the default tag is used or not. the
|
|
||||||
# logic here is that if the tag key is not already in mapping then it
|
|
||||||
# wil be added during the template render, so default_tag is set to
|
|
||||||
# True.
|
|
||||||
mapping['default_tag'] = 'tag' not in mapping
|
|
||||||
|
|
||||||
if CONTAINER_IMAGES_DEFAULTS is None:
|
if CONTAINER_IMAGES_DEFAULTS is None:
|
||||||
return
|
return
|
||||||
|
|
|
@ -884,6 +884,86 @@ class TestBaseImageUploader(base.TestCase):
|
||||||
build(url1, '/t/nova-api/blobs/asdf1234')
|
build(url1, '/t/nova-api/blobs/asdf1234')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_inspect_default_tag(self):
|
||||||
|
req = self.requests
|
||||||
|
session = requests.Session()
|
||||||
|
session.headers['Authorization'] = 'Bearer asdf1234'
|
||||||
|
inspect = image_uploader.BaseImageUploader._inspect
|
||||||
|
|
||||||
|
url1 = urlparse('docker://docker.io/t/nova-api:latest')
|
||||||
|
|
||||||
|
manifest_resp = {
|
||||||
|
'schemaVersion': 2,
|
||||||
|
'config': {
|
||||||
|
'mediaType': 'text/html',
|
||||||
|
'digest': 'abcdef'
|
||||||
|
},
|
||||||
|
'layers': [
|
||||||
|
{'digest': 'aaa'},
|
||||||
|
{'digest': 'bbb'},
|
||||||
|
{'digest': 'ccc'},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
manifest_str = json.dumps(manifest_resp, indent=3)
|
||||||
|
manifest_headers = {'Docker-Content-Digest': 'eeeeee'}
|
||||||
|
tags_resp = {'tags': ['one', 'two']}
|
||||||
|
config_resp = {
|
||||||
|
'created': '2018-10-02T11:13:45.567533229Z',
|
||||||
|
'docker_version': '1.13.1',
|
||||||
|
'config': {
|
||||||
|
'Labels': {
|
||||||
|
'build-date': '20181002',
|
||||||
|
'build_id': '1538477701',
|
||||||
|
'kolla_version': '7.0.0'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'architecture': 'amd64',
|
||||||
|
'os': 'linux',
|
||||||
|
}
|
||||||
|
|
||||||
|
req.get('https://registry-1.docker.io/v2/t/nova-api/tags/list',
|
||||||
|
json=tags_resp)
|
||||||
|
req.get('https://registry-1.docker.io/v2/t/nova-api/blobs/abcdef',
|
||||||
|
json=config_resp)
|
||||||
|
req.get('https://registry-1.docker.io/v2/t/nova-api/manifests/two',
|
||||||
|
text=manifest_str, headers=manifest_headers)
|
||||||
|
|
||||||
|
# test default_tag=True
|
||||||
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'Architecture': 'amd64',
|
||||||
|
'Created': '2018-10-02T11:13:45.567533229Z',
|
||||||
|
'Digest': 'eeeeee',
|
||||||
|
'DockerVersion': '1.13.1',
|
||||||
|
'Labels': {
|
||||||
|
'build-date': '20181002',
|
||||||
|
'build_id': '1538477701',
|
||||||
|
'kolla_version': '7.0.0'
|
||||||
|
},
|
||||||
|
'Layers': ['aaa', 'bbb', 'ccc'],
|
||||||
|
'Name': 'docker.io/t/nova-api',
|
||||||
|
'Os': 'linux',
|
||||||
|
'RepoTags': ['one', 'two'],
|
||||||
|
'Tag': 'latest'
|
||||||
|
},
|
||||||
|
inspect(url1, session=session, default_tag=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
# test default_tag=False
|
||||||
|
req.get('https://registry-1.docker.io/v2/t/nova-api/manifests/latest',
|
||||||
|
status_code=404)
|
||||||
|
self.assertRaises(ImageNotFoundException, inspect, url1,
|
||||||
|
session=session,
|
||||||
|
default_tag=False)
|
||||||
|
|
||||||
|
# test default_tag=True, but no tags returned
|
||||||
|
tags_resp = {'tags': []}
|
||||||
|
req.get('https://registry-1.docker.io/v2/t/nova-api/tags/list',
|
||||||
|
json=tags_resp)
|
||||||
|
self.assertRaises(ImageNotFoundException, inspect, url1,
|
||||||
|
session=session,
|
||||||
|
default_tag=True)
|
||||||
|
|
||||||
def test_inspect(self):
|
def test_inspect(self):
|
||||||
req = self.requests
|
req = self.requests
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
|
@ -241,7 +241,6 @@ class TestKollaImageBuilderTemplate(base.TestCase):
|
||||||
'name_suffix': '',
|
'name_suffix': '',
|
||||||
'rhel_containers': False,
|
'rhel_containers': False,
|
||||||
'neutron_driver': 'ovn',
|
'neutron_driver': 'ovn',
|
||||||
'default_tag': True,
|
|
||||||
}
|
}
|
||||||
for key in (
|
for key in (
|
||||||
'namespace',
|
'namespace',
|
||||||
|
@ -278,7 +277,6 @@ class TestKollaImageBuilderTemplate(base.TestCase):
|
||||||
'ceph_tag': 'latest',
|
'ceph_tag': 'latest',
|
||||||
'name_prefix': 'prefix-',
|
'name_prefix': 'prefix-',
|
||||||
'name_suffix': '-suffix',
|
'name_suffix': '-suffix',
|
||||||
'default_tag': False,
|
|
||||||
'tag': 'master',
|
'tag': 'master',
|
||||||
'rhel_containers': False,
|
'rhel_containers': False,
|
||||||
'neutron_driver': 'ovn',
|
'neutron_driver': 'ovn',
|
||||||
|
@ -707,6 +705,36 @@ class TestPrepare(base.TestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@mock.patch.object(image_uploader, 'ImageUploadManager')
|
||||||
|
@mock.patch('tripleo_common.image.kolla_builder.'
|
||||||
|
'detect_insecure_registries', return_value={})
|
||||||
|
def test_prepare_default_tag(self, mock_insecure, mock_manager):
|
||||||
|
mock_manager_instance = mock.Mock()
|
||||||
|
mock_manager.return_value = mock_manager_instance
|
||||||
|
mock_uploader = mock.Mock()
|
||||||
|
mock_uploader.discover_image_tags.return_value = []
|
||||||
|
mock_manager_instance.uploader.return_value = mock_uploader
|
||||||
|
|
||||||
|
kb.container_images_prepare(
|
||||||
|
template_file=TEMPLATE_PATH,
|
||||||
|
output_env_file=constants.CONTAINER_DEFAULTS_ENVIRONMENT,
|
||||||
|
output_images_file='container_images.yaml',
|
||||||
|
mapping_args={},
|
||||||
|
tag_from_label="n-v",
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
mock_uploader.discover_image_tags.call_args_list[0][0][2])
|
||||||
|
|
||||||
|
kb.container_images_prepare(
|
||||||
|
template_file=TEMPLATE_PATH,
|
||||||
|
output_env_file=constants.CONTAINER_DEFAULTS_ENVIRONMENT,
|
||||||
|
output_images_file='container_images.yaml',
|
||||||
|
mapping_args={"tag": "master"},
|
||||||
|
tag_from_label="n-v",
|
||||||
|
)
|
||||||
|
self.assertFalse(
|
||||||
|
mock_uploader.discover_image_tags.call_args_list[1][0][2])
|
||||||
|
|
||||||
def test_get_enabled_services_empty(self):
|
def test_get_enabled_services_empty(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
set([]),
|
set([]),
|
||||||
|
|
Loading…
Reference in New Issue