From dc97cbd575eb1fcddcd96f423e9aa79dea471604 Mon Sep 17 00:00:00 2001 From: Dostoievski Batista Date: Mon, 2 Dec 2024 17:32:30 -0300 Subject: [PATCH] Copy precheck scripts to the pre-patched ISO When adding patches to the pre-patched ISO some may have the following precheck scripts: "deploy-precheck" and "upgrade_utils.py". With this change they will be copied to the upgrades folder inside the pre-patched ISO. Test plan: PASS: Build pre-patched ISO with one patch PASS: Build pre-patched ISO with more than one patch Partial-Bug: 2090871 Change-Id: I10186da0cea59b0f8a6560b0d7c77df2abaf19ab Signed-off-by: Dostoievski Batista --- build-tools/create-prepatched-iso | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/build-tools/create-prepatched-iso b/build-tools/create-prepatched-iso index f0bf20b4..0179201b 100755 --- a/build-tools/create-prepatched-iso +++ b/build-tools/create-prepatched-iso @@ -399,12 +399,31 @@ def main(): packages = [] for i in xml_root.find('packages').findall('deb'): packages.append(i.text.split("_")[0]) + # Patches can contain precheck scripts, we need to verify if + # they exist and if so move then to the pre-patched iso. + precheck = False + path_precheck = '' + path_upgrade_utils = '' + if "deploy-precheck" in f.getnames() and "upgrade_utils.py" in f.getnames(): + precheck = True + f.extract('deploy-precheck', f"{extract_folder}/") + f.extract('upgrade_utils.py', f"{extract_folder}/") + precheck_folder = f"{ptc_folder}/{sw_version}/precheck" + os.makedirs(f"{precheck_folder}") + path_precheck = f"{precheck_folder}/deploy-precheck" + path_upgrade_utils = f"{precheck_folder}/upgrade_utils.py" + shutil.copy(f"{extract_folder}/deploy-precheck", path_precheck) + shutil.copy(f"{extract_folder}/upgrade_utils.py", path_upgrade_utils) + # Now we save the information we extract for later use patches_data.append({ "sw_version": sw_version, "path": f"{ptc_folder}/{sw_version}", "packages": packages, - "metadata": metadata_path + "metadata": metadata_path, + "precheck": precheck, + "path_precheck": path_precheck, + "path_upgrade_utils": path_upgrade_utils }) # Save the biggest version from the patches we have @@ -429,6 +448,7 @@ def main(): # Now we need to populate reprepo feed with every deb from every patch # after that we install it on the ostree repository logger.info('Populate ostree repository with .deb files...') + patches_data = sorted(patches_data, key=lambda x:x['sw_version']) for patch in patches_data: # Scan /debs/ folder and load every patch to the reprepo feed deb_dir = os.scandir(os.path.join(patch["path"],"debs/")) @@ -451,6 +471,11 @@ def main(): logger.debug('Running command: %s', cmd) subprocess.check_call(cmd, shell=False) + # Check if patch has precheck scripts, if yes move then to the upgrades folder + if patch["precheck"]: + shutil.copy(patch["path_precheck"], f"{iso_folder}/upgrades") + shutil.copy(patch["path_upgrade_utils"], f"{iso_folder}/upgrades") + # Copy only the patch metadata with the biggest patch version to ISO patch_num = int(patch["sw_version"].split(".")[-1]) if latest_patch_number == patch_num: