Remove duplicate load import script copy

The usm_load_import script is currently being copied to two
different places needlessly during the upload process for a
major release: (/etc/software and /opt/software/rel-<ver>/bin).

This commit keeps only the copy to the versioned directory under
/opt/software/rel-<ver> and also changes the code to use the
script from this location accordingly.

Test Plan
PASS: run 'software upload' successfully

Story: 2010676
Task: 49624

Relates-to: https://review.opendev.org/c/starlingx/update/+/910027

Change-Id: I0178007721505ff8e2c2244964692b79e8aafea9
Signed-off-by: Heitor Matsui <heitorvieira.matsui@windriver.com>
This commit is contained in:
Heitor Matsui 2024-02-26 16:29:59 -03:00
parent 557b80922e
commit e414d85716
3 changed files with 27 additions and 22 deletions

View File

@ -155,7 +155,6 @@ PATCH_EXTENSION = ".patch"
SUPPORTED_UPLOAD_FILE_EXT = [ISO_EXTENSION, SIG_EXTENSION, PATCH_EXTENSION]
SCRATCH_DIR = "/scratch"
RELEASE_GA_NAME = "starlingx-%s"
LOCAL_LOAD_IMPORT_FILE = "/etc/software/usm_load_import"
# Precheck constants
LICENSE_FILE = "/etc/platform/.license"

View File

@ -1153,7 +1153,7 @@ class PatchController(PatchService):
major_releases.append(major_rel)
if len(major_releases) >= max_major_releases:
msg = f"Major releases {major_releases} have already been uploaded." + \
msg = f"Major releases {major_releases} have already been uploaded. " + \
f"Max major releases is {max_major_releases}"
LOG.info(msg)
raise SoftwareServiceError(error=msg)
@ -1173,6 +1173,7 @@ class PatchController(PatchService):
# validate this major release upload
self.major_release_upload_check()
to_release = None
iso_mount_dir = None
try:
if not verify_files([upgrade_files[constants.ISO_EXTENSION]],
@ -1199,13 +1200,18 @@ class PatchController(PatchService):
raise UpgradeNotSupported("Current release %s not supported to upgrade to %s"
% (SW_VERSION, to_release))
# Run /etc/software/usm-load-import script
LOG.info("Start load importing from %s", iso_file)
import_script = os.path.join(iso_mount_dir, 'upgrades',
constants.SOFTWARE_DEPLOY_FOLDER, 'usm_load_import')
shutil.copyfile(import_script, constants.LOCAL_LOAD_IMPORT_FILE)
os.chmod(constants.LOCAL_LOAD_IMPORT_FILE, 0o755)
load_import_cmd = [constants.LOCAL_LOAD_IMPORT_FILE,
# Copy iso /upgrades/software-deploy/ to /opt/software/rel-<rel>/bin/
to_release_bin_dir = os.path.join(
constants.SOFTWARE_STORAGE_DIR, ("rel-%s" % to_release), "bin")
if os.path.exists(to_release_bin_dir):
shutil.rmtree(to_release_bin_dir)
shutil.copytree(os.path.join(iso_mount_dir, "upgrades",
constants.SOFTWARE_DEPLOY_FOLDER), to_release_bin_dir)
# Run usm_load_import script
LOG.info("Starting load import from %s", iso_file)
import_script = os.path.join(to_release_bin_dir, 'usm_load_import')
load_import_cmd = [import_script,
"--from-release=%s" % SW_VERSION,
"--to-release=%s" % to_release,
"--iso-dir=%s" % iso_mount_dir]
@ -1220,13 +1226,6 @@ class PatchController(PatchService):
else:
local_info += load_import_return.stdout
# Copy iso /upgrades/software-deploy/ to /opt/software/rel-<rel>/bin/
to_release_bin_dir = os.path.join(
constants.SOFTWARE_STORAGE_DIR, ("rel-%s" % to_release), "bin")
if os.path.exists(to_release_bin_dir):
shutil.rmtree(to_release_bin_dir)
shutil.copytree(os.path.join(iso_mount_dir, "upgrades",
constants.SOFTWARE_DEPLOY_FOLDER), to_release_bin_dir)
# Copy metadata.xml to /opt/software/rel-<rel>/
to_file = os.path.join(constants.SOFTWARE_STORAGE_DIR, ("rel-%s" % to_release), "metadata.xml")
metadata_file = os.path.join(iso_mount_dir, "upgrades", "metadata.xml")
@ -1259,6 +1258,10 @@ class PatchController(PatchService):
msg = "Failed to process upgrade files. Error: %s" % str(e)
LOG.exception(msg)
local_error += msg + "\n"
# delete versioned directory
if to_release:
to_release_dir = os.path.join(constants.SOFTWARE_STORAGE_DIR, "rel-%s" % to_release)
shutil.rmtree(to_release_dir, ignore_errors=True)
finally:
# Unmount the iso file
if iso_mount_dir:

View File

@ -54,13 +54,13 @@ class TestSoftwareController(unittest.TestCase):
mock_verify_files.return_value = True
mock_mount_iso_load.return_value = '/test/iso'
mock_read_upgrade_support_versions.return_value = (
'2.0', [{'version': '1.0'}, {'version': '2.0'}])
'2.0.0', [{'version': '1.0.0'}, ])
mock_run.return_value.returncode = 0
mock_run.return_value.stdout = 'Load import successful'
mock_parse_release_metadata.return_value = {"id": 1, "sw_version": "2.0"}
mock_parse_release_metadata.return_value = {"id": 1, "sw_version": "2.0.0"}
# Call the function being tested
with patch('software.software_controller.SW_VERSION', '1.0'):
with patch('software.software_controller.SW_VERSION', '1.0.0'):
info, warning, error, release_meta_info = controller._process_upload_upgrade_files(self.upgrade_files, # pylint: disable=protected-access
controller.release_data)
@ -71,8 +71,11 @@ class TestSoftwareController(unittest.TestCase):
self.upgrade_files[constants.ISO_EXTENSION], constants.TMP_DIR)
mock_read_upgrade_support_versions.assert_called_once_with('/test/iso')
self.assertEqual(mock_run.call_args[0][0], [constants.LOCAL_LOAD_IMPORT_FILE,
"--from-release=1.0", "--to-release=2.0", "--iso-dir=/test/iso"])
self.assertEqual(mock_run.call_args[0][0], ["%s/rel-%s/bin/%s" % (
constants.SOFTWARE_STORAGE_DIR,
release_meta_info["test.iso"]["sw_version"],
"usm_load_import"),
"--from-release=1.0.0", "--to-release=2.0.0", "--iso-dir=/test/iso"])
mock_unmount_iso_load.assert_called_once_with('/test/iso')
# Verify that the expected messages were returned
@ -83,7 +86,7 @@ class TestSoftwareController(unittest.TestCase):
self.assertEqual(error, '')
self.assertEqual(
release_meta_info,
{"test.iso": {"id": 1, "sw_version": "2.0"},
{"test.iso": {"id": 1, "sw_version": "2.0.0"},
"test.sig": {"id": None, "sw_version": None}})
@patch('software.software_controller.PatchController.__init__', return_value=None)