Stop doing tag_from_label lookup with tag

When using specifying ContainerImagePrepare if a tag is explicitly
provided in a set, the tag_from_label functionality will not be run as
we use the defined tag for the containers. Previously we would still
attempt tag lookups even if we wanted a specific tag.

This would also cause failures during the deployment if using a
namespace that didn't have the defined tag_from_label format but we
defined a specific tag we wanted to use. e.g. using a tag with a md5 vs
a tag_from_label with numbers in it.

Change-Id: I4966641aed1a21be60d915ea58dda78b80fe0e1f
Partial-Bug: #1889122
This commit is contained in:
Alex Schultz 2020-08-05 08:42:17 -06:00
parent 5602dfd986
commit 014d985f08
3 changed files with 131 additions and 3 deletions

View File

@ -0,0 +1,7 @@
---
fixes:
- |
When using specifying ContainerImagePrepare if a tag is explicitly provided
in a set, the tag_from_label functionality will not be run as we use
the defined tag for the containers. Previously we would still attempt
tag lookups even if we wanted a specific tag.

View File

@ -190,6 +190,12 @@ def container_images_prepare_multi(environment, roles_data, dry_run=False,
modify_append_tag = cip_entry.get('modify_append_tag', modify_append_tag = cip_entry.get('modify_append_tag',
time.strftime( time.strftime(
'-modified-%Y%m%d%H%M%S')) '-modified-%Y%m%d%H%M%S'))
# do not use tag_from_label if a tag is specified in the set
tag_from_label = None
if not mapping_args.get('tag'):
tag_from_label = cip_entry.get('tag_from_label')
if multi_arch and 'multi_arch' in cip_entry: if multi_arch and 'multi_arch' in cip_entry:
# individual entry sets multi_arch, # individual entry sets multi_arch,
# so set global multi_arch to False # so set global multi_arch to False
@ -204,7 +210,7 @@ def container_images_prepare_multi(environment, roles_data, dry_run=False,
mapping_args=mapping_args, mapping_args=mapping_args,
output_env_file='image_params', output_env_file='image_params',
output_images_file='upload_data', output_images_file='upload_data',
tag_from_label=cip_entry.get('tag_from_label'), tag_from_label=tag_from_label,
append_tag=modify_append_tag, append_tag=modify_append_tag,
modify_role=modify_role, modify_role=modify_role,
modify_vars=modify_vars, modify_vars=modify_vars,

View File

@ -842,7 +842,6 @@ class TestPrepare(base.TestCase):
'namespace': 't', 'namespace': 't',
'name_prefix': '', 'name_prefix': '',
'name_suffix': '', 'name_suffix': '',
'tag': 'l',
} }
env = { env = {
'parameter_defaults': { 'parameter_defaults': {
@ -964,7 +963,6 @@ class TestPrepare(base.TestCase):
'namespace': 't', 'namespace': 't',
'name_prefix': '', 'name_prefix': '',
'name_suffix': '', 'name_suffix': '',
'tag': 'l',
} }
env = { env = {
'parameter_defaults': { 'parameter_defaults': {
@ -1066,6 +1064,123 @@ class TestPrepare(base.TestCase):
image_params image_params
) )
@mock.patch('tripleo_common.image.kolla_builder.container_images_prepare')
@mock.patch('tripleo_common.image.image_uploader.ImageUploadManager',
autospec=True)
def test_container_images_prepare_multi_tag_from_label(self, mock_im,
mock_cip):
mock_lock = mock.MagicMock()
mapping_args = {
'namespace': 't',
'name_prefix': '',
'name_suffix': '',
'tag': 'l',
}
mapping_args_no_tag = {
'namespace': 't',
'name_prefix': '',
'name_suffix': '',
}
env = {
'parameter_defaults': {
'ContainerImagePrepare': [{
'set': mapping_args_no_tag,
'tag_from_label': 'foo',
}, {
'set': mapping_args,
'tag_from_label': 'bar',
'excludes': ['nova', 'neutron'],
'push_destination': '192.0.2.1:8787',
'modify_role': 'add-foo-plugin',
'modify_only_with_labels': ['kolla_version'],
'modify_vars': {'foo_version': '1.0.1'},
'modify_append_tag': 'modify-123'
}]
}
}
roles_data = []
mock_cip.side_effect = [
{
'image_params': {
'FooImage': 't/foo:latest',
'BarImage': 't/bar:latest',
'BazImage': 't/baz:latest',
'BinkImage': 't/bink:latest'
},
'upload_data': []
}, {
'image_params': {
'BarImage': 't/bar:1.0',
'BazImage': 't/baz:1.0'
},
'upload_data': [{
'imagename': 't/bar:1.0',
'push_destination': '192.0.2.1:8787'
}, {
'imagename': 't/baz:1.0',
'push_destination': '192.0.2.1:8787'
}]
},
]
image_params = kb.container_images_prepare_multi(env, roles_data, True,
lock=mock_lock)
mock_cip.assert_has_calls([
mock.call(
excludes=None,
includes=None,
mapping_args=mapping_args_no_tag,
output_env_file='image_params',
output_images_file='upload_data',
pull_source=None,
push_destination=None,
service_filter=None,
tag_from_label='foo',
append_tag=mock.ANY,
modify_role=None,
modify_only_with_labels=None,
modify_vars=None,
mirrors={},
registry_credentials=None,
multi_arch=False,
lock=mock_lock
),
mock.call(
excludes=['nova', 'neutron'],
includes=None,
mapping_args=mapping_args,
output_env_file='image_params',
output_images_file='upload_data',
pull_source=None,
push_destination='192.0.2.1:8787',
service_filter=None,
tag_from_label=None,
append_tag=mock.ANY,
modify_role='add-foo-plugin',
modify_only_with_labels=['kolla_version'],
modify_vars={'foo_version': '1.0.1'},
mirrors={},
registry_credentials=None,
multi_arch=False,
lock=mock_lock
)
])
mock_im.assert_called_once_with(mock.ANY, dry_run=True, cleanup='full',
mirrors={}, registry_credentials=None,
multi_arch=False, lock=mock_lock)
self.assertEqual(
{
'BarImage': 't/bar:1.0',
'BazImage': 't/baz:1.0',
'BinkImage': 't/bink:latest',
'FooImage': 't/foo:latest'
},
image_params
)
def test_set_neutron_driver(self): def test_set_neutron_driver(self):
mapping_args = {} mapping_args = {}
kb.set_neutron_driver(None, mapping_args) kb.set_neutron_driver(None, mapping_args)