diff --git a/tests/provision/connect/test.sh b/tests/provision/connect/test.sh index 18367244e8..a3a22aeedf 100755 --- a/tests/provision/connect/test.sh +++ b/tests/provision/connect/test.sh @@ -30,11 +30,11 @@ rlJournalStart rlAssertGrep "Reboot finished" $rlRun_LOG rlAssertGrep "sudo /bin/bash -c reboot" $rlRun_LOG - # Test reboot without become (should fail for non-root user) + # Test reboot without become (should apply sudo as well, no a user script) provision_no_become="provision -h connect --guest localhost --port $guest_port --key $guest_key --user $guest_user" - rlRun -s "tmt -vv run --scratch -i $run_connect_no_become $provision_no_become reboot --step provision" 2 - rlAssertGrep "fail: Command 'reboot' returned 1." $rlRun_LOG - rlAssertGrep "Call to Reboot failed: Access denied" $rlRun_LOG + rlRun -s "tmt -vv run --scratch -i $run_connect_no_become $provision_no_become reboot --step provision" + rlAssertGrep "Reboot finished" $rlRun_LOG + rlAssertGrep "sudo /bin/bash -c reboot" $rlRun_LOG rlRun "tmt run -i $run cleanup" rlRun "tmt run -i $run_connect cleanup" diff --git a/tests/provision/reboot/test.sh b/tests/provision/reboot/test.sh index 00d64c97fc..e5020e7046 100755 --- a/tests/provision/reboot/test.sh +++ b/tests/provision/reboot/test.sh @@ -124,7 +124,7 @@ rlJournalStart 0 "Systemd soft-reboot" rlAssertGrep "reboot: Rebooting guest using systemd-soft mode." $rlRun_LOG rlAssertGrep "reboot: Reboot finished" $rlRun_LOG - rlAssertGrep "cmd: systemctl soft-reboot" $rlRun_LOG + rlAssertGrep "cmd: /bin/bash -c 'systemctl soft-reboot'" $rlRun_LOG rlRun -s "tmt -vv run -l reboot --systemd-soft --command 'systemctl soft-reboot'" \ 0 "Systemd soft-reboot with custom command" diff --git a/tests/test/check/test-journal.sh b/tests/test/check/test-journal.sh index a5598c5e46..88ed69dcac 100755 --- a/tests/test/check/test-journal.sh +++ b/tests/test/check/test-journal.sh @@ -145,10 +145,10 @@ rlJournalStart rlAssertGrep "Configured persistent journal storage with sudo" $rlRun_LOG fi - rlFileExists "$config_test/checks/journal.txt" + rlAssertExists "$config_test/checks/journal.txt" rlRun -s "cat $config_test_check/output.txt" - rlAssertGrep "^\[Journal\]$" $rlRun_LOG + rlAssertGrep "\[Journal\]" $rlRun_LOG rlAssertGrep "^Storage=persistent$" $rlRun_LOG rlAssertGrep "^Compress=yes$" $rlRun_LOG rlPhaseEnd diff --git a/tmt/guest/__init__.py b/tmt/guest/__init__.py index 928982def5..c4f29067fb 100644 --- a/tmt/guest/__init__.py +++ b/tmt/guest/__init__.py @@ -1309,8 +1309,9 @@ class GuestData( is_flag=True, option=('-b', '--become'), help=""" - Whether to run tests and shell scripts in prepare and - finish steps with ``sudo``. + If set, user-provided commands - ``prepare`` and ``finish`` + scripts and tests - will be invoked with elevated, superuser + privileges via passwordless ``sudo`` if necessary. """, ) @@ -3757,10 +3758,9 @@ def reboot( f"Guest '{self.multihost_name}' does not support hard reboot." ) - if self.become: - default_reboot_command = ShellScript( - f'sudo {default_reboot_command.to_shell_command()}' - ) + default_reboot_command = ShellScript( + f'{self.facts.sudo_prefix} {default_reboot_command.to_shell_command()}' + ) command = command or default_reboot_command waiting = waiting or default_reboot_waiting() diff --git a/tmt/steps/context/pidfile.py b/tmt/steps/context/pidfile.py index 80fd9a30ce..8d1487a9f4 100644 --- a/tmt/steps/context/pidfile.py +++ b/tmt/steps/context/pidfile.py @@ -102,13 +102,8 @@ OUTER_WRAPPER_TEMPLATE = jinja2.Template(""" {% macro log_to_dmesg(msg) %} {%- if not GUEST.facts.is_superuser %} - {%- if GUEST.become %} # Logging test into kernel log -sudo bash -c "echo \\\"{{ msg }}\\\" > /dev/kmsg" - {%- else %} -# Not logging into kernel log: not a superuser, 'become' not enabled -# echo \"{{ msg }}\" > /dev/kmsg - {%- endif %} +{{ GUEST.facts.sudo_prefix }} bash -c "echo \\\"{{ msg }}\\\" > /dev/kmsg" {%- else %} # Logging test into kernel log echo "{{ msg }}" > /dev/kmsg diff --git a/tmt/steps/prepare/shell.py b/tmt/steps/prepare/shell.py index 0a8e604760..4fe15c17e8 100644 --- a/tmt/steps/prepare/shell.py +++ b/tmt/steps/prepare/shell.py @@ -250,9 +250,7 @@ def _invoke_script( pull_options.exclude.append(str(script_log_filepath)) if guest.become and not guest.facts.is_superuser: - command = tmt.utils.ShellScript( - f'{guest.facts.sudo_prefix} {script.to_shell_command()}' - ) + command = tmt.utils.ShellScript(f'sudo -E {script.to_shell_command()}') else: command = script