Merge "Update images prestage logic for USM"

This commit is contained in:
Zuul 2024-07-30 19:00:46 +00:00 committed by Gerrit Code Review
commit a714f57a37
2 changed files with 31 additions and 34 deletions

View File

@ -337,19 +337,20 @@ def prestage_subcloud(context, payload):
def _prestage_standalone_thread(context, subcloud, payload):
"""Run the prestage operations inside a separate thread"""
log_file = utils.get_subcloud_ansible_log_file(subcloud.name)
for_sw_deploy = is_prestage_for_sw_deploy(payload)
if is_prestage_for_sw_deploy(payload):
prestage_reason = consts.PRESTAGE_FOR_SW_DEPLOY
else:
prestage_reason = consts.PRESTAGE_FOR_INSTALL
try:
prestage_packages(context, subcloud, payload)
prestage_packages(context, subcloud, payload, prestage_reason)
# Get the prestage versions from the logs generated by
# the prestage packages playbook
prestage_versions = utils.get_msg_output_info(
log_file, PRINT_PRESTAGE_VERSIONS_TASK, PRESTAGE_VERSIONS_KEY_STR
)
# TODO(kmacleod) need to invoke this for retagging images
if not for_sw_deploy:
prestage_images(context, subcloud, payload)
prestage_images(context, subcloud, payload, prestage_reason)
prestage_complete(context, subcloud.id, prestage_versions)
LOG.info("Prestage complete: %s", subcloud.name)
@ -449,7 +450,7 @@ def _run_ansible(
LOG.info("Prestage %s successful for subcloud %s", phase, subcloud.name)
def prestage_packages(context, subcloud, payload):
def prestage_packages(context, subcloud, payload, reason=consts.PRESTAGE_FOR_INSTALL):
"""Run the prestage packages ansible script."""
# Ansible inventory filename for the specified subcloud
@ -460,13 +461,8 @@ def prestage_packages(context, subcloud, payload):
prestage_software_version = payload.get(consts.PRESTAGE_REQUEST_RELEASE, SW_VERSION)
prestage_major_release = utils.get_major_release(prestage_software_version)
extra_vars_str = f"software_version={prestage_software_version} "
extra_vars_str += f"software_major_release={prestage_major_release}"
if is_prestage_for_sw_deploy(payload):
extra_vars_str += f" prestage_install={consts.PRESTAGE_FOR_SW_DEPLOY}"
else:
# default
extra_vars_str += f" prestage_install={consts.PRESTAGE_FOR_INSTALL}"
extra_vars_str += f"software_major_release={prestage_major_release} "
extra_vars_str += f"prestage_reason={reason}"
ostree_mount.validate_ostree_iso_mount(prestage_major_release)
@ -490,7 +486,7 @@ def prestage_packages(context, subcloud, payload):
)
def prestage_images(context, subcloud, payload):
def prestage_images(context, subcloud, payload, reason=consts.PRESTAGE_FOR_INSTALL):
"""Run the prestage images ansible script.
If the prestage images file has been uploaded, include the fully
@ -505,19 +501,11 @@ def prestage_images(context, subcloud, payload):
"""
prestage_software_version = payload.get(consts.PRESTAGE_REQUEST_RELEASE, SW_VERSION)
prestage_major_release = utils.get_major_release(prestage_software_version)
extra_vars_str = f"software_version={prestage_software_version} "
extra_vars_str += f"software_major_release={prestage_major_release}"
# TODO(kmacleod) we may not need these if images are not prestaged
# if for_sw_deploy
if consts.PRESTAGE_FOR_INSTALL in payload:
extra_vars_str += f" for_install={payload[consts.PRESTAGE_FOR_INSTALL]}"
elif consts.PRESTAGE_FOR_SW_DEPLOY in payload:
extra_vars_str += f" for_sw_deploy={payload[consts.PRESTAGE_FOR_SW_DEPLOY]}"
extra_vars_str += f"prestage_reason={reason}"
image_list_filename = None
deploy_dir = os.path.join(DEPLOY_BASE_DIR, prestage_major_release)
deploy_dir = os.path.join(DEPLOY_BASE_DIR, prestage_software_version)
if os.path.isdir(deploy_dir):
image_list_filename = utils.get_filename_by_prefix(
deploy_dir, "prestage_images"
@ -529,14 +517,21 @@ def prestage_images(context, subcloud, payload):
LOG.debug("prestage images list file: %s", image_list_file)
else:
LOG.debug("prestage images list file does not exist")
if prestage_major_release != subcloud.software_version:
# Prestage source is remote but there is no images list file so
# skip the images prestage.
if reason == consts.PRESTAGE_FOR_SW_DEPLOY:
LOG.info(
"Images prestage is skipped for %s as the prestage images "
"list for release %s has not been uploaded and the "
"subcloud is running a different load than %s."
% (subcloud.name, prestage_major_release, prestage_major_release)
f"Images prestage is skipped for {subcloud.name} as "
f"the prestage images list for release {prestage_software_version} "
f"has not been uploaded for {reason}."
)
return
elif prestage_software_version != subcloud.software_version:
# Prestage source is remote but there is no images list file for
# for-install scenario so skip the images prestage.
LOG.info(
f"Images prestage is skipped for {subcloud.name}. The prestage "
f"images list for release {prestage_software_version} has not "
f"been uploaded for {reason} and the subcloud is "
f"running a different load than {prestage_software_version}."
)
return

View File

@ -3533,9 +3533,11 @@ class TestSubcloudPrestage(BaseTestSubcloudManager):
prestage._prestage_standalone_thread(self.ctx, self.subcloud, payload=values)
mock_run_ansible.return_value = None
mock_prestage_packages.assert_called_once_with(
self.ctx, self.subcloud, values
self.ctx, self.subcloud, values, consts.PRESTAGE_FOR_INSTALL
)
mock_prestage_images.assert_called_once_with(
self.ctx, self.subcloud, values, consts.PRESTAGE_FOR_INSTALL
)
mock_prestage_images.assert_called_once_with(self.ctx, self.subcloud, values)
self.mock_delete_subcloud_inventory.return_value = None
# Verify that subcloud has the "prestage-complete" deploy status