From f66d6a128d05bb1401afae51d896b635c0c41553 Mon Sep 17 00:00:00 2001 From: mcasquer Date: Wed, 6 Nov 2024 21:54:45 +0100 Subject: [PATCH] Removes the sudo(s) from tmt commands and instead apply it directly in the pidfile creation. Also includes the super().setup() call to the setup GuestSsh function. Signed-off-by: mcasquer --- tests/provision/become/test.sh | 12 ++++++------ tmt/steps/provision/__init__.py | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/provision/become/test.sh b/tests/provision/become/test.sh index 6d61940c7e..9480ead94c 100755 --- a/tests/provision/become/test.sh +++ b/tests/provision/become/test.sh @@ -13,27 +13,27 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "$PROVISION_HOW, test with become=true" - rlRun "sudo tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /test/root" + rlRun "tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /test/root" rlPhaseEnd rlPhaseStartTest "$PROVISION_HOW, test with become=false" - rlRun "sudo tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /test/user" + rlRun "tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /test/user" rlPhaseEnd rlPhaseStartTest "$PROVISION_HOW, prepare/finish inline with become=true" - rlRun "sudo tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/root/inline" + rlRun "tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/root/inline" rlPhaseEnd rlPhaseStartTest "$PROVISION_HOW, prepare/finish inline with become=false" - rlRun "sudo tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/user/inline" + rlRun "tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/user/inline" rlPhaseEnd rlPhaseStartTest "$PROVISION_HOW, prepare/finish scripts with become=true" - rlRun "sudo tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/root/scripts" + rlRun "tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/root/scripts" rlPhaseEnd rlPhaseStartTest "$PROVISION_HOW, prepare/finish scripts with become=false" - rlRun "sudo tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/user/scripts" + rlRun "tmt --context provisiontest=$PROVISION_HOW run -rvvv plan --name /prepare-finish/user/scripts" rlPhaseEnd if [[ "$PROVISION_HOW" == "virtual" ]]; then diff --git a/tmt/steps/provision/__init__.py b/tmt/steps/provision/__init__.py index 38ed15721b..907d17dc9c 100644 --- a/tmt/steps/provision/__init__.py +++ b/tmt/steps/provision/__init__.py @@ -924,12 +924,13 @@ def setup(self) -> None: Setup the guest after it has been started. It is called after :py:meth:`Guest.start`. """ from tmt.steps.execute.internal import effective_pidfile_root + sudo = 'sudo' if not self.facts.is_superuser and self.become else '' pid_directory = effective_pidfile_root() self.execute(ShellScript( f""" if [ ! -d {pid_directory} ]; then \ - mkdir -p {pid_directory} \ - && chmod ugo+rwx {pid_directory}; \ + {sudo} mkdir -p {pid_directory} \ + && {sudo} chmod ugo+rwx {pid_directory}; \ fi """ )) @@ -1719,6 +1720,7 @@ def is_ready(self) -> bool: return self.primary_address is not None def setup(self) -> None: + super().setup() if self.is_dry_run: return if not self.facts.is_superuser and self.become: