Skip to content

Commit

Permalink
Skip $self in opensusebasetest::select_serial_terminal
Browse files Browse the repository at this point in the history
The $self parameter in opensusebasetest::select_serial_console is not
used in the subroutine. That brings only confusion.

The key change is in lib/serial_terminal.pm
  • Loading branch information
pdostal committed Oct 24, 2022
1 parent 6e0a2d5 commit d1a53e4
Show file tree
Hide file tree
Showing 458 changed files with 1,066 additions and 610 deletions.
5 changes: 3 additions & 2 deletions lib/Tomcat/ModjkTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use base "x11test";
use strict;
use warnings;
use testapi;
use serial_terminal 'select_serial_terminal';
use utils;
use version_utils 'is_sle';
use registration;
Expand All @@ -21,7 +22,7 @@ use registration;
# via the package apache2-mod_jk
sub mod_jk_setup() {
my $self = shift;
$self->select_serial_terminal();
select_serial_terminal();

record_info('install and configure apache2 and apache2-mod_jk connector Setup');
zypper_call('in apache2 apache2-mod_jk');
Expand All @@ -33,7 +34,7 @@ sub mod_jk_setup() {
# Connection from apache2 to tomcat: Functionality test
sub func_conn_apache2_tomcat() {
my $self = shift;
$self->select_serial_terminal();
select_serial_terminal();
systemctl('stop apache2');
systemctl('stop tomcat');
assert_script_run(
Expand Down
5 changes: 3 additions & 2 deletions lib/hpcbase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package hpcbase;
use Mojo::Base 'opensusebasetest';
use testapi;
use serial_terminal 'select_serial_terminal';
use utils;
use Utils::Architectures;
use version_utils 'is_sle';
Expand Down Expand Up @@ -108,7 +109,7 @@ sub post_run_hook {
sub post_fail_hook {
my ($self) = @_;
$self->destroy_test_barriers();
$self->select_serial_terminal;
select_serial_terminal;
script_run("SUSEConnect --status-text");
script_run("journalctl -o short-precise > /tmp/journal.log");
script_run('cat /tmp/journal.log');
Expand Down Expand Up @@ -350,7 +351,7 @@ sub prepare_spack_env {
$mpi //= 'mpich';
zypper_call "in spack $mpi-gnu-hpc $mpi-gnu-hpc-devel";
type_string('pkill -u root'); # this kills sshd
$self->select_serial_terminal(0);
select_serial_terminal(0);
assert_script_run 'module load gnu $mpi'; ## TODO
assert_script_run 'source /usr/share/spack/setup-env.sh';
record_info 'spack', script_output 'zypper -q info spack';
Expand Down
3 changes: 2 additions & 1 deletion lib/jeos.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package jeos;
use Mojo::Base qw(Exporter);
use testapi;
use serial_terminal 'select_serial_terminal';
use utils qw(ensure_serialdev_permissions);
use power_action_utils qw(power_action);
use Utils::Backends qw(is_hyperv);
Expand All @@ -21,7 +22,7 @@ sub reboot_image {
power_action('reboot', textmode => 1);
record_info('reboot', $msg);
$self->wait_boot(bootloader_time => 150);
$self->select_serial_terminal;
select_serial_terminal;
ensure_serialdev_permissions;
}

Expand Down
81 changes: 0 additions & 81 deletions lib/opensusebasetest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1263,87 +1263,6 @@ sub remount_tmp_if_ro {
script_run 'touch /tmp/test_ro || mount -t tmpfs /dev/shm /tmp';
}

=head2 select_serial_terminal
select_serial_terminal($root);
Select most suitable text console. The optional parameter C<root> controls
whether the console will have root privileges or not. Passing any value that
evaluates to true will select a root console (default). Passing any value that
evaluates to false will select unprivileged user console.
The choice is made by BACKEND and other variables.
Purpose of this wrapper is to avoid if/else conditions when selecting console.
Optional C<root> parameter specifies, whether use root user (C<root>=1, also
default when parameter not specified) or prefer non-root user if available.
Variables affecting behavior:
C<VIRTIO_CONSOLE>=0 disables virtio console (use {root,user}-console instead
of the default {root-,user-}virtio-terminal)
NOTE: virtio console is enabled by default (C<VIRTIO_CONSOLE>=1).
For ppc64le it requires to call prepare_serial_console() to before first use
(used in console/system_prepare and shutdown/cleanup_before_shutdown modules)
and console=hvc0 in kernel parameters (add it to autoyast profile or update
grub setup manually with add_grub_cmdline_settings()).
C<SERIAL_CONSOLE>=0 disables serial console (use {root,user}-console instead
of the default {root-,}sut-serial)
NOTE: serial console is disabled by default on all but s390x machines
(C<SERIAL_CONSOLE>=0), because it's not working yet on other machines
(see poo#55985).
For s390x it requires console=ttysclp0 in kernel parameters (add it to autoyast
profile or update grub setup manually with add_grub_cmdline_settings()).
On ikvm|ipmi|spvm|pvm_hmc it's expected, that use_ssh_serial_console() has been called
(done via activate_console()) therefore SERIALDEV has been set and we can
use root-ssh console directly.
=cut

sub select_serial_terminal {
my ($self, $root) = @_;
$root //= 1;

my $backend = get_required_var('BACKEND');
my $console;

if ($backend eq 'qemu') {
if (check_var('VIRTIO_CONSOLE', 0)) {
$console = $root ? 'root-console' : 'user-console';
} else {
$console = $root ? 'root-virtio-terminal' : 'user-virtio-terminal';
}
} elsif (get_var('SUT_IP')) {
$console = $root ? 'root-serial-ssh' : 'user-serial-ssh';
} elsif ($backend eq 'svirt') {
if (check_var('SERIAL_CONSOLE', 0)) {
$console = $root ? 'root-console' : 'user-console';
} else {
$console = $root ? 'root-sut-serial' : 'sut-serial';
}
} elsif (has_serial_over_ssh) {
$console = 'root-ssh';
} elsif (($backend eq 'generalhw' && !has_serial_over_ssh) || $backend eq 's390x') {
$console = $root ? 'root-console' : 'user-console';
}

die "No support for backend '$backend', add it" if (!defined $console) || ($console eq '');
select_console($console);
}

=head2 select_user_serial_terminal
select_user_serial_terminal();
Select most suitable text console with non-root user.
The choice is made by BACKEND and other variables.
=cut

sub select_user_serial_terminal {
my ($self) = @_;
$self->select_serial_terminal(0);
}

=head2 upload_coredumps
upload_coredumps(%args);
Expand Down
3 changes: 2 additions & 1 deletion lib/publiccloud/k8sbasetest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package publiccloud::k8sbasetest;
use Mojo::Base 'publiccloud::basetest';
use utils 'script_retry';
use testapi;
use serial_terminal 'select_serial_terminal';
use warnings;
use strict;
use utils qw(random_string);
Expand All @@ -24,7 +25,7 @@ Prepare the provider and install kubectl
sub init {
my ($self, %args) = @_;

$self->select_serial_terminal;
select_serial_terminal;
install_kubectl();

$args{provider} //= get_required_var('PUBLIC_CLOUD_PROVIDER');
Expand Down
3 changes: 2 additions & 1 deletion lib/publiccloud/ssh_interactive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package publiccloud::ssh_interactive;
use testapi qw(is_serial_terminal);
use base Exporter;
use testapi;
use serial_terminal 'select_serial_terminal';
use Utils::Backends qw(set_sshserial_dev unset_sshserial_dev);
use version_utils qw(is_tunneled);
use strict;
Expand Down Expand Up @@ -116,7 +117,7 @@ sub select_host_console {
ssh_interactive_leave();
}
set_var('TUNNELED', 0);
opensusebasetest::select_serial_terminal();
select_serial_terminal();
# ssh termination sequence to ensure any ssh connections we're in are terminated
type_string("\n~.\n", max_interval => 1); # send the ssh termination sequence to ensure no previous ssh connection is present
set_var('TUNNELED', $tunneled);
Expand Down
5 changes: 3 additions & 2 deletions lib/selinuxtest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package selinuxtest;
use strict;
use warnings;
use testapi;
use serial_terminal 'select_serial_terminal';
use utils;
use Utils::Backends 'is_pvm';
use bootloader_setup qw(add_grub_cmdline_settings replace_grub_cmdline_settings);
Expand Down Expand Up @@ -108,7 +109,7 @@ sub reboot_and_reconnect {
sub set_sestatus {
my ($self, $mode, $type) = @_;
my $selinux_config_file = '/etc/selinux/config';
$self->select_serial_terminal;
select_serial_terminal;

# workaround for 'selinux-auto-relabel' in case: auto relabel then trigger reboot
my $results = script_run("zypper --non-interactive se selinux-autorelabel");
Expand All @@ -132,7 +133,7 @@ sub set_sestatus {

# reboot the vm and reconnect the console
$self->reboot_and_reconnect(textmode => 1);
$self->select_serial_terminal;
select_serial_terminal;

validate_script_output(
'sestatus',
Expand Down
82 changes: 82 additions & 0 deletions lib/serial_terminal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use 5.018;
use warnings;
use testapi;
use Utils::Architectures;
use Utils::Backends;
use utils;
use autotest;
use base 'Exporter';
Expand All @@ -28,6 +29,8 @@ BEGIN {
set_serial_prompt
serial_term_prompt
upload_file
select_serial_terminal
select_user_serial_terminal
);
our @EXPORT_OK = qw(
reboot
Expand Down Expand Up @@ -287,4 +290,83 @@ sub reboot {
assert_script_run("! test -e '$check_file'");
}

=head2 select_serial_terminal
select_serial_terminal($root);
Select most suitable text console. The optional parameter C<root> controls
whether the console will have root privileges or not. Passing any value that
evaluates to true will select a root console (default). Passing any value that
evaluates to false will select unprivileged user console.
The choice is made by BACKEND and other variables.
Purpose of this wrapper is to avoid if/else conditions when selecting console.
Optional C<root> parameter specifies, whether use root user (C<root>=1, also
default when parameter not specified) or prefer non-root user if available.
Variables affecting behavior:
C<VIRTIO_CONSOLE>=0 disables virtio console (use {root,user}-console instead
of the default {root-,user-}virtio-terminal)
NOTE: virtio console is enabled by default (C<VIRTIO_CONSOLE>=1).
For ppc64le it requires to call prepare_serial_console() to before first use
(used in console/system_prepare and shutdown/cleanup_before_shutdown modules)
and console=hvc0 in kernel parameters (add it to autoyast profile or update
grub setup manually with add_grub_cmdline_settings()).
C<SERIAL_CONSOLE>=0 disables serial console (use {root,user}-console instead
of the default {root-,}sut-serial)
NOTE: serial console is disabled by default on all but s390x machines
(C<SERIAL_CONSOLE>=0), because it's not working yet on other machines
(see poo#55985).
For s390x it requires console=ttysclp0 in kernel parameters (add it to autoyast
profile or update grub setup manually with add_grub_cmdline_settings()).
On ikvm|ipmi|spvm|pvm_hmc it's expected, that use_ssh_serial_console() has been called
(done via activate_console()) therefore SERIALDEV has been set and we can
use root-ssh console directly.
=cut

sub select_serial_terminal {
my $root = shift // 1;

my $backend = get_required_var('BACKEND');
my $console;

if ($backend eq 'qemu') {
if (check_var('VIRTIO_CONSOLE', 0)) {
$console = $root ? 'root-console' : 'user-console';
} else {
$console = $root ? 'root-virtio-terminal' : 'user-virtio-terminal';
}
} elsif (get_var('SUT_IP')) {
$console = $root ? 'root-serial-ssh' : 'user-serial-ssh';
} elsif ($backend eq 'svirt') {
if (check_var('SERIAL_CONSOLE', 0)) {
$console = $root ? 'root-console' : 'user-console';
} else {
$console = $root ? 'root-sut-serial' : 'sut-serial';
}
} elsif (has_serial_over_ssh) {
$console = 'root-ssh';
} elsif (($backend eq 'generalhw' && !has_serial_over_ssh) || $backend eq 's390x') {
$console = $root ? 'root-console' : 'user-console';
}

die "No support for backend '$backend', add it" if (!defined $console) || ($console eq '');
select_console($console);
}

=head2 select_user_serial_terminal
select_user_serial_terminal();
Select most suitable text console with non-root user.
The choice is made by BACKEND and other variables.
=cut

sub select_user_serial_terminal {
select_serial_terminal(0);
}

1;
3 changes: 2 additions & 1 deletion lib/service_check.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package service_check;

use Exporter 'import';
use testapi;
use serial_terminal 'select_serial_terminal';
use Utils::Architectures;
use utils;
use base 'opensusebasetest';
Expand Down Expand Up @@ -259,7 +260,7 @@ Check service before migration, zypper install service package, enable, start an

sub install_services {
my ($service) = @_;
opensusebasetest::select_serial_terminal() if (get_var('SEL_SERIAL_CONSOLE'));
select_serial_terminal() if (get_var('SEL_SERIAL_CONSOLE'));
# turn off lmod shell debug information
assert_script_run('echo export LMOD_SH_DBG_ON=1 >> /etc/bash.bashrc.local');
# turn off screen saver
Expand Down
13 changes: 7 additions & 6 deletions lib/sles4sap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use base "opensusebasetest";
use strict;
use warnings;
use testapi;
use serial_terminal 'select_serial_terminal';
use utils;
use hacluster qw(get_hostname ha_export_logs pre_run_hook save_state wait_until_resources_started);
use isotovideo;
Expand Down Expand Up @@ -267,7 +268,7 @@ sub prepare_profile {
my $ret = systemctl('restart systemd-logind.service', ignore_failure => 1);
die "systemctl restart systemd-logind.service failed with retcode: [$ret]" if $ret;
if (!defined $ret) {
$self->select_serial_terminal;
select_serial_terminal;
systemctl 'restart systemd-logind.service';
}
}
Expand All @@ -290,13 +291,13 @@ sub prepare_profile {
qw(root-console displaymanager displaymanager-password-prompt generic-desktop
text-login linux-login started-x-displaymanager-info)
], 120);
$self->select_serial_terminal unless (match_has_tag 'root-console');
select_serial_terminal unless (match_has_tag 'root-console');
}
else {
# If running in DESKTOP=gnome, systemd-logind restart may cause the graphical
# console to reset and appear in SUD, so need to select 'root-console' again
# 'root-console' can be re-selected safely even if DESKTOP=textmode
$self->select_serial_terminal;
select_serial_terminal;
}

if ($has_saptune) {
Expand All @@ -305,7 +306,7 @@ sub prepare_profile {
if (!defined $ret) {
# Command timed out. 'saptune daemon start' could have caused the SUT to
# move out of root-console, so select root-console and try again
$self->select_serial_terminal;
select_serial_terminal;
$ret = script_run "saptune solution verify $profile";
}
record_soft_failure("poo#57464: 'saptune solution verify' returned warnings or errors! Please check!") if ($ret && !is_qemu());
Expand All @@ -314,7 +315,7 @@ sub prepare_profile {
if (!defined $output) {
# Command timed out or failed. 'saptune solution verify' could have caused
# the SUT to move out of root-console, so select root-console and try again
$self->select_serial_terminal;
select_serial_terminal;
$output = script_output "saptune daemon status";
}
record_info("saptune status", $output);
Expand Down Expand Up @@ -674,7 +675,7 @@ sub reboot {
power_action('reboot', textmode => 1);
$self->wait_boot(nologin => 1, bootloader_time => 300);
}
$self->select_serial_terminal;
select_serial_terminal;
}

=head2 do_hana_sr_register
Expand Down
Loading

0 comments on commit d1a53e4

Please sign in to comment.