Skip to content

Commit

Permalink
Capture installed and uninstalled packages during test
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Aug 10, 2022
1 parent 1dcc3f8 commit 2992e19
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,31 @@ sub zypper_call {
}
last;
}

# log all install and remove actions for later use by tests/console/zypper_log_packages.pm
my @packages = split(" ", $command);
for (my $i = 0; $i < scalar(@packages); $i++) {
if ($packages[$i] eq "--root" || $packages[$i] eq "-R") {
splice(@packages, $i, 2);
}
}
@packages = grep(/^[^-]/, @packages);
my $zypper_action = shift(@packages);
$zypper_action = "install" if ($zypper_action eq "in");
$zypper_action = "remove" if ($zypper_action eq "rm");
if ($zypper_action =~ m/^(install|remove)$/) {
push(@{$testapi::distri->{zypper_packages}}, {
raw_command => $command,
action => $zypper_action,
packages => \@packages,
return_code => $ret,
test => {
module => $autotest::current_test->{name},
category => $autotest::current_test->{category}
}
});
}

upload_logs("/tmp/$log") if $log;

unless (grep { $_ == $ret } @$allow_exit_codes) {
Expand Down
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_clamav.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ schedule:
- installation/bootloader_start
- boot/boot_to_desktop
- console/clamav
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_dracut.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ schedule:
- boot/boot_to_desktop
- console/dracut
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_gnome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ schedule:
- console/check_default_network_manager
- '{{python_liblouis}}'
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_gnome_sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ schedule:
- console/consoletest_setup
- x11/libqt5_qtbase
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_gnuhealth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ schedule:
- gnuhealth/gnuhealth_client_install
- gnuhealth/gnuhealth_client_preconfigure
- gnuhealth/gnuhealth_client_first_time
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ schedule:
- console/journalctlLevels
- console/perf
- '{{tw_tests}}'
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_networkd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ schedule:
- networkd/networkd_vlan
- networkd/networkd_bridge
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_ovs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ schedule:
- installation/bootloader_start
- network/setup_multimachine
- '{{ovs}}'
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_qemu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ schedule:
- qemu/qemu
- '{{kvm}}'
- '{{user}}'
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_textmode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ schedule:
- '{{tumbleweed_tests}}'
- console/tar
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_textmode_mod_desktop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ schedule:
- console/consoletest_setup
- '{{tests_requiring_soundcard}}'
- console/libvorbis
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_textmode_phub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ schedule:
- console/vmstat
- console/sssd_389ds_functional
- console/coredump_collect
- console/zypper_log_packages
conditional_schedule:
wpa_supplicant:
ARCH:
Expand Down
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_textmode_sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ schedule:
- boot/boot_to_desktop
- console/gdb
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_toolkits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ schedule:
- x11/toolkits/qt5
- x11/toolkits/swing
- console/coredump_collect
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_transactional_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ schedule:
- transactional/transactional_update
- transactional/rebootmgr
- transactional/health_check
- console/zypper_log_packages
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_webframeworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ schedule:
- console/prepare_test_data
- console/django
- console/flask
- console/zypper_log_packages
50 changes: 50 additions & 0 deletions tests/console/zypper_log_packages.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SUSE's openQA tests
#
# Copyright 2022 SUSE LLC
# SPDX-License-Identifier: FSFAP

# Package: zypper
# Summary: gather info about installed/removed packages during the test
# Maintainer: Dominik Heidler <dheidler@suse.de>

use base "consoletest";
use strict;
use warnings;
use testapi;
use utils;

use Mojo::UserAgent;
use Mojo::JSON qw(to_json);

sub run {
my $self = shift;
$self->select_serial_terminal;
my $zypper_packages = {};
$zypper_packages->{commands} = $testapi::distri->{zypper_packages} // [];
my $individual_pkgs = script_output('grep "|\(Installing:\|Removing\) .*} END" /var/log/zypper.log', proceed_on_failure => 1);
# this looks like this:
# 2022-08-05 12:18:55 <1> athene(13626) [Progress++] progressdata.cc(report):89 {#24|Installing: xosview-1.22-1.10.x86_64} END
# 2022-08-05 12:19:48 <1> athene(13993) [Progress++] progressdata.cc(report):89 {#21|Removing xosview-1.22-1.10.x86_64} END
while ($individual_pkgs =~ m/\|([A-Z][a-z]*):? ([^}]*)}/g) {
my $action;
if ($1 eq "Installing") { $action = "install"; }
elsif ($1 eq "Removing") { $action = "remove"; }
$2 =~ m/(.+)-([^-]+)-([^-]+)\.([^.]+)/;
push(@{$zypper_packages->{individual_pkgs}}, {
action => $action,
package => $1,
version => $2,
release => $3,
arch => $4,
});
}

my $ua = Mojo::UserAgent->new;
my $res = $ua->post(autoinst_url("/uploadlog/zypper_packages.json") => form => {
upload => {content => to_json($zypper_packages)},
uname => "zypper_packages.json"
})->result;
record_info('zypper_packages.json', 'zypper_packages.json was uploaded via worker', result => ($res->is_success) ? 'ok' : 'fail');
}

1;

0 comments on commit 2992e19

Please sign in to comment.