Allow override for install and target hash in emit releases undercloud

As described in related-bug, this allows us to override the install
and target delorean hash for use by consumer jobs. There was a previous
attempt with [1] which added the ability to override the target hash.

As commented in the bug (see comment #7) we need to override both target
and install versions. Since this is nested bash/jinja/python :/ we do this
by passing the content provider branches as a string
"branch1:hash1;branch2:hash2" generated in the jinja templating
which is then decoded on the emit-releases python side.

[1] https://review.opendev.org/c/openstack/tripleo-ci/+/813629
Co-Authored-By: Marios Andreou <marios@redhat.com>
Related-Bug: 1946659

Change-Id: I9e0162f88cf262957234bf946ad3c013f6213891
This commit is contained in:
Arx Cruz 2021-11-08 12:17:04 +01:00 committed by Marios Andreou
parent 90d05731e3
commit 4a6b1f0bcf
2 changed files with 80 additions and 18 deletions

View File

@ -99,6 +99,9 @@ elif is_featureset mixed_upgrade "{{ job_featureset_file }}"; then
elif is_featureset undercloud_upgrade "{{ job_featureset_file }}"; then
export UPGRADE_RELEASE=$QUICKSTART_RELEASE
export QUICKSTART_RELEASE=$(previous_release_mixed_upgrade_case "${UPGRADE_RELEASE}")
{% if provider_dlrn_hash_tag_branch is defined %}
EMIT_RELEASES_EXTRA_ARGS="$EMIT_RELEASES_EXTRA_ARGS --content-provider-hashes={{ provider_dlrn_hash_tag_branch.keys()|zip(provider_dlrn_hash_tag_branch.values())|map('join',':')|join(';') }} --target-branch-override=$UPGRADE_RELEASE --install-branch-override=$QUICKSTART_RELEASE"
{% endif %}
fi
# Set UPGRADE_RELEASE if applicable
if [ -n "${MIXED_UPGRADE_TYPE}" ]; then
@ -111,11 +114,6 @@ PERIODIC=1
QUICKSTART_RELEASE="promotion-testing-hash-${QUICKSTART_RELEASE}"
EMIT_RELEASES_EXTRA_ARGS="$EMIT_RELEASES_EXTRA_ARGS --is-periodic"
{% endif %}
{% if job is defined %}
{% if job.provider_dlrn_hash_tag_branch[release] | default(omit) %}
EMIT_RELEASES_EXTRA_ARGS="$EMIT_RELEASES_EXTRA_ARGS --hash-override={{ job.provider_dlrn_hash_tag_branch[release] }}"
{% endif %}
{% endif %}
if [[ -f "$RELEASES_SCRIPT" ]] && [[ {{ featureset }} =~ 037|047|050|056 ]]; then

View File

@ -171,7 +171,9 @@ def compose_releases_dictionary(
is_periodic=False,
distro_name='centos',
distro_version='7',
hash_override=None,
target_branch_override=None,
install_branch_override=None,
content_provider_hashes=None,
):
"""Compose the release dictionary for stable_release and featureset
@ -249,13 +251,19 @@ def compose_releases_dictionary(
current_hash = get_dlrn_hash(
stable_release, PROMOTION_HASH_NAME, distro_name, distro_version
)
else:
if hash_override:
current_hash = hash_override
else:
current_hash = get_dlrn_hash(
stable_release, CURRENT_HASH_NAME, distro_name, distro_version
elif content_provider_hashes is not None and content_provider_hashes.get(
target_branch_override
):
current_hash = content_provider_hashes[target_branch_override]
logger.info(
"Using hash override {} for branch {}".format(
current_hash, target_branch_override
)
)
else:
current_hash = get_dlrn_hash(
stable_release, CURRENT_HASH_NAME, distro_name, distro_version
)
releases_dictionary = {
'undercloud_install_release': stable_release,
@ -306,9 +314,20 @@ def compose_releases_dictionary(
elif featureset.get('undercloud_upgrade'):
logger.info('Doing an undercloud upgrade')
install_release = get_relative_release(stable_release, -1)
install_hash = get_dlrn_hash(
install_release, CURRENT_HASH_NAME, distro_name, distro_version
)
install_hash = ''
if content_provider_hashes is not None and content_provider_hashes.get(
install_branch_override
):
install_hash = content_provider_hashes[install_branch_override]
logger.info(
"Using hash override {} for branch {}".format(
install_hash, install_branch_override
)
)
else:
install_hash = get_dlrn_hash(
install_release, CURRENT_HASH_NAME, distro_name, distro_version
)
releases_dictionary['undercloud_install_release'] = install_release
releases_dictionary['undercloud_install_hash'] = install_hash
@ -480,10 +499,22 @@ if __name__ == '__main__':
)
parser.add_argument(
'--hash-override',
help='Force an specific hash instead of current-tripleo',
'--target-branch-override',
help='Override to use this branch for the target version - required\n'
'with the --content-provider-hashes argument',
)
parser.add_argument(
'--install-branch-override',
help='Override to use this branch for the install version - required\n'
'with the --content-provider-hashes argument',
)
parser.add_argument(
'--content-provider-hashes',
help='A string representing the content provider branches and hashes\n'
'e.g. master:abcd;wallaby:defg i.e. branch1:hash1;branch2:hash2',
)
args = parser.parse_args()
setup_logging(args.log_file)
@ -491,6 +522,37 @@ if __name__ == '__main__':
featureset = load_featureset_file(args.featureset_file)
_content_provider_hashes = None
# when overriding with content-provider-hashes we expect to have
# --install-branch-override and --target-branch-override in args
# and that these branches exist in the passed content-provider-hashes
if args.content_provider_hashes:
if args.target_branch_override is None or args.install_branch_override is None:
raise RuntimeError(
"Missing --target-branch-override or --install-branch-override"
". These are required when using --content-provider-hashes"
)
if (
args.target_branch_override not in args.content_provider_hashes
or args.install_branch_override not in args.content_provider_hashes
):
raise RuntimeError(
"The passed content provider hashes ({}) does not contain"
" the branches specified by --target-branch-override ({}) or"
" --install-branch-override ({})".format(
args.content_provider_hashes,
args.target_branch_override,
args.install_branch_override,
)
)
_content_provider_hashes = {}
# args.content_provider_hashes 'master:1;wallaby:2'
for keyval in args.content_provider_hashes.split(';'):
dict_key = keyval.split(':')[0]
dict_val = keyval.split(':')[1]
_content_provider_hashes.update({dict_key: dict_val})
releases_dictionary = compose_releases_dictionary(
args.stable_release,
featureset,
@ -498,7 +560,9 @@ if __name__ == '__main__':
args.is_periodic,
args.distro_name,
args.distro_version,
args.hash_override,
args.target_branch_override,
args.install_branch_override,
_content_provider_hashes,
)
releases_dictionary = shim_convert_old_release_names(