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 9, 2022
1 parent 1dcc3f8 commit 36fc04a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,18 @@ sub zypper_call {
}
last;
}
my @packages = grep(/^[^-]/, split(" ", $command));
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
});
}
upload_logs("/tmp/$log") if $log;

unless (grep { $_ == $ret } @$allow_exit_codes) {
Expand Down
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 36fc04a

Please sign in to comment.