From cadc3869b3d78ab1a2c9fe58ff20614d1802b8dd Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 14 Apr 2016 16:05:12 +0100 Subject: [PATCH 1/2] Launch observes --no-restart --- weave | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/weave b/weave index 82005ee1..0e39e2fa 100755 --- a/weave +++ b/weave @@ -41,17 +41,17 @@ weave --help | help weave launch launch-router [--password ] [--name ] [--nickname ] - [--ipalloc-init ] + [--no-restart] [--ipalloc-init ] [--ipalloc-range [--ipalloc-default-subnet ]] [--no-discovery] [--no-dns] [--trusted-subnets ,...] ... launch-proxy [-H ] [--without-dns] [--no-multicast-route] - [--no-rewrite-hosts] [--no-default-ipalloc] + [--no-rewrite-hosts] [--no-default-ipalloc] [--no-restart] [--hostname-from-label ] [--hostname-match ] [--hostname-replacement ] [--rewrite-inspect] - launch-plugin [--no-multicast-route] + launch-plugin [--no-restart] [--no-multicast-route] weave prime @@ -380,6 +380,8 @@ if [ -z "$IS_LOCAL" ] ; then exit $? fi +# Default restart policy for router/proxy/plugin +RESTART_POLICY="--restart=always" BASE_IMAGE=$DOCKERHUB_USER/weave IMAGE=$BASE_IMAGE:$IMAGE_VERSION @@ -987,11 +989,18 @@ detach() { # functions for interacting with containers ###################################################################### +pertinent_match_args() { + docker inspect -f '{{.Args}} + {{.Config.Env}} + {{.HostConfig.RestartPolicy.Name}} + {{.HostConfig.RestartPolicy.MaximumRetryCount}}' $1 +} + args_match() { - prev_args="$(docker inspect -f '{{.Args}} {{.Config.Env}}' $1)" || return 1 + prev_args="$(pertinent_match_args $1)" || return 1 shift dummy_container=$(docker create "$@" 2>/dev/null) || return 1 - dummy_args="$(docker inspect -f '{{.Args}} {{.Config.Env}}' $dummy_container)" || return 1 + dummy_args="$(pertinent_match_args $dummy_container)" || return 1 docker rm $dummy_container >/dev/null [ "$prev_args" = "$dummy_args" ] } @@ -1525,6 +1534,9 @@ proxy_parse_args() { --tlskey=*) tls_arg "${1%%=*}" "${1#*=}" key ;; + --no-restart) + RESTART_POLICY= + ;; *) PROXY_ARGS="$PROXY_ARGS $1" ;; @@ -1591,6 +1603,9 @@ common_launch_args() { args="" while [ $# -gt 0 ] ; do case "$1" in + --no-restart) + args="$args $1" + ;; --log-level) [ $# -gt 1 ] || usage args="$args $1 $2" @@ -1663,6 +1678,9 @@ launch_router() { NO_DNS_OPT="--no-dns" ARGS="$ARGS $1" ;; + --no-restart) + RESTART_POLICY= + ;; *) ARGS="$ARGS '$(echo "$1" | sed "s|'|'\"'\"'|g")'" ;; @@ -1695,7 +1713,7 @@ launch_router() { # when launching the weave container. start_if_necessary router $CONTAINER_NAME $IMAGE \ $(docker_run_options) \ - --restart=always \ + $RESTART_POLICY \ --volumes-from $DB_CONTAINER_NAME \ -e WEAVE_PASSWORD \ -e CHECKPOINT_DISABLE \ @@ -1753,7 +1771,7 @@ launch_proxy() { fi start_if_necessary proxy $PROXY_CONTAINER_NAME $EXEC_IMAGE \ $(docker_run_options) \ - --restart=always \ + $RESTART_POLICY \ --pid=host \ $PROXY_VOLUMES \ --volumes-from $VOLUMES_CONTAINER_NAME \ @@ -1774,9 +1792,20 @@ stop_proxy() { } launch_plugin_if_not_running() { + while [ $# -gt 0 ]; do + case "$1" in + --no-restart) + RESTART_POLICY= + ;; + *) + break + ;; + esac + shift + done start_if_necessary plugin $PLUGIN_CONTAINER_NAME $PLUGIN_IMAGE \ $(docker_run_options) \ - --restart=always \ + $RESTART_POLICY \ -v /run/docker/plugins:/run/docker/plugins \ -e WEAVE_HTTP_ADDR \ $WEAVEPLUGIN_DOCKER_ARGS $PLUGIN_IMAGE $COVERAGE_ARGS \ From c6609bd248581fa75153424c3aeb0020bcaadd10 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 14 Apr 2016 16:34:34 +0100 Subject: [PATCH 2/2] Smoke test --no-restart --- test/090_docker_restart_policy_2_test.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/090_docker_restart_policy_2_test.sh b/test/090_docker_restart_policy_2_test.sh index dba02595..f7cc04c2 100755 --- a/test/090_docker_restart_policy_2_test.sh +++ b/test/090_docker_restart_policy_2_test.sh @@ -9,7 +9,7 @@ check_restart() { run_on $1 sudo kill $OLD_PID - for i in $(seq 1 30); do + for i in $(seq 1 10); do NEW_PID=$(container_pid $1 $2) if [ $NEW_PID != 0 -a $NEW_PID != $OLD_PID ] ; then @@ -24,7 +24,25 @@ check_restart() { weave_on $HOST1 launch +assert "docker_on $HOST1 inspect -f '{{.HostConfig.RestartPolicy.Name}}' weave weaveproxy weaveplugin" "always\nalways\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_raises "! check_restart $HOST1 weave" +assert_raises "! check_restart $HOST1 weaveproxy" +assert_raises "! check_restart $HOST1 weaveplugin" + +# Relaunch the plugin to prevent the `weave stop` in `end_suite` +# timing out trying to remove the plugin network +weave_on $HOST1 launch-plugin end_suite