Skip to content

Commit

Permalink
Wrapper for zypper_call and trup_call
Browse files Browse the repository at this point in the history
  • Loading branch information
dzedro committed Nov 28, 2023
1 parent 37409ad commit a3e6c8e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
56 changes: 56 additions & 0 deletions lib/wrapper.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SUSE's openQA tests
#
# Copyright 2023 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Summary: Wrapper for package installation, zypper or transactional update
# Maintainer: QE Core <qe-core@suse.de>

package wrapper;
use Mojo::Base qw(Exporter);
use testapi;
use version_utils qw(is_transactional);
use transactional qw(trup_call check_reboot_changes);
use utils qw(zypper_call);

our @EXPORT = "install_package";

=head1 DESCRIPTION
Wrapper for zypper_call and trup_call
=head2 install_package
install_package('kernel-devel' [, trup_packages => 'kernel-default-base] [, zypper_packages => 'kernel-devel']);
C<packages> defines packages to install for both zypper and trup call,
Parameters C<trup_extra> and C<zypper_extra> define transactional
or zypper specific packages.
C<skip_trup> or C<skip_zypper> will return from fucntion,
record_info is used if sentence is argument value.
C<trup_reboot> parameter will run check_reboot_changes after trup_call,
reboot if diff between the current FS and the new snapshot.
=cut

sub install_package {
my $ret;
my ($packages, %args) = @_;
die 'Paramater packages is required' unless defined($packages);
my $timeout = $args{timeout} // 500;

if (is_transactional) {
record_info('install_package', $args{skip_trup}) if $args{skip_trup} =~ /\w+/;
return if $args{skip_trup};
$packages .= ' ' . $args{trup_extra} // '';
$ret = trup_call('pkg in -l ' . $packages, timeout => $args{timeout});
check_reboot_changes if $args{trup_reboot};
}
else {
record_info('install_package', $args{skip_zypper}) if $args{skip_zypper} =~ /\w+/;
return if $args{skip_zypper};
$packages .= ' ' . $args{zypper_extra} // '';
$ret = zypper_call('in -l ' . $packages, timeout => $args{timeout});
}
return $ret;
}
9 changes: 2 additions & 7 deletions tests/console/year_2038_detection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ use version_utils qw(is_transactional is_sle is_sle_micro is_leap is_leap_micro)
use Utils::Systemd 'disable_and_stop_service';
use power_action_utils 'power_action';
use Utils::Backends 'is_pvm';
use wrapper;

sub install_pkg {
if (is_transactional) {
trup_call('pkg install chrony');
check_reboot_changes;
}
else {
zypper_call('in chrony');
}
install_package('chrony', trup_reboot => 1);
}

sub run {
Expand Down
7 changes: 2 additions & 5 deletions tests/kernel/update_kernel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use repo_tools 'add_qa_head_repo';
use Utils::Backends;
use LTP::utils;
use transactional;
use wrapper;

sub check_kernel_package {
my $kernel_name = shift;
Expand Down Expand Up @@ -86,11 +87,7 @@ sub update_kernel {
fully_patch_system;

if (check_var('SLE_PRODUCT', 'slert')) {
if (is_transactional) {
record_info("There is no kernel-devel-rt available on transactional system.");
} else {
zypper_call('in kernel-devel-rt');
}
install_package('kernel-devel-rt', skip_trup => 'There is no kernel-devel-rt available on transactional system.');
}
elsif (is_sle('12+')) {
zypper_call('in kernel-devel');
Expand Down

0 comments on commit a3e6c8e

Please sign in to comment.