Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/provision/connect/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/provision/reboot/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/test/check/test-journal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tmt/guest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
""",
)

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions tmt/steps/context/pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tmt/steps/prepare/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}')
Comment thread
happz marked this conversation as resolved.
Comment thread
happz marked this conversation as resolved.
else:
command = script

Expand Down
Loading