Skip to content

Commit a68e03b

Browse files
Merge pull request os-autoinst#23653 from ricardobranco777/docker_cleanup
Move gotestsum install to bats library and normalize docker cleanup
2 parents 042e91d + ac204f9 commit a68e03b

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

lib/containers/bats.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ our @EXPORT = qw(
3030
bats_post_hook
3131
bats_tests
3232
go_arch
33+
install_gotestsum
3334
install_ncat
3435
mount_tmp_vartmp
3536
patch_junit
@@ -83,6 +84,14 @@ sub install_git {
8384
run_command "sudo zypper --gpg-auto-import-keys -n install --allow-vendor-change git-core", timeout => 300;
8485
}
8586

87+
sub install_gotestsum {
88+
# We need gotestsum to parse "go test" and create JUnit XML output
89+
return if (script_run("command -v gotestsum") == 0);
90+
run_command 'export GOPATH=$HOME/go';
91+
run_command 'export PATH=$GOPATH/bin:$PATH';
92+
run_command 'go install gotest.tools/[email protected]';
93+
}
94+
8695
sub install_ncat {
8796
if (is_sle('<16')) {
8897
# This repo has ncat 7.94

tests/containers/bats/buildah.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ sub enable_docker {
6767

6868
# Run conformance tests that compare the output of buildah against Docker's BuildKit
6969
sub test_conformance {
70-
run_command 'export GOPATH=$HOME/go';
71-
run_command 'export PATH=$PATH:$GOPATH/bin';
72-
run_command 'go install gotest.tools/[email protected]';
70+
install_gotestsum;
7371
run_command 'cp /usr/bin/busybox-static tests/conformance/testdata/mount-targets/true';
7472
run_command 'docker rmi -f $(docker images -q) || true';
7573
run_command 'gotestsum --junitfile conformance.xml --format standard-verbose -- ./tests/conformance/... |& tee conformance.txt', timeout => 1200;

tests/containers/bats/skopeo.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ sub run_tests {
3535
}
3636

3737
sub test_integration {
38-
run_command 'export GOPATH=$HOME/go';
39-
run_command 'export PATH=$PATH:$GOPATH/bin';
40-
run_command 'go install gotest.tools/[email protected]';
38+
install_gotestsum;
4139
# We can't use openSUSE's distribution-registry package on SLES so extract this binary from the OCI image
4240
# Note: registry:latest with v3 fails unlike library/registry:3
4341
run_command "podman run --rm -v /usr/local/bin:/target:rw,z --user root --entrypoint /bin/cp $registry /bin/registry /target/";

tests/containers/docker_buildx.pm

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sub setup {
2121
my $self = shift;
2222
my @pkgs = qw(buildkit distribution-registry docker docker-buildx docker-compose go1.24);
2323
$self->setup_pkgs(@pkgs);
24+
install_gotestsum;
2425

2526
# The tests assume a vanilla configuration
2627
run_command "mv -f /etc/docker/daemon.json{,.bak}";
@@ -31,11 +32,6 @@ sub setup {
3132
run_command "systemctl restart docker";
3233
record_info "docker info", script_output("docker info");
3334

34-
# We need gotestsum to parse "go test" and create JUnit XML output
35-
run_command 'export GOPATH=$HOME/go';
36-
run_command 'export PATH=$GOPATH/bin:$PATH';
37-
run_command 'go install gotest.tools/[email protected]';
38-
3935
# The tests expect the plugins to be in PATH without the "docker-" prefix
4036
run_command 'cp /usr/lib/docker/cli-plugins/docker-buildx /usr/local/bin/buildx';
4137
run_command 'cp /usr/lib/docker/cli-plugins/docker-compose /usr/local/bin/compose';
@@ -74,14 +70,13 @@ sub run {
7470
upload_logs("buildx.txt");
7571
}
7672

77-
sub cleanup() {
78-
script_run 'rm -vf /usr/local/bin/{buildx,compose}';
73+
sub cleanup {
7974
script_run "mv -f /etc/docker/daemon.json{.bak,}";
8075
script_run "mv -f /etc/sysconfig/docker{.bak,}";
8176
script_run 'docker rm -vf $(docker ps -aq)';
82-
script_run "docker volume prune -a -f";
83-
script_run "docker system prune -a -f";
77+
script_run "docker system prune -a -f --volumes";
8478
systemctl "restart docker";
79+
script_run 'rm -vf /usr/local/bin/{buildx,compose}';
8580
}
8681

8782
sub post_fail_hook {

tests/containers/docker_cli.pm

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sub setup {
2121
my $self = shift;
2222
my @pkgs = qw(docker docker-compose go1.24 jq make);
2323
$self->setup_pkgs(@pkgs);
24+
install_gotestsum;
2425

2526
# The tests assume a vanilla configuration
2627
run_command "mv -f /etc/docker/daemon.json{,.bak}";
@@ -43,10 +44,6 @@ sub setup {
4344
run_command "chmod +x /usr/local/bin/notary";
4445
}
4546

46-
# We need gotestsum to parse "go test" and create JUnit XML output
47-
run_command 'export GOPATH=$HOME/go';
48-
run_command 'export PATH=$PATH:$GOPATH/bin';
49-
run_command 'go install gotest.tools/[email protected]';
5047
# Some tests have /usr/local/go/bin/go hard-coded
5148
run_command 'ln -s /usr /usr/local/go';
5249

@@ -115,17 +112,16 @@ sub run {
115112
upload_logs("cli.txt");
116113
}
117114

118-
sub cleanup() {
119-
script_run "docker rm -vf registry";
115+
sub cleanup {
120116
script_run "COMPOSE_PROJECT_NAME=clie2e COMPOSE_FILE=./e2e/compose-env.yaml docker compose down -v --rmi all";
121117
script_run "docker swarm leave -f";
122-
script_run "docker rmi -f \$(docker images -q)";
123-
script_run "docker volume prune -a -f";
124-
script_run "docker system prune -a -f";
125118
script_run "mv -f /etc/docker/daemon.json{.bak,}";
126119
script_run "mv -f /etc/sysconfig/docker{.bak,}";
127120
script_run "mv -f /usr/lib/docker/cli-plugins/docker-buildx{.bak,}";
121+
script_run 'docker rm -vf $(docker ps -aq)';
122+
script_run "docker system prune -a -f --volumes";
128123
systemctl "restart docker";
124+
script_run "rm -f /usr/local/bin/notary";
129125
}
130126

131127
sub post_fail_hook {

tests/containers/docker_compose.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,20 @@ sub run {
7777
test $_ foreach (@targets);
7878
}
7979

80+
sub cleanup {
81+
script_run 'docker rm -vf $(docker ps -aq)';
82+
script_run "docker system prune -a -f --volumes";
83+
}
84+
8085
sub post_fail_hook {
8186
my ($self) = @_;
87+
cleanup;
8288
bats_post_hook;
8389
}
8490

8591
sub post_run_hook {
8692
my ($self) = @_;
93+
cleanup;
8794
bats_post_hook;
8895
}
8996

tests/containers/docker_engine.pm

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ sub setup {
2222
my $self = shift;
2323
my @pkgs = qw(containerd-ctr distribution-registry docker go1.24 make);
2424
$self->setup_pkgs(@pkgs);
25+
install_gotestsum;
2526

2627
# The tests assume a vanilla configuration
2728
run_command "mv -f /etc/docker/daemon.json{,.bak}";
@@ -34,11 +35,6 @@ sub setup {
3435
run_command "systemctl restart docker";
3536
record_info "docker info", script_output("docker info");
3637

37-
# We need gotestsum to parse "go test" and create JUnit XML output
38-
run_command 'export GOPATH=$HOME/go';
39-
run_command 'export PATH=$GOPATH/bin:/usr/local/bin:$PATH';
40-
run_command 'go install gotest.tools/[email protected]';
41-
4238
# We need ping from GNU inetutils
4339
run_command 'docker run --rm -it -v /usr/local/bin:/target:rw,z debian sh -c "apt update; apt install -y inetutils-ping; cp -v /bin/ping* /target"', timeout => 120;
4440
record_info "ping version", script_output("ping --version");
@@ -112,16 +108,14 @@ sub run {
112108
upload_logs("/var/tmp/report.txt");
113109
}
114110

115-
sub cleanup() {
116-
script_run 'docker rm -vf $(docker ps -aq)';
117-
script_run 'docker rmi -f $(docker images -q)';
118-
script_run "docker volume prune -a -f";
119-
script_run "docker system prune -a -f";
120-
script_run "mv -f /etc/docker/daemon.json{.bak,}";
111+
sub cleanup {
112+
script_run "rm -f /usr/local/bin/{ctr,ping}";
121113
script_run "mv -f /etc/sysconfig/docker{.bak,}";
122114
script_run "mv -f /usr/lib/docker/cli-plugins/docker-buildx{.bak,}";
123-
script_run "rm -f /root/go/bin/docker";
115+
script_run 'docker rm -vf $(docker ps -aq)';
116+
script_run "docker system prune -a -f --volumes";
124117
systemctl "restart docker";
118+
script_run "mv -f /etc/docker/daemon.json{.bak,}";
125119
}
126120

127121
sub post_fail_hook {

tests/containers/python_docker.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ sub run {
105105
test "ssh";
106106
}
107107

108-
sub cleanup() {
108+
sub cleanup {
109109
script_run "unset DOCKER_HOST";
110-
script_run "mv -f /etc/docker/daemon.json.bak /etc/docker/daemon.json";
110+
script_run "mv -f /etc/docker/daemon.json{.bak,}";
111+
script_run 'docker rm -vf $(docker ps -aq)';
112+
script_run "docker system prune -a -f --volumes";
113+
systemctl "restart docker";
114+
script_run "rm -f /usr/local/bin/{docker-credential-pass,pass}";
111115
}
112116

113117
sub post_fail_hook {

0 commit comments

Comments
 (0)