From 03410a3f889da8b7da605beb0b45d4cd79fe8899 Mon Sep 17 00:00:00 2001 From: Leonardo Fagundes Luz Serrano Date: Thu, 11 Apr 2024 22:18:20 -0300 Subject: [PATCH] Remove patch-iso-debian's xmllint pkg requirement With this change, if 'xmllint' is not available, the script will try to use python3's xml default module Also corrected some misleading logs regarding what info is extracted from the patch xmls Test Plan: pass - Execute snippet with the changes and confirm ostree commit was properly extracted pending - Build pre-patched ISO Jira: CGTS-61404 Change-Id: I13c2440814de337049c0af84f20b83bf524a05ea Signed-off-by: Leonardo Fagundes Luz Serrano --- build-tools/patch-iso-debian | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/build-tools/patch-iso-debian b/build-tools/patch-iso-debian index 93dc782e..61b3ccfd 100755 --- a/build-tools/patch-iso-debian +++ b/build-tools/patch-iso-debian @@ -38,6 +38,18 @@ function usage() { echo "" } +function extract_ostree_commit_from_metadata_xml() { + local XML_PATH=$1 + local XPATH="//contents/ostree/commit1/commit" + + # Check if xmllint is available. Otherwise, use python's xml standard lib + if (which xmllint &>/dev/null); then + xmllint --xpath "string(${XPATH})" ${XML_PATH} + else + python3 -c "import xml.etree.ElementTree as ET ; print(ET.parse('${XML_PATH}').find('.${XPATH}').text, end='')" + fi +} + function extract_metadata() { local patchesdir=${BUILDDIR}/patches local patchfile=$1 @@ -53,11 +65,11 @@ function extract_metadata() { fi # Verify if top commit from metadata exist in ostree log - xml_base=$(xmllint --xpath "string(//contents/ostree/commit1/commit)" ${patchesdir}/${patchid}-metadata.xml) - if [[ "$ostree_log" != *"$xml_base"* ]]; then - echo "Error, xml base commit does not exist in ostree log." - echo "patch base: ${xml_base}" - echo "ostree log:" + ostree_commit=$(extract_ostree_commit_from_metadata_xml ${patchesdir}/${patchid}-metadata.xml) + if [[ "$ostree_log" != *"$ostree_commit"* ]]; then + echo "Error: Patch ${patchid} ostree commit does not exist in ISO ostree log." + echo "patch's ostree commit: ${ostree_commit}" + echo "ISO ostree log:" ostree --repo=${BUILDDIR}/ostree_repo log starlingx exit 1 fi @@ -126,7 +138,6 @@ function check_requirements { isohybrid implantisomd5 ostree - xmllint ) if [ $UID -ne 0 ]; then # If running as non-root user, additional utils are required @@ -236,7 +247,7 @@ mkdir -p ${BUILDDIR}/patches chmod -R +w ${BUILDDIR}/patches echo "Copying only the latest commit from ostree_repo..." -ostree --repo=${BUILDDIR}/ostree_repo init --mode=archive-z2 +ostree --repo=${BUILDDIR}/ostree_repo init --mode=archive-z2 ostree --repo=${BUILDDIR}/ostree_repo pull-local --depth=0 ${OSTREE_REPO} starlingx ostree --repo=${BUILDDIR}/ostree_repo summary --update echo "Updated iso ostree commit:"