From b447a6a3078789c247b43f29e830bafb4e81d65c Mon Sep 17 00:00:00 2001 From: Miroslav Vadkerti Date: Fri, 20 Sep 2024 01:40:14 +0200 Subject: [PATCH] Support Fedora Image Mode - [x] Proof-of-concept - [ ] Discuss how to solve the scripts location read-only - [ ] Polish and prepare for merging Signed-off-by: Miroslav Vadkerti --- tmt/steps/execute/__init__.py | 44 ++++++++++++++++++++++---------- tmt/steps/execute/scripts/tmt.sh | 2 ++ tmt/steps/provision/__init__.py | 18 +------------ 3 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 tmt/steps/execute/scripts/tmt.sh diff --git a/tmt/steps/execute/__init__.py b/tmt/steps/execute/__init__.py index f1da4e7d52..04036305a4 100644 --- a/tmt/steps/execute/__init__.py +++ b/tmt/steps/execute/__init__.py @@ -27,6 +27,7 @@ from tmt.steps.discover import Discover, DiscoverPlugin, DiscoverStepData from tmt.steps.provision import Guest from tmt.utils import ( + Command, Path, ShellScript, Stopwatch, @@ -58,6 +59,9 @@ # Scripts source directory SCRIPTS_SRC_DIR = tmt.utils.resource_files('steps/execute/scripts') +# Scripts destination directory, hardcoded in the tmt.sh script +SCRIPTS_DEST_DIR = "/var/tmp/tmt/bin" + @dataclass class Script: @@ -77,10 +81,10 @@ class ScriptCreatingFile(Script): # Script handling reboots, in restraint compatible fashion TMT_REBOOT_SCRIPT = ScriptCreatingFile( - path=Path("/usr/local/bin/tmt-reboot"), + path=Path(f"{SCRIPTS_DEST_DIR}/tmt-reboot"), aliases=[ - Path("/usr/local/bin/rstrnt-reboot"), - Path("/usr/local/bin/rhts-reboot")], + Path(f"{SCRIPTS_DEST_DIR}/rstrnt-reboot"), + Path(f"{SCRIPTS_DEST_DIR}/rhts-reboot")], related_variables=[ "TMT_REBOOT_COUNT", "REBOOTCOUNT", @@ -89,43 +93,52 @@ class ScriptCreatingFile(Script): ) TMT_REBOOT_CORE_SCRIPT = Script( - path=Path("/usr/local/bin/tmt-reboot-core"), + path=Path(f"{SCRIPTS_DEST_DIR}/tmt-reboot-core"), aliases=[], related_variables=[]) # Script handling result reporting, in restraint compatible fashion TMT_REPORT_RESULT_SCRIPT = ScriptCreatingFile( - path=Path("/usr/local/bin/tmt-report-result"), + path=Path(f"{SCRIPTS_DEST_DIR}/tmt-report-result"), aliases=[ - Path("/usr/local/bin/rstrnt-report-result"), - Path("/usr/local/bin/rhts-report-result")], + Path(f"{SCRIPTS_DEST_DIR}/rstrnt-report-result"), + Path(f"{SCRIPTS_DEST_DIR}/rhts-report-result")], related_variables=[], created_file="tmt-report-results.yaml" ) # Script for archiving a file, usable for BEAKERLIB_COMMAND_SUBMIT_LOG TMT_FILE_SUBMIT_SCRIPT = Script( - path=Path("/usr/local/bin/tmt-file-submit"), + path=Path(f"{SCRIPTS_DEST_DIR}/tmt-file-submit"), aliases=[ - Path("/usr/local/bin/rstrnt-report-log"), - Path("/usr/local/bin/rhts-submit-log"), - Path("/usr/local/bin/rhts_submit_log")], + Path(f"{SCRIPTS_DEST_DIR}/rstrnt-report-log"), + Path(f"{SCRIPTS_DEST_DIR}/rhts-submit-log"), + Path(f"{SCRIPTS_DEST_DIR}/rhts_submit_log")], related_variables=[] ) # Script handling text execution abortion, in restraint compatible fashion TMT_ABORT_SCRIPT = ScriptCreatingFile( - path=Path("/usr/local/bin/tmt-abort"), + path=Path(f"{SCRIPTS_DEST_DIR}/tmt-abort"), aliases=[ - Path("/usr/local/bin/rstrnt-abort"), - Path("/usr/local/bin/rhts-abort")], + Path(f"{SCRIPTS_DEST_DIR}/rstrnt-abort"), + Path(f"{SCRIPTS_DEST_DIR}/rhts-abort")], related_variables=[], created_file="abort" ) +# Profile script for adding SCRIPTS_DEST_DIR to executable pats system-wide +TMT_ETC_PROFILE_D = Script( + path=Path(f"/etc/profile.d/tmt.sh"), + aliases=[], + related_variables=[], + ) + + # List of all available scripts SCRIPTS = ( TMT_ABORT_SCRIPT, + TMT_ETC_PROFILE_D, TMT_FILE_SUBMIT_SCRIPT, TMT_REBOOT_SCRIPT, TMT_REBOOT_CORE_SCRIPT, @@ -597,6 +610,9 @@ def prepare_tests(self, guest: Guest, logger: tmt.log.Logger) -> list[TestInvoca def prepare_scripts(self, guest: "tmt.steps.provision.Guest") -> None: """ Prepare additional scripts for testing """ + # Create scripts directory + guest.execute(Command("mkdir", "-p", f"{SCRIPTS_DEST_DIR}")) + # Install all scripts on guest for script in self.scripts: source = SCRIPTS_SRC_DIR / script.path.name diff --git a/tmt/steps/execute/scripts/tmt.sh b/tmt/steps/execute/scripts/tmt.sh new file mode 100644 index 0000000000..27630ea23d --- /dev/null +++ b/tmt/steps/execute/scripts/tmt.sh @@ -0,0 +1,2 @@ +# tmt provides certain executable scripts under this path +export PATH=/var/tmp/tmt/bin:$PATH diff --git a/tmt/steps/provision/__init__.py b/tmt/steps/provision/__init__.py index 049ae27d84..619a78c4c6 100644 --- a/tmt/steps/provision/__init__.py +++ b/tmt/steps/provision/__init__.py @@ -1303,23 +1303,7 @@ def _check_rsync(self) -> CheckRsyncOutcome: except tmt.utils.RunError: pass - # Install under '/root/pkg' for read-only distros - # (for now the check is based on 'rpm-ostree' presence) - # FIXME: Find a better way how to detect read-only distros - # self.debug("Check for a read-only distro.") - if self.facts.package_manager == 'rpm-ostree': - self.package_manager.install( - Package('rsync'), - options=tmt.package_managers.Options( - install_root=Path('/root/pkg'), - release_version='/' - ) - ) - - self.execute(Command('ln', '-sf', '/root/pkg/bin/rsync', '/usr/local/bin/rsync')) - - else: - self.package_manager.install(Package('rsync')) + self.package_manager.install(Package('rsync')) return CheckRsyncOutcome.INSTALLED