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