|
| 1 | +# SUSE's openQA tests |
| 2 | +# |
| 3 | +# Copyright SUSE LLC |
| 4 | +# SPDX-License-Identifier: FSFAP |
| 5 | + |
| 6 | +# Packages: docker-compose |
| 7 | +# Summary: Upstream docker-compose tests |
| 8 | +# Maintainer: QE-C team <qa-c@suse.de> |
| 9 | + |
| 10 | +use Mojo::Base 'containers::basetest', -signatures; |
| 11 | +use testapi; |
| 12 | +use serial_terminal qw(select_serial_terminal); |
| 13 | +use version_utils; |
| 14 | +use utils; |
| 15 | +use power_action_utils 'power_action'; |
| 16 | +use containers::common qw(install_packages); |
| 17 | +use containers::bats; |
| 18 | + |
| 19 | +my $docker_compose = "/usr/lib/docker/cli-plugins/docker-compose"; |
| 20 | + |
| 21 | +sub setup { |
| 22 | + my @pkgs = qw(docker docker-compose go1.24 make); |
| 23 | + install_packages(@pkgs); |
| 24 | + install_git; |
| 25 | + |
| 26 | + systemctl "enable docker"; |
| 27 | + systemctl "restart docker"; |
| 28 | + record_info("docker info", script_output("docker info")); |
| 29 | + |
| 30 | + # Some tests need this file |
| 31 | + run_command "mkdir /root/.docker"; |
| 32 | + run_command "touch /root/.docker/config.json"; |
| 33 | + |
| 34 | + my $version = script_output "$docker_compose version | awk '{ print \$4 }'"; |
| 35 | + record_info("version", $version); |
| 36 | + my $branch = "v$version"; |
| 37 | + my $github_org = "docker"; |
| 38 | + |
| 39 | + # Support these cases for GIT_REPO: [<GITHUB_ORG>]#BRANCH |
| 40 | + # 1. As GITHUB_ORG#TAG: github_user#test-patch |
| 41 | + # 2. As TAG only: main, v1.2.3, etc |
| 42 | + # 3. Empty. Use defaults specified above for $github_org & $branch |
| 43 | + my $repo = get_var("GIT_REPO", ""); |
| 44 | + if ($repo =~ /#/) { |
| 45 | + ($github_org, $branch) = split("#", $repo, 2); |
| 46 | + } elsif ($repo) { |
| 47 | + $branch = $repo; |
| 48 | + } |
| 49 | + |
| 50 | + run_command "cd ~"; |
| 51 | + run_command "git clone --branch $branch https://github.com/$github_org/compose", timeout => 300; |
| 52 | + run_command "cd ~/compose"; |
| 53 | + |
| 54 | + unless ($repo) { |
| 55 | + my @patches = (); |
| 56 | + foreach my $patch (@patches) { |
| 57 | + my $url = "https://github.com/docker/compose/pull/$patch"; |
| 58 | + record_info("patch", $url); |
| 59 | + assert_script_run "curl -O " . data_url("containers/patches/compose/$patch.patch"); |
| 60 | + run_command "git apply -3 --ours $patch.patch"; |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +sub test ($target) { |
| 67 | + my %env = ( |
| 68 | + COMPOSE_E2E_BIN_PATH => $docker_compose, |
| 69 | + # This test fails on v2.39.2 at least |
| 70 | + EXCLUDE_E2E_TESTS => 'TestWatchMultiServices', |
| 71 | + ); |
| 72 | + my $env = join " ", map { "$_=$env{$_}" } sort keys %env; |
| 73 | + |
| 74 | + run_command "$env make $target |& tee $target.txt || true", timeout => 3600; |
| 75 | + |
| 76 | + # Patch the test name in the first line of the JUnit XML file so each target is parsed independently |
| 77 | + assert_script_run qq{sed -ri '0,/name=/s/name="[^"]*"/name="$target"/' /tmp/report/report.xml}; |
| 78 | + assert_script_run "mv /tmp/report/report.xml $target.xml"; |
| 79 | + parse_extra_log(XUnit => "$target.xml"); |
| 80 | + upload_logs("$target.txt"); |
| 81 | +} |
| 82 | + |
| 83 | +sub run { |
| 84 | + my ($self, $args) = @_; |
| 85 | + |
| 86 | + select_serial_terminal; |
| 87 | + setup; |
| 88 | + |
| 89 | + # Bind-mount /tmp to /var/tmp |
| 90 | + mount_tmp_vartmp; |
| 91 | + power_action('reboot', textmode => 1); |
| 92 | + $self->wait_boot(); |
| 93 | + select_serial_terminal; |
| 94 | + |
| 95 | + assert_script_run "cd ~/compose"; |
| 96 | + run_command 'PATH=$PATH:$HOME/compose/bin/build'; |
| 97 | + |
| 98 | + my @targets = split('\s+', get_var("DOCKER_COMPOSE_TARGETS", "e2e-compose e2e-compose-standalone")); |
| 99 | + test $_ foreach (@targets); |
| 100 | +} |
| 101 | + |
| 102 | +sub cleanup() { |
| 103 | + script_run "cd / ; rm -rf /root/compose"; |
| 104 | +} |
| 105 | + |
| 106 | +sub post_fail_hook { |
| 107 | + my ($self) = @_; |
| 108 | + cleanup; |
| 109 | + bats_post_hook; |
| 110 | + $self->SUPER::post_fail_hook; |
| 111 | +} |
| 112 | + |
| 113 | +sub post_run_hook { |
| 114 | + my ($self) = @_; |
| 115 | + cleanup; |
| 116 | + bats_post_hook; |
| 117 | + $self->SUPER::post_run_hook; |
| 118 | +} |
| 119 | + |
| 120 | +1; |
0 commit comments