Change scripts names in the patch's metadata
When adding a pre-install or post-install script to the patch, we rename it to "pre-install.sh" or "post-install.sh" to facilitate the use of the patch afterwards. This change makes the metadata inside the patch reflect this. Together with this change we move PATCH_SCRIPTS constant to separate file as the same will be call in different files. Test plan: PASS: Create patch without any scripts PASS: Create patch with only pre-install script PASS: Create patch with only post-install script PASS: Create patch with all scripts PASS: Install patch with all scripts in a running AIO-SX, check if scripts are present in /opt/software/software-scripts/ PASS: Delete patch with all scripts in a running AIO-SX, check if scripts are not present in /opt/software/software-scripts/ Story: 2010676 Task: 50926 Change-Id: I639ff15e306ec69ed1bbbfea8c99aa96affa1dec Signed-off-by: Dostoievski Batista <dostoievski.albinobatista@windriver.com>
This commit is contained in:
parent
93d6fe12d5
commit
a1a167bb71
13
build-tools/stx/patch/constants.py
Normal file
13
build-tools/stx/patch/constants.py
Normal file
@ -0,0 +1,13 @@
|
||||
#
|
||||
# Copyright (c) 2024 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# Default names for the script inside the patch
|
||||
PATCH_SCRIPTS = {
|
||||
"PRE_INSTALL": "pre-install.sh",
|
||||
"POST_INSTALL": "post-install.sh",
|
||||
"DEPLOY_PRECHECK": "deploy-precheck",
|
||||
"UPGRADE_UTILS": "upgrade_utils.py",
|
||||
}
|
@ -17,6 +17,8 @@ import xml.etree.ElementTree as ET
|
||||
from lxml import etree
|
||||
from xml.dom import minidom
|
||||
|
||||
import constants
|
||||
|
||||
logger = logging.getLogger('metadata_parser')
|
||||
utils.set_logger(logger)
|
||||
|
||||
@ -98,10 +100,6 @@ class PatchMetadata(object):
|
||||
|
||||
def generate_patch_metadata(self, file_path):
|
||||
# Generate patch metadata.xml
|
||||
# strip path from pre_install and post_install scripts
|
||||
self.pre_install = self.pre_install.split('/')[-1]
|
||||
self.post_install = self.post_install.split('/')[-1]
|
||||
|
||||
top_tag = ET.Element(PATCH_ROOT_TAG)
|
||||
self.__add_text_tag_to_xml(top_tag, PATCH_ID, self.patch_id)
|
||||
self.__add_text_tag_to_xml(top_tag, SW_VERSION, self.sw_version)
|
||||
@ -128,8 +126,17 @@ class PatchMetadata(object):
|
||||
for req_patch in sorted(self.requires):
|
||||
self.__add_text_tag_to_xml(requires_atg, REQUIRES_PATCH_ID, req_patch)
|
||||
|
||||
self.__add_text_tag_to_xml(top_tag, PRE_INSTALL, self.pre_install)
|
||||
self.__add_text_tag_to_xml(top_tag, POST_INSTALL, self.post_install)
|
||||
if self.pre_install:
|
||||
self.__add_text_tag_to_xml(top_tag, PRE_INSTALL,
|
||||
constants.PATCH_SCRIPTS['PRE_INSTALL'])
|
||||
else:
|
||||
self.__add_text_tag_to_xml(top_tag, PRE_INSTALL, "")
|
||||
|
||||
if self.post_install:
|
||||
self.__add_text_tag_to_xml(top_tag, POST_INSTALL,
|
||||
constants.PATCH_SCRIPTS['POST_INSTALL'])
|
||||
else:
|
||||
self.__add_text_tag_to_xml(top_tag, POST_INSTALL, "")
|
||||
|
||||
packages_tag = ET.SubElement(top_tag, PACKAGES)
|
||||
for package in sorted(self.debs):
|
||||
@ -202,7 +209,7 @@ class PatchMetadata(object):
|
||||
def check_script_path(self, script_path):
|
||||
if not script_path:
|
||||
# No scripts provided
|
||||
return ''
|
||||
return None
|
||||
|
||||
if not os.path.isabs(script_path):
|
||||
script_path = os.path.join(os.getcwd(), script_path)
|
||||
|
@ -22,6 +22,8 @@ import fetch_debs
|
||||
import metadata
|
||||
from signing.patch_signing import sign_files
|
||||
|
||||
import constants
|
||||
|
||||
sys.path.append('..')
|
||||
import utils
|
||||
|
||||
@ -36,14 +38,6 @@ mdsum_signature_file = "signature"
|
||||
DEPLOY_DIR = "/localdisk/deploy"
|
||||
PATCH_OUTPUT = os.path.join(DEPLOY_DIR, "patch_output")
|
||||
|
||||
# Default names for every script type
|
||||
PATCH_SCRIPTS = {
|
||||
"PRE_INSTALL": "pre-install.sh",
|
||||
"POST_INSTALL": "post-install.sh",
|
||||
"DEPLOY_PRECHECK": "deploy-precheck",
|
||||
"UPGRADE_UTILS": "upgrade_utils.py",
|
||||
}
|
||||
|
||||
class PatchBuilder(object):
|
||||
def __init__(self, patch_recipe_file, file_name=None):
|
||||
self.metadata = metadata.PatchMetadata(patch_recipe_file)
|
||||
@ -112,7 +106,8 @@ class PatchBuilder(object):
|
||||
tmp_folder = tempfile.mkdtemp(prefix='deb_')
|
||||
|
||||
# Collect files
|
||||
files_to_get = [PATCH_SCRIPTS["DEPLOY_PRECHECK"], PATCH_SCRIPTS["UPGRADE_UTILS"]]
|
||||
files_to_get = [constants.PATCH_SCRIPTS["DEPLOY_PRECHECK"],
|
||||
constants.PATCH_SCRIPTS["UPGRADE_UTILS"]]
|
||||
path_files = self.get_files_from_deb(dl_dir, tmp_folder, 'software', files_to_get)
|
||||
|
||||
for path in path_files:
|
||||
@ -153,7 +148,7 @@ class PatchBuilder(object):
|
||||
# check if need a rename or not
|
||||
if rename:
|
||||
# We check the type to correctly rename the file to a expected value
|
||||
script_name = PATCH_SCRIPTS.get(script_type, None)
|
||||
script_name = constants.PATCH_SCRIPTS.get(script_type, None)
|
||||
|
||||
if script_name and rename:
|
||||
logger.info(f"Renaming {path_to_script} to {script_name}")
|
||||
@ -227,10 +222,10 @@ class PatchBuilder(object):
|
||||
filelist = ["metadata.tar", "software.tar"]
|
||||
|
||||
if self.metadata.pre_install:
|
||||
filelist.append(PATCH_SCRIPTS["PRE_INSTALL"])
|
||||
filelist.append(constants.PATCH_SCRIPTS["PRE_INSTALL"])
|
||||
|
||||
if self.metadata.post_install:
|
||||
filelist.append(PATCH_SCRIPTS["POST_INSTALL"])
|
||||
filelist.append(constants.PATCH_SCRIPTS["POST_INSTALL"])
|
||||
|
||||
# Generate the local signature file
|
||||
logger.debug(f"Generating signature for patch files {filelist}")
|
||||
|
Loading…
Reference in New Issue
Block a user