connhelper: add e2e

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2018-09-06 14:38:01 +09:00
parent 00c0c7e12f
commit 9b148db87a
7 changed files with 54 additions and 16 deletions

View File

@ -105,7 +105,7 @@ shellcheck: build_shell_validate_image ## run shellcheck validation
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(VALIDATE_IMAGE_NAME) make shellcheck docker run -ti --rm $(ENVVARS) $(MOUNTS) $(VALIDATE_IMAGE_NAME) make shellcheck
.PHONY: test-e2e ## run e2e tests .PHONY: test-e2e ## run e2e tests
test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ssh
.PHONY: test-e2e-experimental .PHONY: test-e2e-experimental
test-e2e-experimental: build_e2e_image test-e2e-experimental: build_e2e_image
@ -115,6 +115,10 @@ test-e2e-experimental: build_e2e_image
test-e2e-non-experimental: build_e2e_image test-e2e-non-experimental: build_e2e_image
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME) docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME)
.PHONY: test-e2e-connhelper-ssh
test-e2e-connhelper-ssh: build_e2e_image
docker run -e TEST_CONNHELPER=ssh -e DOCKERD_EXPERIMENTAL=1 --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME)
.PHONY: help .PHONY: help
help: ## print this help help: ## print this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

View File

@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y \
libapparmor-dev \ libapparmor-dev \
libseccomp-dev \ libseccomp-dev \
iptables \ iptables \
openssh-client \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
ARG COMPOSE_VERSION=1.21.2 ARG COMPOSE_VERSION=1.21.2

View File

@ -0,0 +1,9 @@
version: '2.1'
services:
engine:
build:
context: ./testdata
dockerfile: Dockerfile.connhelper-ssh
environment:
- TEST_CONNHELPER_SSH_ID_RSA_PUB

14
e2e/testdata/Dockerfile.connhelper-ssh vendored Normal file
View File

@ -0,0 +1,14 @@
FROM docker:test-dind
RUN apk --no-cache add shadow openssh-server && \
groupadd -f docker && \
useradd -m penguin && \
usermod -aG docker penguin && \
usermod -p $(head -c32 /dev/urandom | base64) penguin && \
chsh -s /bin/sh penguin && \
ssh-keygen -A
# workaround: ssh session excludes /usr/local/bin from $PATH
RUN ln -s /usr/local/bin/docker /usr/bin/docker
COPY ./connhelper-ssh/entrypoint.sh /
EXPOSE 22
ENTRYPOINT ["/entrypoint.sh"]
# usage: docker run --privileged -e TEST_CONNHELPER_SSH_ID_RSA_PUB=$(cat ~/.ssh/id_rsa.pub) -p 22 $THIS_IMAGE

8
e2e/testdata/connhelper-ssh/entrypoint.sh vendored Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
set -ex
mkdir -m 0700 -p /home/penguin/.ssh
echo ${TEST_CONNHELPER_SSH_ID_RSA_PUB} > /home/penguin/.ssh/authorized_keys
chmod 0600 /home/penguin/.ssh/authorized_keys
chown -R penguin:penguin /home/penguin
/usr/sbin/sshd -E /var/log/sshd.log
exec dockerd-entrypoint.sh $@

View File

@ -1,15 +1,13 @@
package environment package environment
import ( import (
"context"
"os" "os"
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/assert" "gotest.tools/icmd"
"gotest.tools/poll" "gotest.tools/poll"
"gotest.tools/skip" "gotest.tools/skip"
) )
@ -79,21 +77,14 @@ func boolFromString(val string) bool {
} }
} }
func dockerClient(t *testing.T) client.APIClient {
t.Helper()
c, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.37"))
assert.NilError(t, err)
return c
}
// DefaultPollSettings used with gotestyourself/poll // DefaultPollSettings used with gotestyourself/poll
var DefaultPollSettings = poll.WithDelay(100 * time.Millisecond) var DefaultPollSettings = poll.WithDelay(100 * time.Millisecond)
// SkipIfNotExperimentalDaemon returns whether the test docker daemon is in experimental mode // SkipIfNotExperimentalDaemon returns whether the test docker daemon is in experimental mode
func SkipIfNotExperimentalDaemon(t *testing.T) { func SkipIfNotExperimentalDaemon(t *testing.T) {
t.Helper() t.Helper()
c := dockerClient(t) result := icmd.RunCmd(icmd.Command("docker", "info", "--format", "{{.ExperimentalBuild}}"))
info, err := c.Info(context.Background()) result.Assert(t, icmd.Expected{Err: icmd.None})
assert.NilError(t, err) experimentalBuild := strings.TrimSpace(result.Stdout()) == "true"
skip.If(t, !info.ExperimentalBuild, "running against a non-experimental daemon") skip.If(t, !experimentalBuild, "running against a non-experimental daemon")
} }

View File

@ -18,6 +18,14 @@ function setup {
local file=$2 local file=$2
test "${DOCKERD_EXPERIMENTAL:-}" -eq "1" && file="${file}:./e2e/compose-env.experimental.yaml" test "${DOCKERD_EXPERIMENTAL:-}" -eq "1" && file="${file}:./e2e/compose-env.experimental.yaml"
if [[ "${TEST_CONNHELPER:-}" = "ssh" ]];then
test ! -f "${HOME}/.ssh/id_rsa" && ssh-keygen -t rsa -C docker-e2e-dummy -N "" -f "${HOME}/.ssh/id_rsa" -q
grep "^StrictHostKeyChecking no" "${HOME}/.ssh/config" > /dev/null 2>&1 || echo "StrictHostKeyChecking no" > "${HOME}/.ssh/config"
TEST_CONNHELPER_SSH_ID_RSA_PUB=$(cat "${HOME}/.ssh/id_rsa.pub")
export TEST_CONNHELPER_SSH_ID_RSA_PUB
file="${file}:./e2e/compose-env.connhelper-ssh.yaml"
fi
COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker-compose up --build -d >&2 COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker-compose up --build -d >&2
local network="${project}_default" local network="${project}_default"
@ -26,6 +34,9 @@ function setup {
engine_ip="$(container_ip "${project}_engine_1" "$network")" engine_ip="$(container_ip "${project}_engine_1" "$network")"
engine_host="tcp://$engine_ip:2375" engine_host="tcp://$engine_ip:2375"
if [[ "${TEST_CONNHELPER:-}" = "ssh" ]];then
engine_host="ssh://penguin@${engine_ip}"
fi
( (
export DOCKER_HOST="$engine_host" export DOCKER_HOST="$engine_host"
timeout 200 ./scripts/test/e2e/wait-on-daemon timeout 200 ./scripts/test/e2e/wait-on-daemon
@ -57,7 +68,7 @@ function runtests {
TEST_REMOTE_DAEMON="${REMOTE_DAEMON-}" \ TEST_REMOTE_DAEMON="${REMOTE_DAEMON-}" \
TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \ TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \
GOPATH="$GOPATH" \ GOPATH="$GOPATH" \
PATH="$PWD/build/" \ PATH="$PWD/build/:/usr/bin" \
"$(which go)" test -v ./e2e/... ${TESTFLAGS-} "$(which go)" test -v ./e2e/... ${TESTFLAGS-}
} }