summaryrefslogtreecommitdiff
path: root/test/buildah-bud/buildah-tests.diff
blob: b1a19a52247b62eaa6400302aa18dcdf69f3cd36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
From c18638abfbc1066442cf6ff0b3f012a5c25a918e Mon Sep 17 00:00:00 2001
From: Ed Santiago <santiago@redhat.com>
Date: Tue, 9 Feb 2021 17:28:05 -0700
Subject: [PATCH] tweaks for running buildah tests under podman

Signed-off-by: Ed Santiago <santiago@redhat.com>
---
 tests/helpers.bash | 72 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 68 insertions(+), 4 deletions(-)

diff --git a/tests/helpers.bash b/tests/helpers.bash
index bd2794c9..ecf6ed7d 100644
--- a/tests/helpers.bash
+++ b/tests/helpers.bash
@@ -43,6 +43,23 @@ EOF
     ROOTDIR_OPTS="--root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER}"
     BUILDAH_REGISTRY_OPTS="--registries-conf ${TESTSDIR}/registries.conf --registries-conf-dir ${TESTDIR}/registries.d --short-name-alias-conf ${TESTDIR}/cache/shortnames.conf"
     PODMAN_REGISTRY_OPTS="--registries-conf ${TESTSDIR}/registries.conf"
+
+    PODMAN_SERVER_PID=
+    PODMAN_NATIVE="${PODMAN_BINARY} ${ROOTDIR_OPTS} ${PODMAN_REGISTRY_OPTS}"
+    if [[ -n "$REMOTE" ]]; then
+        PODMAN_NATIVE="${PODMAN_BINARY%%-remote} ${ROOTDIR_OPTS} ${PODMAN_REGISTRY_OPTS}"
+        # static CONTAINERS_CONF needed for capabilities test. As of 2021-07-01
+        # no tests in bud.bats override this; if at some point any test does
+        # so, it will probably need to be skip_if_remote()d.
+        env CONTAINERS_CONF=${CONTAINERS_CONF:-$(dirname ${BASH_SOURCE})/containers.conf} $PODMAN_NATIVE system service --timeout=0  &
+        PODMAN_SERVER_PID=$!
+        local timeout=10
+        while ((timeout > 0)); do
+            test -S /run/podman/podman.sock && return
+            sleep 0.2
+        done
+        die "podman server never came up"
+    fi
 }
 
 function starthttpd() {
@@ -85,6 +102,12 @@ function teardown_tests() {
     stophttpd
     stop_git_daemon
 
+    if [[ -n "$PODMAN_SERVER_PID" ]]; then
+        kill $PODMAN_SERVER_PID
+        wait $PODMAN_SERVER_PID
+        rm -f /run/podman/podman.sock
+    fi
+
     # Workaround for #1991 - buildah + overlayfs leaks mount points.
     # Many tests leave behind /var/tmp/.../root/overlay and sub-mounts;
     # let's find those and clean them up, otherwise 'rm -rf' fails.
@@ -157,7 +180,13 @@ function copy() {
 }
 
 function podman() {
-    command podman ${PODMAN_REGISTRY_OPTS} ${ROOTDIR_OPTS} "$@"
+    echo "# ... podman $*" >&3
+    ${PODMAN_BINARY} ${PODMAN_REGISTRY_OPTS} ${ROOTDIR_OPTS} "$@"
+}
+
+function podman-remote() {
+    echo "# ... podman-remote $*" >&3
+    ${PODMAN_BINARY} ${ROOTDIR_OPTS} "$@"
 }
 
 #################
@@ -192,15 +221,41 @@ function run_buildah() {
         --retry)         retry=3;        shift;;  # retry network flakes
     esac
 
+    local podman_or_buildah=${BUILDAH_BINARY}
+    local _opts="${ROOTDIR_OPTS} ${BUILDAH_REGISTRY_OPTS}"
+    if [[ $1 == "build" || $1 == "build-using-dockerfile" ]]; then
+        shift
+        # podman defaults to --layers=true; buildah to --false.
+        # If command line includes explicit --layers, leave it untouched,
+        # but otherwise update command line so podman mimics buildah default.
+        if [[ "$*" =~ --layers || "$*" =~ --squash ]]; then
+            set "build" "--force-rm=false" "$@"
+        else
+            set "build" "--force-rm=false" "--layers=false" "$@"
+        fi
+        podman_or_buildah=${PODMAN_BINARY}
+        _opts="${ROOTDIR_OPTS} ${PODMAN_REGISTRY_OPTS}"
+        if [[ -n "$REMOTE" ]]; then
+            _opts=
+        fi
+
+        # podman always exits 125 where buildah exits 1 or 2 (or, in the
+        # case of git, 128, which is a bug in git, but I won't harp on that).
+        case $expected_rc in
+            1|2|128)   expected_rc=125 ;;
+        esac
+    fi
+    local cmd_basename=$(basename ${podman_or_buildah})
+
     # Remember command args, for possible use in later diagnostic messages
-    MOST_RECENT_BUILDAH_COMMAND="buildah $*"
+    MOST_RECENT_BUILDAH_COMMAND="$cmd_basename $*"
 
     while [ $retry -gt 0 ]; do
         retry=$(( retry - 1 ))
 
         # stdout is only emitted upon error; this echo is to help a debugger
-        echo "\$ $BUILDAH_BINARY $*"
-        run env CONTAINERS_CONF=${CONTAINERS_CONF:-$(dirname ${BASH_SOURCE})/containers.conf} timeout --foreground --kill=10 $BUILDAH_TIMEOUT ${BUILDAH_BINARY} ${BUILDAH_REGISTRY_OPTS} ${ROOTDIR_OPTS} "$@"
+        echo "\$ $cmd_basename $*"
+        run env CONTAINERS_CONF=${CONTAINERS_CONF:-$(dirname ${BASH_SOURCE})/containers.conf} timeout --foreground --kill=10 $BUILDAH_TIMEOUT ${podman_or_buildah} ${_opts} "$@"
         # without "quotes", multiple lines are glommed together into one
         if [ -n "$output" ]; then
             echo "$output"
@@ -499,6 +554,15 @@ function skip_if_no_docker() {
   fi
 }
 
+####################
+#  skip_if_remote  #  (only applicable for podman)
+####################
+function skip_if_remote() {
+    if [[ -n "$REMOTE" ]]; then
+        skip "${1:-test does not work with podman-remote}"
+    fi
+}
+
 function start_git_daemon() {
   daemondir=${TESTDIR}/git-daemon
   mkdir -p ${daemondir}/repo
-- 
2.34.1