create-prepatched-iso: Delete ostree remote refs

Some references to remote ostree repos were being left
in the ostree repo config of the output ISO, causing
problems when manipulating it during install and runtime.

Added a remote refs removal step.

Test Plan:
pass: input ostree repo without remotes
pass: input ostree repo with remotes
pass: pre-patched ISO ostree repo configs do not include
      the ostree remotes used for building the ISO
pass: Testpatch applied on pre-patched ISO

Story: 2011318
Task: 51562

Change-Id: I02957c19a1238b5ca947c22b201cd48614527faf
Signed-off-by: Leonardo Fagundes Luz Serrano <Leonardo.FagundesLuzSerrano@windriver.com>
This commit is contained in:
Leonardo Fagundes Luz Serrano 2025-01-17 20:08:36 -03:00
parent c4a96b33f3
commit 9cbdd472fe

View File

@ -508,6 +508,32 @@ def get_ostree_history(ostree_repo: str, filtered: bool = True) -> str:
return "\n".join(filtered_history)
def remove_ostree_remotes(ostree_repo: str) -> None:
"""
Remove all references to remote ostree repos from the target ostree repo
:param ostree_repo: Path to ostree repo
"""
logger.info("Cleaning remotes from ostree repo...")
if not os.path.isdir(ostree_repo):
raise Exception(f"Ostree repo directory does not exist: {ostree_repo}")
cmd = ["ostree", f"--repo={ostree_repo}", "remote", "list"]
remote_list = run_command(cmd).split()
logger.debug(f"Remotes: {remote_list}")
for remote in remote_list:
cmd = ["ostree", f"--repo={ostree_repo}", "remote", "delete", remote]
run_command(cmd)
with open(f"{ostree_repo}/config", mode="r", encoding="utf-8") as file:
ostree_config = file.read()
logger.debug(log_message("Clean ostree config:", ostree_config))
# TODO (lfagunde): This function, along with all ostree repo manipulations
# across this script, can be implemented as a separate file for "ostree utils".
# Define a class with the repo path as it's defining property and several
@ -976,6 +1002,9 @@ def main():
# Keep only the latest commit in ostree_repo to save storage space
clean_ostree(f"{build_tempdir}/ostree_repo")
# Remove all references to remote ostree repos used during build
remove_ostree_remotes(f"{build_tempdir}/ostree_repo")
# Now we get the label and re create the ISO with the new ostree
logger.info('Creating new .iso file...')
instlabel = get_iso_label_from_isolinux_cfg(f"{build_tempdir}/isolinux/isolinux.cfg")