Skip to content

Commit

Permalink
cherry-pick: Reenable remote system tests
Browse files Browse the repository at this point in the history
NOTE: the remote tests are not reenabled but the changes are applied.
Future commits depend on some of the changes and having the commit
applied will likely facilitate future backports as well.

podman-remote is in better shape now. Let's see what needs
to be done to reenable remote system tests.

 - logs test: skip multilog, it doesn't work remote

 - diff test: use -l only when local, not with remote

 - many other tests: skip_if_remote, with 'FIXME: pending #xxxx'
   where xxxx is a filed issue.

Unrelated: added new helper to skip_if_remote and _if_rootless,
where we check if the source message includes "remote"/"rootless"
and insert it if missing. This is a minor usability enhancement
to make it easier to understand at-a-glance why a skip triggers.

Backported-by: Valentin Rothberg <[email protected]>
Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago authored and vrothberg committed Aug 11, 2020
1 parent 589627b commit 9b591e1
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 22 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ remotesystem:
if timeout -v 1 true; then \
SOCK_FILE=$(shell mktemp --dry-run --tmpdir podman.XXXXXX);\
export PODMAN_SOCKET=unix:$$SOCK_FILE; \
./bin/podman system service --timeout=0 $$PODMAN_SOCKET &> $(if $(PODMAN_SERVER_LOG),$(PODMAN_SERVER_LOG),/dev/null) & \
./bin/podman system service --timeout=0 $$PODMAN_SOCKET > $(if $(PODMAN_SERVER_LOG),$(PODMAN_SERVER_LOG),/dev/null) 2>&1 & \
retry=5;\
while [[ $$retry -ge 0 ]]; do\
while [ $$retry -ge 0 ]; do\
echo Waiting for server...;\
sleep 1;\
./bin/podman-remote --url $$PODMAN_SOCKET info &>/dev/null && break;\
./bin/podman-remote --url $$PODMAN_SOCKET info >/dev/null 2>&1 && break;\
retry=$$(expr $$retry - 1);\
done;\
if [[ $$retry -lt 0 ]]; then\
if [ $$retry -lt 0 ]; then\
echo "Error: ./bin/podman system service did not come up on $$SOCK_FILE" >&2;\
exit 1;\
fi;\
Expand Down
26 changes: 26 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ echo $rand | 0 | $rand
# Believe it or not, 'sh -c' resulted in different behavior
run_podman 0 run --rm $IMAGE sh -c /bin/true
run_podman 1 run --rm $IMAGE sh -c /bin/false

if is_remote; then sleep 2;fi # FIXME: pending #7119
}

@test "podman run --name" {
Expand Down Expand Up @@ -190,6 +192,8 @@ echo $rand | 0 | $rand
}

@test "podman run docker-archive" {
skip_if_remote "FIXME: pending #7116"

# Create an image that, when run, outputs a random magic string
expect=$(random_string 20)
run_podman run --name myc --entrypoint="[\"/bin/echo\",\"$expect\"]" $IMAGE
Expand Down Expand Up @@ -235,6 +239,8 @@ echo $rand | 0 | $rand
# symptom only manifests on a fedora container image -- we have no
# reproducer on alpine. Checking directory ownership is good enough.
@test "podman run : user namespace preserved root ownership" {
skip_if_remote "FIXME: pending #7195"

for priv in "" "--privileged"; do
for user in "--user=0" "--user=100"; do
for keepid in "" "--userns=keep-id"; do
Expand All @@ -252,6 +258,8 @@ echo $rand | 0 | $rand

# #6829 : add username to /etc/passwd inside container if --userns=keep-id
@test "podman run : add username to /etc/passwd if --userns=keep-id" {
skip_if_remote "FIXME: pending #7195"

# Default: always run as root
run_podman run --rm $IMAGE id -un
is "$output" "root" "id -un on regular container"
Expand All @@ -272,4 +280,22 @@ echo $rand | 0 | $rand
is "$output" "root" "--user=0 overrides keep-id"
}

# #6991 : /etc/passwd is modifiable
@test "podman run : --userns=keep-id: passwd file is modifiable" {
skip_if_remote "FIXME: pending #7195"

run_podman run -d --userns=keep-id $IMAGE sh -c 'while ! test -e /stop; do sleep 0.1; done'
cid="$output"

gecos="$(random_string 6) $(random_string 8)"
run_podman exec --user root $cid adduser -D -g "$gecos" -s /bin/sh newuser3
is "$output" "" "output from adduser"
run_podman exec $cid tail -1 /etc/passwd
is "$output" "newuser3:x:1000:1000:$gecos:/home/newuser3:/bin/sh" \
"newuser3 added to /etc/passwd in container"

run_podman exec $cid touch /stop
run_podman wait $cid
}

# vim: filetype=sh
2 changes: 2 additions & 0 deletions test/system/035-logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ load helpers
}

@test "podman logs - multi" {
skip_if_remote "logs does not support multiple containers when run remotely"

# Simple helper to make the container starts, below, easier to read
local -a cid
doit() {
Expand Down
7 changes: 5 additions & 2 deletions test/system/050-stop.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ load helpers
run_podman stop $cid
t1=$SECONDS

# Confirm that container is stopped
# Confirm that container is stopped. Podman-remote unfortunately
# cannot tell the difference between "stopped" and "exited", and
# spits them out interchangeably, so we need to recognize either.
run_podman inspect --format '{{.State.Status}} {{.State.ExitCode}}' $cid
is "$output" "exited \+137" "Status and exit code of stopped container"
is "$output" "\\(stopped\|exited\\) \+137" \
"Status and exit code of stopped container"

# The initial SIGTERM is ignored, so this operation should take
# exactly 10 seconds. Give it some leeway.
Expand Down
2 changes: 2 additions & 0 deletions test/system/055-rm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ load helpers
#
# See https://github.com/containers/libpod/issues/3795
@test "podman rm -f" {
skip_if_remote "FIXME: pending #7117"

rand=$(random_string 30)
( sleep 3; run_podman rm -f $rand ) &
run_podman 137 run --name $rand $IMAGE sleep 30
Expand Down
154 changes: 146 additions & 8 deletions test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
load helpers

@test "podman build - basic test" {
if is_remote && is_rootless; then
skip "unreliable with podman-remote and rootless; #2972"
fi
skip_if_remote "FIXME: pending #7136"

rand_filename=$(random_string 20)
rand_content=$(random_string 50)
Expand All @@ -34,6 +32,7 @@ EOF

# Regression from v1.5.0. This test passes fine in v1.5.0, fails in 1.6
@test "podman build - cache (#3920)" {
skip_if_remote "FIXME: pending #7136"
if is_remote && is_rootless; then
skip "unreliable with podman-remote and rootless; #2972"
fi
Expand Down Expand Up @@ -81,6 +80,8 @@ EOF
}

@test "podman build - URLs" {
skip_if_remote "FIXME: pending #7137"

tmpdir=$PODMAN_TMPDIR/build-test
mkdir -p $tmpdir

Expand All @@ -90,6 +91,7 @@ ADD https://github.com/containers/libpod/blob/master/README.md /tmp/
EOF
run_podman build -t add_url $tmpdir
run_podman run --rm add_url stat /tmp/README.md
if is_remote; then sleep 2;fi # FIXME: pending #7119
run_podman rmi -f add_url

# Now test COPY. That should fail.
Expand All @@ -98,20 +100,156 @@ EOF
is "$output" ".*error building at STEP .*: source can't be a URL for COPY"
}

@test "podman build - stdin test" {
if is_remote && is_rootless; then
skip "unreliable with podman-remote and rootless; #2972"
fi
@test "podman build - workdir, cmd, env, label" {
skip_if_remote "FIXME: pending #7137"

tmpdir=$PODMAN_TMPDIR/build-test
mkdir -p $tmpdir

# Random workdir, and multiple random strings to verify command & env
workdir=/$(random_string 10)
s_echo=$(random_string 15)
s_env1=$(random_string 20)
s_env2=$(random_string 25)
s_env3=$(random_string 30)
s_env4=$(random_string 40)

# Label name: make sure it begins with a letter! jq barfs if you
# try to ask it for '.foo.<N>xyz', i.e. any string beginning with digit
label_name=l$(random_string 8)
label_value=$(random_string 12)

# Command to run on container startup with no args
cat >$tmpdir/mycmd <<EOF
#!/bin/sh
PATH=/usr/bin:/bin
pwd
echo "\$1"
printenv | grep MYENV | sort | sed -e 's/^MYENV.=//'
EOF

# For overridding with --env-file
cat >$PODMAN_TMPDIR/env-file <<EOF
MYENV3=$s_env3
http_proxy=http-proxy-in-env-file
https_proxy=https-proxy-in-env-file
EOF

cat >$tmpdir/Containerfile <<EOF
FROM $IMAGE
LABEL $label_name=$label_value
RUN mkdir $workdir
WORKDIR $workdir
# Test for #7094 - chowning of invalid symlinks
RUN mkdir -p /a/b/c
RUN ln -s /no/such/nonesuch /a/b/c/badsymlink
RUN ln -s /bin/mydefaultcmd /a/b/c/goodsymlink
RUN touch /a/b/c/myfile
RUN chown -h 1:2 /a/b/c/badsymlink /a/b/c/goodsymlink && chown -h 4:5 /a/b/c/myfile
VOLUME /a/b/c
# Test for environment passing and override
ENV MYENV1=$s_env1
ENV MYENV2 this-should-be-overridden-by-env-host
ENV MYENV3 this-should-be-overridden-by-env-file
ENV MYENV4 this-should-be-overridden-by-cmdline
ENV http_proxy http-proxy-in-image
ENV ftp_proxy ftp-proxy-in-image
ADD mycmd /bin/mydefaultcmd
RUN chmod 755 /bin/mydefaultcmd
RUN chown 2:3 /bin/mydefaultcmd
CMD ["/bin/mydefaultcmd","$s_echo"]
EOF

# cd to the dir, so we test relative paths (important for podman-remote)
cd $PODMAN_TMPDIR
run_podman build -t build_test -f build-test/Containerfile build-test

# Run without args - should run the above script. Verify its output.
export MYENV2="$s_env2"
export MYENV3="env-file-should-override-env-host!"
run_podman run --rm \
--env-file=$PODMAN_TMPDIR/env-file \
--env-host \
-e MYENV4="$s_env4" \
build_test
is "${lines[0]}" "$workdir" "container default command: pwd"
is "${lines[1]}" "$s_echo" "container default command: output from echo"
is "${lines[2]}" "$s_env1" "container default command: env1"
is "${lines[3]}" "$s_env2" "container default command: env2"
is "${lines[4]}" "$s_env3" "container default command: env3 (from envfile)"
is "${lines[5]}" "$s_env4" "container default command: env4 (from cmdline)"

# Proxies - environment should override container, but not env-file
http_proxy=http-proxy-from-env ftp_proxy=ftp-proxy-from-env \
run_podman run --rm --env-file=$PODMAN_TMPDIR/env-file \
build_test \
printenv http_proxy https_proxy ftp_proxy
is "${lines[0]}" "http-proxy-in-env-file" "env-file overrides env"
is "${lines[1]}" "https-proxy-in-env-file" "env-file sets proxy var"
is "${lines[2]}" "ftp-proxy-from-env" "ftp-proxy is passed through"

# test that workdir is set for command-line commands also
run_podman run --rm build_test pwd
is "$output" "$workdir" "pwd command in container"

# Confirm that 'podman inspect' shows the expected values
# FIXME: can we rely on .Env[0] being PATH, and the rest being in order??
run_podman image inspect build_test
tests="
Env[1] | MYENV1=$s_env1
Env[2] | MYENV2=this-should-be-overridden-by-env-host
Env[3] | MYENV3=this-should-be-overridden-by-env-file
Env[4] | MYENV4=this-should-be-overridden-by-cmdline
Cmd[0] | /bin/mydefaultcmd
Cmd[1] | $s_echo
WorkingDir | $workdir
Labels.$label_name | $label_value
"

parse_table "$tests" | while read field expect; do
actual=$(jq -r ".[0].Config.$field" <<<"$output")
dprint "# actual=<$actual> expect=<$expect}>"
is "$actual" "$expect" "jq .Config.$field"
done

# Bad symlink in volume. Prior to #7094, well, we wouldn't actually
# get here because any 'podman run' on a volume that had symlinks,
# be they dangling or valid, would barf with
# Error: chown <mountpath>/_data/symlink: ENOENT
run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/badsymlink
is "$output" "1:2:'/a/b/c/badsymlink' -> '/no/such/nonesuch'" \
"bad symlink to nonexistent file is chowned and preserved"

run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/goodsymlink
is "$output" "1:2:'/a/b/c/goodsymlink' -> '/bin/mydefaultcmd'" \
"good symlink to existing file is chowned and preserved"

run_podman run --rm build_test stat -c'%u:%g' /bin/mydefaultcmd
is "$output" "2:3" "target of symlink is not chowned"

run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/myfile
is "$output" "4:5:/a/b/c/myfile" "file in volume is chowned"

# Clean up
run_podman rmi -f build_test
}

@test "podman build - stdin test" {
skip_if_remote "FIXME: pending #7136"

# Random workdir, and random string to verify build output
workdir=/$(random_string 10)
random_echo=$(random_string 15)
PODMAN_TIMEOUT=240 run_podman build -t build_test - << EOF
FROM $IMAGE
RUN mkdir $workdir
WORKDIR $workdir
RUN /bin/echo 'Test'
RUN /bin/echo $random_echo
EOF
is "$output" ".*STEP 5: COMMIT" "COMMIT seen in log"
is "$output" ".*STEP .: RUN /bin/echo $random_echo"

run_podman run --rm build_test pwd
is "$output" "$workdir" "pwd command in container"
Expand Down
2 changes: 2 additions & 0 deletions test/system/110-history.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
load helpers

@test "podman history - basic tests" {
skip_if_remote "FIXME: pending #7122"

tests="
| .*[0-9a-f]\\\{12\\\} .* CMD .* LABEL
--format '{{.ID}} {{.Created}}' | .*[0-9a-f]\\\{12\\\} .* ago
Expand Down
2 changes: 2 additions & 0 deletions test/system/120-load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ verify_iid_and_name() {


@test "podman load - by image ID" {
skip_if_remote "FIXME: pending #7123"

# FIXME: how to build a simple archive instead?
get_iid_and_name

Expand Down
2 changes: 2 additions & 0 deletions test/system/130-kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
load helpers

@test "podman kill - test signal handling in containers" {
skip_if_remote "FIXME: pending #7135"

# podman-remote and crun interact poorly in f31: crun seems to gobble up
# some signals.
# Workaround: run 'env --default-signal sh' instead of just 'sh' in
Expand Down
13 changes: 10 additions & 3 deletions test/system/140-diff.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
load helpers

@test "podman diff" {
n=$(random_string 10) # container name
rand_file=$(random_string 10)
run_podman run $IMAGE sh -c "touch /$rand_file;rm /etc/services"
run_podman diff --format json -l
run_podman run --name $n $IMAGE sh -c "touch /$rand_file;rm /etc/services"

# If running local, test `-l` (latest) option. This can't work with remote.
if ! is_remote; then
n=-l
fi

run_podman diff --format json $n

# Expected results for each type of diff
declare -A expect=(
Expand All @@ -22,7 +29,7 @@ load helpers
is "$result" "${expect[$field]}" "$field"
done

run_podman rm -l
run_podman rm $n
}

# vim: filetype=sh
Loading

0 comments on commit 9b591e1

Please sign in to comment.