From 47e7cda4e971be73a08d4c88792a3fc7d817ad57 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Tue, 28 May 2019 09:11:25 -0600 Subject: [PATCH] System tests - get working under podman-in-podman Skopeo CI tests run under podman; hence the registries run in the tests will be podman-in-podman. This requires complex muckery to make work: - install bats, jq, and podman in the test image - add new test-system Make target. It runs podman with /var/lib/containers bind-mounted to a tmpdir and with other necessary options; and invokes a test script that hack-edits /etc/containers/storage.conf before running podman for the first time. - add --cgroup-manager=cgroupfs option to podman invocations in BATS: without this, podman-in-podman fails with: systemd cgroup flag passed, but systemd support for managing cgroups is not available Also: gpg --pinentry-mode option is not available on all our test platforms. Check for it before using. Signed-off-by: Ed Santiago --- Dockerfile | 1 + Makefile | 13 ++++++++++++- hack/make/test-system | 18 ++++++++++++++++++ systemtest/050-signing.bats | 11 ++++++++++- systemtest/helpers.bash | 8 ++++++-- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100755 hack/make/test-system diff --git a/Dockerfile b/Dockerfile index 3cf2be4f..28d82980 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN dnf -y update && dnf install -y make git golang golang-github-cpuguy83-go-md gnupg \ # OpenShift deps which tar wget hostname util-linux bsdtar socat ethtool device-mapper iptables tree findutils nmap-ncat e2fsprogs xfsprogs lsof docker iproute \ + bats jq podman \ && dnf clean all # Install two versions of the registry. The first is an older version that diff --git a/Makefile b/Makefile index 8f431701..6e5df788 100644 --- a/Makefile +++ b/Makefile @@ -138,12 +138,23 @@ install-completions: shell: build-container $(CONTAINER_RUN) bash -check: validate test-unit test-integration +check: validate test-unit test-integration test-system # The tests can run out of entropy and block in containers, so replace /dev/random. test-integration: build-container $(CONTAINER_RUN) bash -c 'rm -f /dev/random; ln -sf /dev/urandom /dev/random; SKOPEO_CONTAINER_TESTS=1 BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-integration' +# complicated set of options needed to run podman-in-podman +test-system: build-container + DTEMP=$(shell mktemp -d --tmpdir=/var/tmp podman-tmp.XXXXXX); \ + $(CONTAINER_CMD) --privileged --net=host \ + -v $$DTEMP:/var/lib/containers:Z \ + "$(IMAGE)" \ + bash -c 'BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-system'; \ + rc=$$?; \ + $(RM) -rf $$DTEMP; \ + exit $$rc + test-unit: build-container # Just call (make test unit-local) here instead of worrying about environment differences, e.g. GO15VENDOREXPERIMENT. $(CONTAINER_RUN) make test-unit-local BUILDTAGS='$(BUILDTAGS)' diff --git a/hack/make/test-system b/hack/make/test-system new file mode 100755 index 00000000..bc881e17 --- /dev/null +++ b/hack/make/test-system @@ -0,0 +1,18 @@ +#!/bin/bash +set -e + +# Before running podman for the first time, make sure +# to set storage to vfs (not overlay): podman-in-podman +# doesn't work with overlay. And, disable mountopt, +# which causes error with vfs. +sed -i \ + -e 's/^driver\s*=.*/driver = "vfs"/' \ + -e 's/^mountopt/#mountopt/' \ + /etc/containers/storage.conf + +# Build skopeo, install into /usr/bin +make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"} +make install + +# Run tests +SKOPEO_BINARY=/usr/bin/skopeo bats --tap systemtest diff --git a/systemtest/050-signing.bats b/systemtest/050-signing.bats index 7cdfc598..af7e978f 100644 --- a/systemtest/050-signing.bats +++ b/systemtest/050-signing.bats @@ -11,8 +11,17 @@ function setup() { # Create dummy gpg keys export GNUPGHOME=$TESTDIR/skopeo-gpg mkdir --mode=0700 $GNUPGHOME + + # gpg on f30 needs this, otherwise: + # gpg: agent_genkey failed: Inappropriate ioctl for device + # ...but gpg on f29 (and, probably, Ubuntu) doesn't grok this + GPGOPTS='--pinentry-mode loopback' + if gpg --pinentry-mode asdf 2>&1 | grep -qi 'Invalid option'; then + GPGOPTS= + fi + for k in alice bob;do - gpg --batch --pinentry-mode loopback --gen-key --passphrase '' <> $AUTHDIR/htpasswd fi @@ -305,7 +309,7 @@ start_registry() { cp $CERT $TESTDIR/client-auth/ fi - podman run -d --name $name "${reg_args[@]}" registry:2 + $PODMAN run -d --name $name "${reg_args[@]}" registry:2 } # END helpers for starting/stopping registries