Skip to content

Commit

Permalink
Removes the sudo(s) from tmt commands and instead apply it directly
Browse files Browse the repository at this point in the history
in the pidfile creation. Also includes the super().setup() call to
the setup GuestSsh function.

Signed-off-by: mcasquer <[email protected]>
  • Loading branch information
mcasquer committed Nov 6, 2024
1 parent b55235a commit f66d6a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions tests/provision/become/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tmt/steps/provision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f66d6a1

Please sign in to comment.