Skip to content

Commit

Permalink
Replace all uses of obsolete "script_run(..., die_on_timeout => 0)"
Browse files Browse the repository at this point in the history
The call `script_run(..., die_on_timeout => 0)` is deprecated and soon to be
removed from os-autoinst. This commit replaces all such calls with an
alternative. In many cases "die_on_timeout => 0" is not actually needed or
not necessary anymore after underlying bugs are fixed so in those cases I
simply remove the parameter without further changes. In other cases I am
using an alternative, e.g. using the Linux internal "timeout" command
prefixed.
  • Loading branch information
okurz committed Aug 9, 2024
1 parent b244b4b commit 2cf6d19
Show file tree
Hide file tree
Showing 25 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lib/btrfs_test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ it means that DBus got activated somehow, thus invalidated `snapper --no-dbus` t
sub snapper_nodbus_restore {
my $ret = script_run('systemctl is-active dbus', timeout => 300);
die 'DBus service should be inactive, but it is active' if ($ret == 0);
script_run('systemctl default', timeout => 600, die_on_timeout => 0);
script_run('systemctl default', timeout => 600);
my $tty = get_root_console_tty;

if (is_sle('<15-SP3') && !defined(my $match = check_screen("tty$tty-selected", 120))) {
Expand Down
2 changes: 1 addition & 1 deletion lib/db_utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ sub check_postgres_db {
# Empty records will return '{"results":[{"statement_id":0}]}'
# Existing records will return '{"results":[{"statement_id":0,"series":[{"name":"size","columns":["time","value"],"values"' ...
my $request = "curl -IfLv 'http://$db_ip:$db_port/$db_db'";
if (script_run("$request 2>&1 >/var/tmp/db_curl.tmp", timeout => 120, die_on_timeout => 0) != 0) {
if (script_run("timeout 100 $request 2>&1 >/var/tmp/db_curl.tmp", timeout => 120) != 0) {
my $output = script_output("cat /var/tmp/db_curl.tmp");
record_info("db error", "cannot reach POSTGREST database\n$request\n$output", result => 'fail');
return 0;
Expand Down
5 changes: 3 additions & 2 deletions lib/guest_installation_and_configuration_base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2572,9 +2572,10 @@ sub start_guest_installation {
my $_guest_installation_log = "$common_log_folder/$self->{guest_name}/$self->{guest_name}" . "_installation_log_" . $_start_installation_timestamp;
assert_script_run("touch $_guest_installation_log && chmod 777 $_guest_installation_log");
# Dry run always timeout when downloading initrd from download.opensuse.org in O3
my $ret = script_run("set -o pipefail; $self->{virt_install_command_line_dryrun} 2>&1 | tee -a $_guest_installation_dryrun_log", timeout => 600 / get_var('TIMEOUT_SCALE', 1), die_on_timeout => 0);
my $ret = script_run("set -o pipefail; timeout 580 $self->{virt_install_command_line_dryrun} 2>&1 | tee -a $_guest_installation_dryrun_log", timeout => 600);
save_screenshot;
unless (defined(script_run('set +o pipefail', die_on_timeout => 0))) {
enter_cmd "set +o pipefail; echo DONE > /dev/$serialdev";
unless (defined(wait_serial('DONE', timeout => 30))) {
reconnect_when_ssh_console_broken;
script_run("set +o pipefail");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/migration.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sub setup_sle {

# Enable Y2DEBUG for error debugging
enter_cmd "echo 'export Y2DEBUG=1' >> /etc/bash.bashrc.local";
script_run("source /etc/bash.bashrc.local", die_on_timeout => 0);
script_run("source /etc/bash.bashrc.local");
set_zypp_single_rpmtrans();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/publiccloud/azure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ sub cleanup {

if (!check_var('PUBLIC_CLOUD_SLES4SAP', 1) && defined($args->{my_instance}->{instance_id})) {
my $id = $args->{my_instance}->{instance_id};
script_run("az vm boot-diagnostics get-boot-log --ids $id | jq -r '.' > bootlog.txt", timeout => 120, die_on_timeout => 0);
script_run("timeout 110 az vm boot-diagnostics get-boot-log --ids $id | jq -r '.' > bootlog.txt", timeout => 120);
upload_logs("bootlog.txt", failok => 1);
}
$self->SUPER::cleanup();
Expand Down
2 changes: 1 addition & 1 deletion lib/services/registered_addons.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sub check_registered_system {
}
suseconnect_ls($pro);
my $ver = $system =~ s/\-SP/./r;
script_run("SUSEConnect -s | grep " . $ver, die_on_timeout => 0);
script_run("timeout 20 SUSEConnect -s | grep " . $ver);
}

sub check_registered_addons {
Expand Down
3 changes: 2 additions & 1 deletion lib/sles4sap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ sub prepare_profile {

if ($has_saptune) {
assert_script_run 'saptune service takeover';
my $ret = script_run("saptune solution verify $profile", die_on_timeout => 0);
enter_cmd "saptune solution verify $profile; echo DONE-$\? > /dev/$serialdev";
my $ret = wait_serial qr/DONE-\d/, timeout => 30;
if (!defined $ret) {
# Command timed out. 'saptune service takeover' could have caused the SUT to
# move out of root-console, so select root-console and try again
Expand Down
2 changes: 1 addition & 1 deletion lib/transactional.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ sub trup_call {
$ret = script_finish_io(timeout => $args{timeout});
}
else {
$ret = script_run($script, timeout => $args{timeout}, die_on_timeout => 0);
$ret = script_run($script, timeout => $args{timeout});
}

if ($args{proceed_on_failure}) {
Expand Down
4 changes: 3 additions & 1 deletion lib/virt_autotest/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ sub check_failures_in_journal {
record_soft_failure("Found new failures: " . $failures . " please take actions as described in poo#151361.\n");
record_info("Found failures in journal log", "Found new failures: " . $failures . " please take actions as described in poo#151361.\n", result => 'fail');
}
script_run("rsync root\@$machine:$logfile $logfile", die_on_timeout => 0) if $machine ne 'localhost';
# ignore the attempt timing out with "timeout 20" which exits before
# the script_run internal timeout
script_run("timeout 20 rsync root\@$machine:$logfile $logfile") if $machine ne 'localhost';
upload_logs($logfile);
}
return $failures;
Expand Down
20 changes: 10 additions & 10 deletions lib/virt_feature_test_base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ sub run_test {
die('Please override this subroutine in children modules to run desired tests.');
}

sub reconnect_if_problematic {
enter_cmd "rm -f /root/{commands_history,commands_failure}; echo DONE > /dev/$serialdev";
unless (defined(wait_serial('DONE', timeout => 30))) {
reconnect_when_ssh_console_broken;
alp_workloads::kvm_workload_utils::enter_kvm_container_sh if is_alp;
}
}

sub prepare_run_test {
my $self = shift;

select_console 'sol', await_console => 0;
use_ssh_serial_console;

unless (defined(script_run("rm -f /root/{commands_history,commands_failure}", die_on_timeout => 0))) {
reconnect_when_ssh_console_broken;
alp_workloads::kvm_workload_utils::enter_kvm_container_sh if is_alp;
}
reconnect_if_problematic;
assert_script_run("history -c");

check_host_health;
Expand Down Expand Up @@ -179,11 +183,7 @@ sub post_fail_hook {
my ($self) = shift;

$self->{"stop_run"} = time();
unless (defined(script_run("rm -f /root/{commands_history,commands_failure}", die_on_timeout => 0))) {
reconnect_when_ssh_console_broken;
alp_workloads::kvm_workload_utils::enter_kvm_container_sh if is_alp;
}

reconnect_if_problematic;
check_host_health;
virt_utils::stop_monitor_guest_console() if (!(get_var("TEST", '') =~ /qam/) && (is_xen_host() || is_kvm_host()));
#(caller(0))[3] can help pass calling subroutine name into called subroutine
Expand Down
4 changes: 2 additions & 2 deletions lib/wickedbase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,8 @@ sub wait_for_background_process {
my ($self, $pid, %args) = @_;
$args{proceed_on_failure} //= 0;

my $ret = script_run("wait $pid", die_on_timeout => 0, %args);
unless (defined($ret)) {
my $ret = script_run("waitpid --timeout 25 $pid", %args);
if ($ret == 3) { # timeout
if (is_serial_terminal()) {
type_string(qq(\cc));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/x11utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ Disable screensaver in gnome. To be called from a command prompt, for example an
=cut

sub turn_off_gnome_screensaver {
script_run 'gsettings set org.gnome.desktop.session idle-delay 0', die_on_timeout => 0, timeout => 90;
script_run 'timeout 80 gsettings set org.gnome.desktop.session idle-delay 0', timeout => 90;
}

=head2 turn_off_gnome_screensaver_for_gdm
Expand Down
2 changes: 1 addition & 1 deletion tests/console/btrfs_qgroups.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ sub run {
record_soft_failure 'File overwrite test: bsc#1113042 - btrfs is not informed to commit transaction';
}
# write some more times to the same file to be sure
if (script_run("for c in {1..38}; do $write_chunk; done", die_on_timeout => 0)) {
if (script_run("timeout 20 sh -c \"for c in {1..38}; do $write_chunk; done\"")) {
record_soft_failure 'File overwrite test: bsc#1113042 - btrfs is not informed to commit transaction';
}
assert_script_run 'sync';
Expand Down
2 changes: 1 addition & 1 deletion tests/containers/bci_prepare.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sub packages_to_install {
my $bci_virtualenv = get_var('BCI_VIRTUALENV', 0);

# Avoid PackageKit to conflict about lock with zypper
script_run("pkcon quit", die_on_timeout => 0) if (is_sle || is_opensuse);
script_run("timeout 20 pkcon quit") if (is_sle || is_opensuse);

# common packages
my @packages = ('git-core', 'python3', 'gcc', 'jq');
Expand Down
2 changes: 1 addition & 1 deletion tests/ha/ha_cluster_crash_test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ sub run {
# Execute the command
my $cmd = "crm cluster crash_test --$check --force";
record_info($check, "Executing $cmd");
my $cmd_fails = script_run($cmd, die_on_timeout => 0);
my $cmd_fails = script_run("timeout 20 $cmd");

# Killing pacemaker should result in service restart
# All remaining commands lead to a reboot of the node
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/run_ltp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ sub upload_tcpdump {
$old_console = current_console();
select_console('root-console');

unless (defined(script_run("kill -s INT $pid && while [ -d /proc/$pid ]; do usleep 100000; done", die_on_timeout => 0))) {
unless (defined(script_run("timeout 20 sh -c \"kill -s INT $pid && while [ -d /proc/$pid ]; do usleep 100000; done\""))) {
select_console($old_console, await_console => 0);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/migration/setup_sle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub run {

# Stop packagekitd
quit_packagekit;
script_run("source /etc/bash.bashrc.local", die_on_timeout => 0);
script_run("source /etc/bash.bashrc.local");
}

1;
2 changes: 1 addition & 1 deletion tests/qam-updinstall/update_install.pm
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ sub run {

# merge logs from all patches into one which is testreport template expecting
foreach (qw(prepare zypper new)) {
next if script_run("ls /tmp|grep ${_}_", die_on_timeout => 0);
next if script_run("timeout 20 ls /tmp|grep ${_}_");
assert_script_run("cat /tmp/$_* > /tmp/$_.log");
upload_logs("/tmp/$_.log");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/security/selinux/enforcing_mode_setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ sub run {

# label system
assert_script_run("semanage boolean --modify --on selinuxuser_execmod");
script_run("restorecon -R /", timeout => 1800, die_on_timeout => 0);
script_run("restorecon -R /*", timeout => 1800, die_on_timeout => 0);
script_run("timeout 1780 restorecon -R /", timeout => 1800);
script_run("timeout 1780 restorecon -R /*", timeout => 1800);

# enable enforcing mode from SELinux
replace_grub_cmdline_settings('security=selinux selinux=1 enforcing=0', 'security=selinux selinux=1 enforcing=1', update_grub => 1);
Expand Down
14 changes: 6 additions & 8 deletions tests/virt_autotest/guest_upgrade_run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,19 @@ sub run {
my $self = shift;
my $timeout = get_var('MAX_TEST_TIME', '36000') + 10;
my $upload_log_name = 'guest-upgrade-logs';
if (is_s390x) {
#ues die_on_timeout=> 0 as workaround for s390x test during call script_run, refer to poo#106765
script_run("echo \"Debug info: max_test_time is $timeout\"", die_on_timeout => 0);
} else {
script_run("echo \"Debug info: max_test_time is $timeout\"");
}
enter_cmd "echo \"Debug info: max_test_time is $timeout\"; echo DONE > /dev/$serialdev";
my $ret = wait_serial 'DONE', timeout => 30;
# workaround for s390x test during call script_run, refer to poo#106765
die "Timeout exceeded on wait_serial" unless $ret or is_s390x;
# Modify source configuration file sources.* of virtauto-data pkg on host
# to use openqa daily build installer repo and module repo for guests,
# and it will be copied into guests to be used during guest upgrade test
repl_module_in_sourcefile();

$self->{'package_name'} = 'Guest Upgrade Test';
if (is_s390x) {
#ues die_on_timeout=> 0 as workaround for s390x test during call script_run, refer to poo#106765
script_run "[ -d /var/log/qa/ctcs2 ] && rm -r /var/log/qa/ctcs2 ; [ -d /var/lib/libvirt/images/prj4_guest_upgrade ] && rm -r /var/lib/libvirt/images/prj4_guest_upgrade /tmp/full_guest_upgrade_test-* /tmp/kill_zypper_procs-* /tmp/update-guest-*", die_on_timeout => 0;
enter_cmd "[ -d /var/log/qa/ctcs2 ] && rm -r /var/log/qa/ctcs2 ; [ -d /var/lib/libvirt/images/prj4_guest_upgrade ] && rm -r /var/lib/libvirt/images/prj4_guest_upgrade /tmp/full_guest_upgrade_test-* /tmp/kill_zypper_procs-* /tmp/update-guest-*; echo DONE > /dev/$serialdev";
wait_serial 'DONE', timeout => 30;
}
else {
$self->execute_script_run("[ -d /var/log/qa/ctcs2 ] && rm -r /var/log/qa/ctcs2 ; [ -d /tmp/prj4_guest_upgrade ] && rm -r /tmp/prj4_guest_upgrade", 30);
Expand Down
8 changes: 4 additions & 4 deletions tests/virt_autotest/sriov_network_card_pci_passthrough.pm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ sub run_test {
assert_script_run("virsh nodedev-reattach $vfs[$i]->{host_id}", 60);
record_info("Reattach VF to host", "vm=$guest \nvf=$vfs[$i]->{host_id}");
save_network_device_status_logs($guest, $passthru_vf_count + 4 + $i . "-after_hot_unplug_$vfs[$i]->{host_id}");
script_run("ssh root\@$guest 'dmesg' >> $log_dir/dmesg_$guest 2>&1", die_on_timeout => 0) if $i == $passthru_vf_count - 1;
script_run("timeout 20 ssh root\@$guest 'dmesg' >> $log_dir/dmesg_$guest 2>&1") if $i == $passthru_vf_count - 1;
}
script_run "lspci | grep Ethernet";
save_screenshot;
Expand Down Expand Up @@ -390,7 +390,7 @@ sub save_network_device_status_logs {
my ($vm, $test_step) = @_;

#vm configuration file
script_run("virsh dumpxml $vm > $log_dir/${vm}_${test_step}.xml", die_on_timeout => 0);
script_run("timeout 20 virsh dumpxml $vm > $log_dir/${vm}_${test_step}.xml");

my $log_file = "log.txt";
script_run "echo `date` > $log_file";
Expand All @@ -402,7 +402,7 @@ sub save_network_device_status_logs {
script_run "echo '***** Status & logs inside $vm *****' >> $log_file";
my $debug_script = "sriov_network_guest_logging.sh";
download_script($debug_script, machine => $vm, proceed_on_failure => 1) if (${test_step} eq "1-initial");
script_run("ssh root\@$vm \"~/$debug_script\" >> $log_file 2>&1", die_on_timeout => 0);
script_run("timeout 20 ssh root\@$vm \"~/$debug_script\" >> $log_file 2>&1");

script_run "mv $log_file $log_dir/${vm}_${test_step}_network_device_status.txt";

Expand All @@ -414,7 +414,7 @@ sub post_fail_hook {
diag("Module sriov_network_card_pci_passthrough post fail hook starts.");
foreach (keys %virt_autotest::common::guests) {
save_network_device_status_logs($_, "post_fail_hook");
script_run("ssh root\@$_ 'dmesg' >> $log_dir/dmesg_$_ 2>&1", die_on_timeout => 0);
script_run("timeout 20 ssh root\@$_ 'dmesg' >> $log_dir/dmesg_$_ 2>&1");
check_guest_health($_);
}
virt_autotest::utils::upload_virt_logs($log_dir, "network_device_status");
Expand Down
5 changes: 3 additions & 2 deletions tests/virt_autotest/validate_system_health.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sub run {
@health_status{(keys %virt_autotest::common::guests)} = ();
$health_status{host} = check_host_health;
foreach my $guest (grep { $_ ne 'host' } keys %health_status) {
script_run("virsh start $guest", die_on_timeout => 0);
script_run("timeout 20 virsh start $guest");
if (script_retry("nmap $guest -PN -p ssh | grep open", delay => 2, retry => 60, die => 0) == 0) {
$health_status{$guest} = check_guest_health($guest);
}
Expand Down Expand Up @@ -55,7 +55,8 @@ sub run {
sub post_fail_hook {
my $self = shift;
diag("Module validate_system_health post fail hook starts.");
unless (defined(script_run("rm -f /root/{commands_history,commands_failure}", die_on_timeout => 0))) {
enter_cmd "rm -f /root/{commands_history,commands_failure}; echo DONE > /dev/$serialdev";
unless (defined(wait_serial 'DONE', timeout => 30)) {
reconnect_when_ssh_console_broken;
alp_workloads::kvm_workload_utils::enter_kvm_container_sh if is_alp;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/x11/rmt/rmt_chinese.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sub set_language_to_Chinese {
x11_start_program('xterm');
wait_still_screen 2, 2;
become_root;
script_run('yast2 language', die_on_timeout => 0);
enter_cmd 'yast2 language';
assert_screen 'yast2-language', 60;
send_key_until_needlematch 'yast2-lang-simplified-chinese', 'down', 181;
send_key 'alt-o';
Expand Down
4 changes: 2 additions & 2 deletions tests/xfstests/generate_report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ sub run {
# Reload uploaded status log back to file
my $log_line = int(script_output("cat $STATUS_LOG | wc -l"));
if ($log_line < 2) {
script_run('df -h; curl -O ' . autoinst_url . "/files/status.log; cat status.log > $STATUS_LOG", die_on_timeout => 0);
script_run('df -h; timeout 20 curl -O ' . autoinst_url . "/files/status.log; cat status.log > $STATUS_LOG");
}

# Reload test logs if check missing
script_run("if [ ! -d $LOG_DIR ]; then mkdir -p $LOG_DIR; curl -O " . autoinst_url . '/files/opt_logs.tar.gz; tar zxvfP opt_logs.tar.gz; fi', die_on_timeout => 0);
script_run("if [ ! -d $LOG_DIR ]; then mkdir -p $LOG_DIR; timeout 20 curl -O " . autoinst_url . '/files/opt_logs.tar.gz; tar zxvfP opt_logs.tar.gz; fi');

# Finalize status log and upload it
log_end($STATUS_LOG);
Expand Down
4 changes: 2 additions & 2 deletions tests/xfstests/run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ sub run {
#Save status log before next step(if run.pm fail will load into a last good snapshot)
save_tmp_file('status.log', $status_log_content);
my $local_file = "/tmp/opt_logs.tar.gz";
script_run("tar zcvf $local_file --absolute-names /opt/log/", timeout => 600, die_on_timeout => 0);
script_run("timeout 580 tar zcvf $local_file --absolute-names /opt/log/", timeout => 600);
upload_logs($local_file, failok => 1, timeout => 180);
}

Expand All @@ -624,7 +624,7 @@ sub test_flags {
sub post_fail_hook {
my ($self) = shift;
# Collect executed test logs
script_run('tar zcvf /tmp/opt_logs.tar.gz --absolute-names /opt/log/', timeout => 600, die_on_timeout => 0);
script_run('timeout 580 tar zcvf /tmp/opt_logs.tar.gz --absolute-names /opt/log/', timeout => 600);
upload_logs('/tmp/opt_logs.tar.gz', failok => 1, timeout => 180);
}

Expand Down

0 comments on commit 2cf6d19

Please sign in to comment.