Skip to content

Commit 620b351

Browse files
containers: Add migration module to support container upgrades
1 parent 0d1b273 commit 620b351

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

tests/containers/migration.pm

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# SUSE's openQA tests
2+
#
3+
# Copyright SUSE LLC
4+
# SPDX-License-Identifier: FSFAP
5+
# Maintainer: QE-C team <[email protected]>
6+
7+
# Summary: Validate docker and podman runtime upgrades
8+
# Maintainer: QE-C team <[email protected]>
9+
10+
use Mojo::Base 'containers::basetest';
11+
use testapi;
12+
use serial_terminal qw(select_serial_terminal select_user_serial_terminal);
13+
use utils;
14+
use containers::common;
15+
16+
my $port = 8080;
17+
18+
sub validate {
19+
my $runtime = shift;
20+
21+
assert_script_run "$runtime compose start";
22+
assert_script_run "$runtime compose logs";
23+
assert_script_run "$runtime compose ps";
24+
25+
assert_script_run "$runtime container ls";
26+
assert_script_run "$runtime volume ls";
27+
assert_script_run "$runtime image ls";
28+
29+
validate_script_output "curl -s http://127.0.0.1:$port", qr/Welcome to nginx/;
30+
31+
$port++;
32+
}
33+
34+
sub setup_containers {
35+
my ($runtime, $rootless) = @_;
36+
my $opts = $rootless ? "--user" : "";
37+
38+
if ($runtime eq "docker") {
39+
assert_script_run "dockerd-rootless-setuptool.sh install" if $rootless;
40+
systemctl "$opts enable --now docker";
41+
} else {
42+
systemctl "$opts start podman.socket";
43+
}
44+
45+
assert_script_run "curl -O " . data_url("containers/docker-compose.yml");
46+
assert_script_run "curl -O " . data_url("containers/haproxy.cfg");
47+
assert_script_run "sed -i 's/8080/$port/g' docker-compose.yml";
48+
49+
assert_script_run "$runtime compose pull", 600;
50+
assert_script_run "$runtime compose up -d", 120;
51+
wait_still_screen stilltime => 15, timeout => 180;
52+
53+
validate $runtime;
54+
55+
assert_script_run "$runtime compose stop", 180;
56+
}
57+
58+
sub upgrade {
59+
select_serial_terminal;
60+
61+
foreach my $repo (split /\s+/, get_var("TEST_REPOS", "")) {
62+
zypper_call "addrepo -f $repo";
63+
}
64+
65+
zypper_call "--gpg-auto-import-keys --no-gpg-checks up --details --allow-vendor-change", timeout => 600;
66+
}
67+
68+
sub cleanup {
69+
my ($runtime, $rootless) = @_;
70+
my $opts = $rootless ? "--user" : "";
71+
72+
script_run "$runtime compose down";
73+
script_run "$runtime rmi \$($runtime images -aq)";
74+
75+
if ($runtime eq "docker") {
76+
script_run "dockerd-rootless-setuptool.sh uninstall" if $rootless;
77+
} else {
78+
systemctl "$opts stop podman.socket";
79+
}
80+
}
81+
82+
sub run {
83+
my $self = shift;
84+
85+
select_serial_terminal;
86+
87+
my @pkgs = qw(docker docker-buildx docker-compose docker-rootless-extras podman);
88+
install_packages(@pkgs);
89+
90+
for my $rootless (0, 1) {
91+
for my $runtime ("docker", "podman") {
92+
record_info "$runtime old", script_output("$runtime version", proceeed_on_failure => 1);
93+
select_user_serial_terminal if $rootless;
94+
setup_containers $runtime, $rootless;
95+
}
96+
}
97+
98+
assert_script_run "rpm -qa | sort > /tmp/before", timeout => 180;
99+
upgrade;
100+
assert_script_run "rpm -qa | sort > /tmp/after", timeout => 180;
101+
record_info "rpm diff", script_output "diff /tmp/before /tmp/after || true";
102+
103+
$port = 8080;
104+
105+
for my $rootless (0, 1) {
106+
my $opts = $rootless ? "--user" : "";
107+
for my $runtime ("docker", "podman") {
108+
select_user_serial_terminal if $rootless;
109+
record_info "$runtime new", script_output("$runtime version", proceeed_on_failure => 1);
110+
if ($runtime eq "docker") {
111+
systemctl "$opts restart docker";
112+
} else {
113+
systemctl "$opts restart podman.socket";
114+
}
115+
validate $runtime;
116+
cleanup $runtime, $rootless;
117+
}
118+
}
119+
}
120+
121+
1;

0 commit comments

Comments
 (0)