Merge pull request #2727 from weaveworks/issues/2397-v2-plugin

Create a V2 Docker plugin
This commit is contained in:
Marc Carré authored and GitHub committed 2017-04-12 14:27:34 +01:00
commit 8961041469
33 files changed
+804 -307

No files matched your search

+2 -4
View File
@@ -6,22 +6,20 @@ start_suite "Test docker restart policy"
weave_on $HOST1 launch
assert "docker_on $HOST1 inspect -f '{{.HostConfig.RestartPolicy.Name}}' weave weaveproxy weaveplugin" "always\nalways\nalways"
assert "docker_on $HOST1 inspect -f '{{.HostConfig.RestartPolicy.Name}}' weave weaveproxy" "always\nalways"
assert_raises "check_restart $HOST1 weave"
assert_raises "check_restart $HOST1 weaveproxy"
assert_raises "check_restart $HOST1 weaveplugin"
# stop + launch tests that restart policy changes result
# in the old containers being removed and new ones created
weave_on $HOST1 stop
weave_on $HOST1 launch --no-restart
assert "docker_on $HOST1 inspect -f '{{.HostConfig.RestartPolicy.Name}}' weave weaveproxy weaveplugin" "no\nno\nno"
assert "docker_on $HOST1 inspect -f '{{.HostConfig.RestartPolicy.Name}}' weave weaveproxy" "no\nno"
assert_raises "! check_restart $HOST1 weave"
assert_raises "! check_restart $HOST1 weaveproxy"
assert_raises "! check_restart $HOST1 weaveplugin"
# Relaunch to prevent the `weave stop` in `end_suite`
# timing out trying to remove the plugin network
+1 -2
View File
@@ -12,9 +12,8 @@ start_suite "--no-multicast-route operation"
$SSH $HOST1 docker network rm testmcasttrue testmcastfalse >/dev/null 2>&1 || true
# Ensure containers run either way have no multicast route
weave_on $HOST1 launch-router
weave_on $HOST1 launch-router --plugin
weave_on $HOST1 launch-proxy --no-multicast-route
weave_on $HOST1 launch-plugin # plugin defaults to multicast off except for 'net=weave'
docker_on $HOST1 run --name c1 -dt $SMALL_IMAGE /bin/sh
weave_on $HOST1 attach --no-multicast-route c1
+4 -1
View File
@@ -14,7 +14,10 @@ weave_on $HOST3 launch $HOST1
weave_on $HOST3 prime
# nuke 1st peer
docker_on $HOST1 kill weave
# NOTE: docker-kill hangs (https://github.com/docker/docker/issues/31447), so we
# kill directly the weaver process instead.
WEAVER_PID=$(container_pid $HOST1 weave)
run_on $HOST1 "sudo kill -9 $WEAVER_PID"
# transfer its space to the 2nd
weave_on $HOST2 rmpeer $PEER1
+1 -1
View File
@@ -3,7 +3,7 @@
. "$(dirname "$0")/config.sh"
IMAGE="joffrey/docker-py:1.8.1"
IMAGE="joffrey/docker-py:1.9.0-rc2"
docker_py_test() {
SHARD=$1
+6 -2
View File
@@ -15,7 +15,7 @@ run_container() {
}
start_suite "Proxy uses correct entrypoint and command with weavewait"
weave_on $HOST1 launch-proxy
weave_on $HOST1 launch-proxy --no-restart
build_image check-ethwe-up '["grep"]' '["^1$", "/sys/class/net/ethwe/carrier"]'
run_container "check-ethwe-up"
@@ -27,7 +27,11 @@ build_image false '["/bin/false"]' ''
run_container "--entrypoint='grep' false ^1$ /sys/class/net/ethwe/carrier"
weave_on $HOST1 launch-router --ipalloc-range 10.2.2.0/24
docker_on $HOST1 kill weaveproxy
# NOTE: docker-kill hangs (https://github.com/docker/docker/issues/31447), so we
# kill directly the weaveproxy process instead.
WEAVEPROXY_PID=$(container_pid $HOST1 weaveproxy)
$SSH $HOST1 "ps aux | grep weaveproxy"
run_on $HOST1 "sudo kill -9 $WEAVEPROXY_PID"
weave_on $HOST1 launch-proxy
assert_raises "proxy docker_on $HOST1 run check-ethwe-up"
+128
View File
@@ -0,0 +1,128 @@
#! /bin/bash
. "$(dirname "$0")/config.sh"
PLUGIN_NAME="weave-ci-registry:5000/weaveworks/net-plugin"
HOST1_IP=$($SSH $HOST1 getent ahosts $HOST1 | grep "RAW" | cut -d' ' -f1)
SERVICE="weave-850-service"
NETWORK="weave-850-network"
setup_master() {
# Setup Docker image registry on $HOST1
docker_on $HOST1 run -p 5000:5000 -d registry:2
# Build plugin-v2 on $HOST1, because Circle "CI" runs only ancient
# version of Docker which does not support v2 plugins.
build_plugin_img="buildpluginv2-ci"
rsync -az -e "$SSH" "$(dirname $0)/../prog/net-plugin" $HOST1:~/
$SSH $HOST1<<EOF
docker rmi $build_plugin_img 2>/dev/null
docker plugin disable $PLUGIN_NAME >/dev/null
docker plugin remove $PLUGIN_NAME 2>/dev/null
WORK_DIR=$(mktemp -d)
mkdir -p \${WORK_DIR}/rootfs
docker create --name=$build_plugin_img weaveworks/weave true
docker export $build_plugin_img | tar -x -C \${WORK_DIR}/rootfs
cp \${HOME}/net-plugin/launch.sh \${WORK_DIR}/rootfs/home/weave/launch.sh
cp \${HOME}/net-plugin/config.json \${WORK_DIR}
docker plugin create $PLUGIN_NAME \${WORK_DIR}
echo "$HOST1_IP weave-ci-registry" | sudo tee -a /etc/hosts
docker plugin push $PLUGIN_NAME
# Start Swarm Manager and enable the plugin
docker swarm init --advertise-addr=$HOST1_IP
[ -n "$COVERAGE" ] && docker plugin set $PLUGIN_NAME EXTRA_ARGS="-test.coverprofile=/home/weave/cover.prof --"
#docker plugin set $PLUGIN_NAME WEAVE_PASSWORD="foobar"
docker plugin enable $PLUGIN_NAME
EOF
}
setup_worker() {
$SSH $HOST2<<EOF
echo "$HOST1_IP weave-ci-registry" | sudo tee -a /etc/hosts
ping -nq -W 2 -c 1 weave-ci-registry
docker swarm join --token "$1" "${HOST1_IP}:2377"
docker plugin install --disable --grant-all-permissions $PLUGIN_NAME
[ -n "$COVERAGE" ] && docker plugin set $PLUGIN_NAME EXTRA_ARGS="-test.coverprofile=/home/weave/cover.prof --"
#docker plugin set $PLUGIN_NAME WEAVE_PASSWORD="foobar"
docker plugin enable $PLUGIN_NAME
EOF
}
cleanup() {
for h in $@; do
$SSH $h<<EOF
sudo sed -i '/weave-ci-registry/d' /etc/hosts
docker service rm $SERVICE || true
docker swarm leave --force || true
docker network rm $NETWORK || true
docker plugin disable -f $PLUGIN_NAME || true
docker plugin remove -f $PLUGIN_NAME || true
EOF
done
}
wait_for_network() {
for i in $(seq 10); do
if docker_on $1 network inspect $2 >/dev/null 2>&1; then
return
fi
echo "Waiting for \"$2\" network"
sleep 2
done
echo "Failed to wait for \"$2\" network" >&2
return 1
}
wait_for_service() {
for i in $(seq 60); do
replicas=$($SSH $1 docker service ls -f="name=$2" | awk '{print $4}' | grep -v REPLICAS)
if [ "$replicas" == "$3/$3" ]; then
return
fi
echo "Waiting for \"$2\" service"
sleep 2
done
echo "Failed to wait for \"$2\" service" >&2
return 1
}
start_suite "Test Docker plugin-v2"
#cleanup $HOST1 $HOST2
#exit 1
setup_master
setup_worker $($SSH $HOST1 docker swarm join-token --quiet worker)
echo "Creating network and service..."
# Create network and service
$SSH $HOST1<<EOF
docker plugin ls
docker network create --driver="${PLUGIN_NAME}:latest" $NETWORK || true
# Otherwise no containers will be scheduled on host2
sleep 20
docker service create --name=$SERVICE --network=$NETWORK --replicas=2 nginx || true
journalctl -r -u docker.service -n30
EOF
wait_for_service $HOST1 $SERVICE 2
C1=$($SSH $HOST1 weave ps | grep -v weave:expose | awk '{print $1}')
C2_IP=$($SSH $HOST2 weave ps | grep -v weave:expose | awk '{print $3}' | cut -d/ -f1)
assert_raises "exec_on $HOST1 $C1 $PING $C2_IP"
# We do not test "weave {status,launch}", because the weave script does not detect
# plugin-v2 if its name is prefixed with a registry name.
# Failing to cleanup will make the rest of the tests to fail
cleanup $HOST1 $HOST2
end_suite