-
Notifications
You must be signed in to change notification settings - Fork 267
/
transactional_update.pm
129 lines (105 loc) · 4.3 KB
/
transactional_update.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# SUSE's openQA tests
#
# Copyright 2020 SUSE LLC
# SPDX-License-Identifier: FSFAP
# Package: transactional-update rebootmgr
# Summary: Test transactional updates
# Installs & remove ptf, update, rollback
# Check that system was rebooted and mounted snapshot changed
# Check that expected package version match
# Maintainer: Martin Kravec <mkravec@suse.com>
# Tags: poo#14444
use strict;
use warnings;
use base "consoletest";
use testapi;
use version_utils qw(is_staging is_opensuse is_leap is_sle is_sle_micro is_leap_micro);
use transactional;
use utils;
use serial_terminal;
=head2 check_package
check_package([stage => $stage, package => $package]);
Check that package presence & version are as expected
Optional C<$stage> can be specified with possible values are 'no', 'in' and 'up'. default is 'no'.
Optional C<$package> can be specified name of rpm file. default is 'update-test-security'.
=cut
sub check_package {
my (%args) = @_;
my $stage = $args{stage} // 'no';
my $package = $args{package} // 'update-test-security';
my $in_vr = rpmver('vr');
if ($stage eq 'no') {
assert_script_run "! rpm -q $package";
} elsif ($stage eq 'in') {
assert_script_run "rpm -q --qf '%{V}-%{R}' $package | grep -x $in_vr";
} elsif ($stage eq 'up') {
my ($in_ver, $in_rel) = split '-', $in_vr;
my ($up_ver, $up_rel) = split '-', script_output("rpm -q --qf '%{V}-%{R}' $package");
$up_rel =~ s/lp\d+\.(?:mo\.)?//;
$in_ver = version->declare($in_ver);
$in_rel = version->declare($in_rel);
$up_ver = version->declare($up_ver);
$up_rel = version->declare($up_rel);
return if $up_ver > $in_ver;
return if $up_rel > $in_rel && $up_ver == $in_ver;
die "Bad version: in:$in_ver-$in_rel up:$up_ver-$up_rel";
} else {
die "Unknown stage: $stage";
}
}
sub run {
select_serial_terminal;
script_run "rebootmgrctl set-strategy off";
get_utt_packages;
record_info 'Install ptf', 'Install package - snapshot #1';
trup_call "ptf install" . rpmver('security');
check_reboot_changes;
check_package(stage => 'in');
# Find snapshot number for rollback
my $snap = script_output "snapper list --columns number | tail -1 | tr -d ' *'";
# Don't use tests requiring repos in staging
unless (is_opensuse && is_staging) {
record_info 'Update #1', 'Add repository and update - snapshot #2';
# Leap Micro misses the gpg key for openSUSE:Maintenance space
my $no_gpg_check = (is_leap_micro) ? '-G' : '';
zypper_call "ar $no_gpg_check utt.repo" if (is_sle || is_sle_micro || is_leap_micro);
# openSUSE MicroOS does not need additional repo as UTT package is already available
trup_call 'cleanup up', timeout => 300;
check_reboot_changes;
check_package(stage => 'up');
# NOTE: This has a very small chance of failing
# See https://progress.opensuse.org/issues/159039
record_info 'Update #2', 'System should be up to date - no changes expected';
trup_call 'cleanup up';
check_reboot_changes 0;
# Check that zypper does not return 0 if update was aborted
record_info 'Broken pkg', 'Install broken package poo#18644 - snapshot #3';
trup_call "pkg install" . rpmver('broken'), interactive => 1;
check_reboot_changes;
# Systems with repositories would downgrade on DUP
if (is_leap) {
record_info 'Broken packages test skipped';
} else {
trup_call "cleanup up", exit_code => 1;
check_reboot_changes 0;
}
}
record_info 'Remove pkg', 'Remove package - snapshot #4';
trup_call 'pkg remove update-test-security';
check_reboot_changes;
check_package;
record_info 'Continue', 'Continue modifying an snapshot -snapshots #5 and #6';
trup_call "pkg install" . rpmver('feature');
trup_call "--continue pkg install" . rpmver('optional');
check_reboot_changes;
check_package(stage => 'in', package => 'update-test-feature');
check_package(stage => 'in', package => 'update-test-optional');
record_info 'Rollback', 'Revert to snapshot with initial rpm';
trup_call "rollback $snap";
check_reboot_changes;
check_package(stage => 'in');
}
sub test_flags {
return {no_rollback => 1};
}
1;