Skip to content

Commit

Permalink
Merge pull request #16364 from DeepthiYV/post_fail_hooks
Browse files Browse the repository at this point in the history
Refactor the post_fail_hook functionality
  • Loading branch information
foursixnine authored Mar 30, 2023
2 parents a7cbebc + bb2c901 commit 534229e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
12 changes: 4 additions & 8 deletions lib/Utils/Logging.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use testapi;
use utils qw(clear_console show_oom_info remount_tmp_if_ro detect_bsc_1063638);
use Utils::Systemd 'get_started_systemd_services';
use Mojo::File 'path';
use serial_terminal 'select_serial_terminal';

our @EXPORT = qw(
save_and_upload_log
Expand Down Expand Up @@ -183,9 +184,7 @@ This method will call several other log gathering methods from this class.
=cut

sub export_logs {
select_log_console();
save_screenshot();
show_oom_info();
select_serial_terminal();
remount_tmp_if_ro();
export_logs_basic();
problem_detection();
Expand All @@ -194,8 +193,6 @@ sub export_logs {
save_and_upload_log("ip addr show", "/tmp/ip-addr-show.log");
save_and_upload_log("cat /etc/resolv.conf", "/tmp/resolv-conf.log");

save_screenshot();

export_logs_desktop();

save_and_upload_log('systemctl list-unit-files', '/tmp/systemctl_unit-files.log');
Expand Down Expand Up @@ -336,8 +333,7 @@ Upload several KDE, GNOME, X11, GDM and SDDM related logs and configs.
=cut

sub export_logs_desktop {
select_log_console;
save_screenshot;
select_serial_terminal();

if (check_var("DESKTOP", "kde")) {
if (get_var('PLASMA5')) {
Expand All @@ -346,7 +342,7 @@ sub export_logs_desktop {
else {
tar_and_upload_log("/home/$username/.kde4/share/config/*rc", '/tmp/kde4_configs.tar.bz2');
}
save_screenshot;
#save_screenshot;
} elsif (check_var("DESKTOP", "gnome")) {
tar_and_upload_log("/home/$username/.cache/gdm", '/tmp/gdm.tar.bz2');
}
Expand Down
7 changes: 3 additions & 4 deletions lib/consoletest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ sub post_fail_hook {
$self->SUPER::post_fail_hook;
# at this point the instance is shutdown
return if (is_public_cloud() || is_openstack());
# Remaining log functions are executed in Utils::Logging::export_logs()
# called in opensusebasetest::post_fail_hook()
select_console('log-console');
remount_tmp_if_ro;
show_oom_info;
show_tasks_in_blocked_state;
export_logs_basic;
# Export extra log after failure for further check gdm issue 1127317, also poo#45236 used for tracking action on Openqa
export_logs_desktop;
}

=head2 record_avc_selinux_alerts
Expand Down
20 changes: 3 additions & 17 deletions lib/opensusebasetest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use IO::Socket::INET;
use x11utils qw(handle_login ensure_unlocked_desktop handle_additional_polkit_windows);
use publiccloud::ssh_interactive 'select_host_console';
use Utils::Logging qw(save_and_upload_log tar_and_upload_log export_healthcheck_basic select_log_console upload_coredumps export_logs);
use serial_terminal 'select_serial_terminal';

# Base class for all openSUSE tests

Expand Down Expand Up @@ -963,29 +964,25 @@ base method using C<$self-E<gt>SUPER::post_fail_hook;> at the end.

sub post_fail_hook {
my ($self) = @_;
return if is_serial_terminal(); # unless VIRTIO_CONSOLE=0 nothing below make sense

show_tasks_in_blocked_state;

return if (get_var('NOLOGS'));

# Upload basic health check log
select_log_console;
select_serial_terminal();
export_healthcheck_basic;

# set by x11_start_program
if (get_var('IN_X11_START_PROGRAM')) {
my ($program) = get_var('IN_X11_START_PROGRAM') =~ m/(\S+)/;
set_var('IN_X11_START_PROGRAM', undef);
select_log_console;

my $r = script_run "which $program";
if ($r != 0) {
record_info("no $program", "Could not find '$program' on the system", result => 'fail');
}
}

if (get_var('FULL_LVM_ENCRYPT') && get_var('LVM_THIN_LV')) {
select_console 'root-console';
my $lvmdump_regex = qr{/root/lvmdump-.*?-\d+\.tgz};
my $out = script_output('lvmdump', proceed_on_failure => 1);
if ($out =~ /(?<lvmdump_gzip>$lvmdump_regex)/) {
Expand All @@ -995,7 +992,6 @@ sub post_fail_hook {
}

if (get_var('COLLECT_COREDUMPS')) {
select_console 'root-console';
upload_coredumps(proceed_on_failure => 1);
}

Expand All @@ -1007,20 +1003,10 @@ sub post_fail_hook {
}
# Find out in post-fail-hook if system is I/O-busy, poo#35877
else {
select_log_console;
my $io_status = script_output("sed -n 's/^.*da / /p' /proc/diskstats | cut -d' ' -f10");
record_info('System I/O status:', ($io_status =~ /^0$/) ? 'idle' : 'busy');
}

# In case the system is stuck in shutting down or during boot up, press
# 'esc' just in case the plymouth splash screen is shown and we can not
# see any interesting console logs.
send_key 'esc';
save_screenshot;
# the space prevents the esc from eating up the next alphanumerical
# character typed into the console
send_key 'spc';

export_logs;

if ((is_public_cloud() || is_openstack()) && $self->{run_args}->{my_provider}) {
Expand Down
6 changes: 4 additions & 2 deletions lib/x11test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use x11utils qw(select_user_gnome start_root_shell_in_xterm handle_gnome_activit
use POSIX 'strftime';
use mm_network;
use Utils::Logging qw(export_healthcheck_basic select_log_console export_logs_basic export_logs_desktop);
use serial_terminal 'select_serial_terminal';

sub post_run_hook {
my ($self) = @_;
Expand All @@ -29,12 +30,13 @@ sub post_run_hook {

sub post_fail_hook {
return if (get_var('NOLOGS'));
select_log_console;
select_serial_terminal();
export_healthcheck_basic;
show_tasks_in_blocked_state;
export_logs_basic;
# Export extra log after failure for further check gdm issue 1127317, also poo#45236 used for tracking action on Openqa
export_logs_desktop;
select_log_console;
show_tasks_in_blocked_state;
}

sub dm_login {
Expand Down

0 comments on commit 534229e

Please sign in to comment.