patch-builder: Flag for adding precheck scripts

Currently, if the patching framework deb package (software.deb)
is one of the pkgs selected for the patch, patch-builder will
also extract a couple scripts (refered to here as 'precheck scripts')
and put them in the separatly in the patch for easier access.

The issue is that, if we create a patch that delivers an ostree repo
instead of a set of deb packages, then auto-inclusion of the
precheck scripts will never happen.

Added a Y/N flag the user can add in the patch XML (similar to the
reboot_required flag) to request inclusion of the precheck scripts.

Test Plan:
pass - flag is not mandatory
pass - if 'Y' regardless of debs requested, scripts are included
pass - if 'N', scripts are included only if software.deb is requested

Story: 2011498
Task: 52900

Change-Id: Ic9866bcd251bfe6f27ce4b60be604beccb815183
Signed-off-by: Leonardo Fagundes Luz Serrano <Leonardo.FagundesLuzSerrano@windriver.com>
This commit is contained in:
Leonardo Fagundes Luz Serrano
2025-10-09 12:43:44 -03:00
parent 472aa67694
commit 12b22ae15f
4 changed files with 22 additions and 4 deletions

View File

@@ -20,6 +20,7 @@
</xs:complexType>
</xs:element>
<xs:element name="semantics" type="xs:string"/>
<xs:element name="precheck_scripts" type="xs:string" minOccurs="0"/>
<xs:element name="pre_start" type="xs:string" minOccurs="0"/>
<xs:element name="post_start" type="xs:string" minOccurs="0"/>
<xs:element name="pre_install" type="xs:string" minOccurs="0"/>

View File

@@ -42,6 +42,7 @@ class FetchDebs(object):
# In general: /localdisk/loadbuild/<USER>/<PROJECT>
self.loadbuild_root = utils.get_env_variable('MY_BUILD_PKG_DIR')
# TODO: These directories should be inputs, not hardcoded.
self.output_dir = os.path.join(self.loadbuild_root, 'dl_debs')
self.apt_src_file = os.path.join(self.loadbuild_root, 'aptsrc')

View File

@@ -45,6 +45,7 @@ BINARY_PACKAGES = 'binary_packages'
SEMANTICS = 'semantics'
ACTIVATION_SCRIPTS = 'activation_scripts'
EXTRA_CONTENT = 'extra_content'
PRECHECK_SCRIPTS_FLAG = 'precheck_scripts'
class PatchMetadata(object):
@@ -122,6 +123,11 @@ class PatchMetadata(object):
else:
raise Exception('Supported values for "Reboot Required" are Y or N, for "Yes" or "No" respectively')
if self.precheck_scripts_flag.upper() in ["Y","N"]:
self.__add_text_tag_to_xml(top_tag, PRECHECK_SCRIPTS_FLAG, self.precheck_scripts_flag.upper())
else:
raise Exception('Supported values for "Precheck Scripts" are Y or N, for "Yes" or "No" respectively')
self.__add_text_tag_to_xml(top_tag, SEMANTICS, self.semantics)
requires_atg = ET.SubElement(top_tag, REQUIRES)
@@ -194,6 +200,10 @@ class PatchMetadata(object):
self.warnings = patch_recipe[WARNINGS]
self.reboot_required = patch_recipe[REBOOT_REQUIRED]
self.precheck_scripts_flag = 'N'
if PRECHECK_SCRIPTS_FLAG in patch_recipe:
self.precheck_scripts_flag = patch_recipe[PRECHECK_SCRIPTS_FLAG]
# For each patch script, validate the path provided
self.patch_script_paths = {
script_id: self.check_script_path(patch_recipe.get(script_id, None))

View File

@@ -135,14 +135,20 @@ class PatchBuilder(object):
logger.info(f"Adding: {item}")
extra_tar.add(item, arcname=os.path.join("extra", os.path.basename(item)))
# if the patch includes the 'software' package we need to make deploy-precheck
# and upgrade_utils.py from .deb file accessible directly from patch file
if 'software' in self.metadata.stx_packages:
logger.info(f"Patch includes the software package, getting scripts from deb file...")
# Precheck Scripts:
# If the patch includes the 'software' package or
# if the patch XML has the 'precheck_scripts' flag set to 'Y',
# extract precheck scripts from software.deb and put them in the patch file
if 'software' in self.metadata.stx_packages or \
self.metadata.precheck_scripts_flag == 'Y':
logger.info(f"Adding precheck scripts...")
# create temporary folder to hold our files until we copy them to the patch
tmp_folder = tempfile.mkdtemp(prefix='deb_')
# Fetch software deb
fetch_debs.FetchDebs(need_dl_stx_pkgs = ['software']).fetch_stx_packages()
# Collect files
files_to_get = [constants.PRECHECK_SCRIPTS["DEPLOY_PRECHECK"],
constants.PRECHECK_SCRIPTS["UPGRADE_UTILS"]]