Skip to content

Commit 578324a

Browse files
Merge pull request #23221 from ricardobranco777/docker_compose
Add docker-compose upstream tests
2 parents e57a233 + 1342a6c commit 578324a

File tree

3 files changed

+129
-5
lines changed

3 files changed

+129
-5
lines changed

lib/containers/bats.pm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ our @EXPORT = qw(
3131
bats_setup
3232
bats_sources
3333
bats_tests
34+
install_git
35+
mount_tmp_vartmp
3436
run_command
3537
switch_to_root
3638
switch_to_user
@@ -203,7 +205,9 @@ sub patch_logfile {
203205
assert_script_run "bats_skip_notok $log_file " . join(' ', @skip_tests) if (@skip_tests);
204206
}
205207

206-
sub fix_tmp {
208+
# /tmp as tmpfs has multiple issues: it can't store SELinux labels, consumes RAM and doesn't have enough space
209+
# Bind-mount it to /var/tmp
210+
sub mount_tmp_vartmp {
207211
my $override_conf = <<'EOF';
208212
[Unit]
209213
ConditionPathExists=/var/tmp
@@ -287,7 +291,7 @@ sub bats_setup {
287291
# Disable tmpfs from next boot
288292
if (script_output("findmnt -no FSTYPE /tmp", proceed_on_failure => 1) =~ /tmpfs/) {
289293
# Bind mount /tmp to /var/tmp
290-
fix_tmp;
294+
mount_tmp_vartmp;
291295
}
292296

293297
# Switch to cgroup v2 if not already active
@@ -340,7 +344,7 @@ sub bats_post_hook {
340344
assert_script_run "mkdir -p $log_dir || true";
341345
assert_script_run "cd $log_dir";
342346

343-
script_run "rm -rf $test_dir";
347+
script_run "rm -rf $test_dir" unless ($test_dir eq "/var/tmp/");
344348

345349
collect_calltraces;
346350
collect_coredumps;

tests/containers/docker_compose.pm

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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;

tools/detect_unused_modules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ for test in $MODULES ; do
4848
done | \
4949
# Whitelist
5050

51-
# bats/*
52-
grep -v 'containers/bats/' |\
51+
# Some tests are loaded dynamically via CONTAINER_TESTS or BATS_PACKAGE
52+
grep -v 'containers' |\
5353

5454
# https://progress.opensuse.org/issues/31750
5555
grep -vE '(fetchmail_ssl|mailx_ssl|mutt_ssl|postfix_tls)' |\

0 commit comments

Comments
 (0)