Better plugin detection functions in weave script
Renamed to "is_plugin_v1_enabled" and "is_plugin_v2_enabled". Improve weave status and weave launch* err message when plugin-v2 is running ``` $ weave launch Docker plugin "weaveworks/net-plugin" is running; Aborting. $ weave status <..> Service: plugin (v2) DriverName: weaveworks/net-plugin ```
This commit is contained in:
1 parent
7fc56e54b3
commit
2ba360f33a
2 files changed
+35
-40
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
. "$(dirname "$0")/config.sh"
|
. "$(dirname "$0")/config.sh"
|
||||||
|
|
||||||
PLUGIN_NAME="weave-ci-registry:5000/weaveworks/plugin-v2"
|
PLUGIN_NAME="weave-ci-registry:5000/weaveworks/net-plugin"
|
||||||
HOST1_IP=$($SSH $HOST1 getent ahosts $HOST1 | grep "RAW" | cut -d' ' -f1)
|
HOST1_IP=$($SSH $HOST1 getent ahosts $HOST1 | grep "RAW" | cut -d' ' -f1)
|
||||||
SERVICE="weave-850-service"
|
SERVICE="weave-850-service"
|
||||||
NETWORK="weave-850-network"
|
NETWORK="weave-850-network"
|
||||||
@@ -46,9 +46,7 @@ setup_worker() {
|
|||||||
echo "$HOST1_IP weave-ci-registry" | sudo tee -a /etc/hosts
|
echo "$HOST1_IP weave-ci-registry" | sudo tee -a /etc/hosts
|
||||||
ping -nq -W 2 -c 1 weave-ci-registry
|
ping -nq -W 2 -c 1 weave-ci-registry
|
||||||
docker swarm join --token "$1" "${HOST1_IP}:2377"
|
docker swarm join --token "$1" "${HOST1_IP}:2377"
|
||||||
echo "Installing..."
|
|
||||||
docker plugin install --disable --grant-all-permissions $PLUGIN_NAME
|
docker plugin install --disable --grant-all-permissions $PLUGIN_NAME
|
||||||
echo "Done"
|
|
||||||
|
|
||||||
[ -n "$COVERAGE" ] && docker plugin set $PLUGIN_NAME EXTRA_ARGS="-test.coverprofile=/home/weave/cover.prof --"
|
[ -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 set $PLUGIN_NAME WEAVE_PASSWORD="foobar"
|
||||||
@@ -100,7 +98,6 @@ start_suite "Test Docker plugin-v2"
|
|||||||
#exit 1
|
#exit 1
|
||||||
|
|
||||||
setup_master
|
setup_master
|
||||||
#sleep 20 # registry seems to be async :(
|
|
||||||
setup_worker $($SSH $HOST1 docker swarm join-token --quiet worker)
|
setup_worker $($SSH $HOST1 docker swarm join-token --quiet worker)
|
||||||
|
|
||||||
echo "Creating network and service..."
|
echo "Creating network and service..."
|
||||||
@@ -117,17 +114,14 @@ EOF
|
|||||||
|
|
||||||
wait_for_service $HOST1 $SERVICE 2
|
wait_for_service $HOST1 $SERVICE 2
|
||||||
|
|
||||||
$SSH $HOST1 "docker service ls"
|
|
||||||
$SSH $HOST1 "docker ps"
|
|
||||||
$SSH $HOST2 "docker ps"
|
|
||||||
|
|
||||||
C1=$($SSH $HOST1 weave ps | grep -v weave:expose | awk '{print $1}')
|
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)
|
C2_IP=$($SSH $HOST2 weave ps | grep -v weave:expose | awk '{print $3}' | cut -d/ -f1)
|
||||||
|
|
||||||
# TODO test for encryption
|
|
||||||
|
|
||||||
assert_raises "exec_on $HOST1 $C1 $PING $C2_IP"
|
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
|
# Failing to cleanup will make the rest of the tests to fail
|
||||||
cleanup $HOST1 $HOST2
|
cleanup $HOST1 $HOST2
|
||||||
|
|
||||||
|
|||||||
@@ -883,28 +883,29 @@ attach() {
|
|||||||
util_op attach-container $ATTACH_ARGS $CONTAINER $BRIDGE $MTU "$@"
|
util_op attach-container $ATTACH_ARGS $CONTAINER $BRIDGE $MTU "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_not_running_v2_plugin() {
|
|
||||||
if is_docker_plugin_enabled $PLUGIN_NAME; then
|
|
||||||
echo "Docker plugin \"$PLUGIN_NAME\" is already running." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Docker Plugin V2
|
|
||||||
is_docker_plugin_enabled() {
|
|
||||||
util_op is-docker-plugin-enabled $PLUGIN_NAME 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Docker Plugin (part of weaver process, so V2 or V1).
|
|
||||||
# Assumes that plugin is running inside Docker container.
|
|
||||||
is_plugin_enabled() {
|
|
||||||
docker inspect -f '{{.Config.Cmd}}' $CONTAINER_NAME | grep -q -- "--plugin"
|
|
||||||
}
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# functions for interacting with containers
|
# functions for interacting with containers
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
# Docker Plugin V1 runs in a Docker container.
|
||||||
|
is_plugin_v1_enabled() {
|
||||||
|
docker inspect -f '{{.Config.Cmd}}' $CONTAINER_NAME 2>/dev/null | grep -q -- "--plugin"
|
||||||
|
}
|
||||||
|
|
||||||
|
# The presence of Docker Plugin V2 can be checked only via 'docker plugin',
|
||||||
|
# as v2 plugins do not run as regular containers.
|
||||||
|
is_plugin_v2_enabled() {
|
||||||
|
util_op is-docker-plugin-enabled $PLUGIN_NAME 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check that plugin (v2) is not running.
|
||||||
|
check_not_running_plugin_v2() {
|
||||||
|
if is_plugin_v2_enabled; then
|
||||||
|
echo "Docker plugin \"$PLUGIN_NAME\" is running; Aborting." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check that a container for component $1 named $2 with image $3 is not running
|
# Check that a container for component $1 named $2 with image $3 is not running
|
||||||
check_not_running() {
|
check_not_running() {
|
||||||
RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Status}} {{.Config.Image}}' $2 2>/dev/null) || true
|
RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Status}} {{.Config.Image}}' $2 2>/dev/null) || true
|
||||||
@@ -1752,7 +1753,7 @@ populate_router() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop_router() {
|
stop_router() {
|
||||||
! is_plugin_enabled || util_op remove-plugin-network weave || true
|
! is_plugin_v1_enabled || util_op remove-plugin-network weave || true
|
||||||
stop $CONTAINER_NAME "Weave"
|
stop $CONTAINER_NAME "Weave"
|
||||||
conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true
|
conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
@@ -1796,7 +1797,7 @@ stop_proxy() {
|
|||||||
|
|
||||||
protect_against_docker_hang() {
|
protect_against_docker_hang() {
|
||||||
# If the plugin is not running, remove its socket so Docker doesn't try to talk to it
|
# If the plugin is not running, remove its socket so Docker doesn't try to talk to it
|
||||||
if ! is_docker_plugin_enabled 2>/dev/null ; then
|
if ! is_plugin_v2_enabled 2>/dev/null ; then
|
||||||
rm -f /run/docker/plugins/weave.sock /run/docker/plugins/weavemesh.sock
|
rm -f /run/docker/plugins/weave.sock /run/docker/plugins/weavemesh.sock
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -1984,7 +1985,7 @@ EOF
|
|||||||
deprecation_warnings "$@"
|
deprecation_warnings "$@"
|
||||||
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
||||||
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
||||||
check_not_running_v2_plugin
|
check_not_running_plugin_v2
|
||||||
COMMON_ARGS=$(common_launch_args "$@")
|
COMMON_ARGS=$(common_launch_args "$@")
|
||||||
launch_router --plugin "$@"
|
launch_router --plugin "$@"
|
||||||
launch_proxy $COMMON_ARGS
|
launch_proxy $COMMON_ARGS
|
||||||
@@ -1992,7 +1993,7 @@ EOF
|
|||||||
launch-router)
|
launch-router)
|
||||||
deprecation_warnings "$@"
|
deprecation_warnings "$@"
|
||||||
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
||||||
check_not_running_v2_plugin
|
check_not_running_plugin_v2
|
||||||
launch_router "$@"
|
launch_router "$@"
|
||||||
echo $ROUTER_CONTAINER
|
echo $ROUTER_CONTAINER
|
||||||
;;
|
;;
|
||||||
@@ -2010,7 +2011,7 @@ EOF
|
|||||||
launch-proxy)
|
launch-proxy)
|
||||||
deprecation_warnings "$@"
|
deprecation_warnings "$@"
|
||||||
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
||||||
check_not_running_v2_plugin
|
check_not_running_plugin_v2
|
||||||
launch_proxy "$@"
|
launch_proxy "$@"
|
||||||
echo $PROXY_CONTAINER
|
echo $PROXY_CONTAINER
|
||||||
;;
|
;;
|
||||||
@@ -2055,14 +2056,14 @@ EOF
|
|||||||
echo " Service: proxy"
|
echo " Service: proxy"
|
||||||
echo " Address: $PROXY_ADDRS"
|
echo " Address: $PROXY_ADDRS"
|
||||||
fi
|
fi
|
||||||
if [ -z "$SUB_STATUS" ] && is_docker_plugin_enabled ; then
|
if [ -z "$SUB_STATUS" ] && is_plugin_v1_enabled ; then
|
||||||
echo
|
echo
|
||||||
echo " Service: plugin"
|
echo " Service: plugin (v1)"
|
||||||
echo " DriverName: $PLUGIN_NAME"
|
|
||||||
elif [ -z "$SUB_STATUS" ] && is_plugin_enabled ; then
|
|
||||||
echo
|
|
||||||
echo " Service: plugin"
|
|
||||||
echo " DriverName: weave"
|
echo " DriverName: weave"
|
||||||
|
elif [ -z "$SUB_STATUS" ] && is_plugin_v2_enabled ; then
|
||||||
|
echo
|
||||||
|
echo " Service: plugin (v2)"
|
||||||
|
echo " DriverName: $PLUGIN_NAME"
|
||||||
fi
|
fi
|
||||||
[ -n "$SUB_STATUS" ] || echo
|
[ -n "$SUB_STATUS" ] || echo
|
||||||
[ $res -eq 0 ]
|
[ $res -eq 0 ]
|
||||||
@@ -2261,7 +2262,7 @@ EOF
|
|||||||
;;
|
;;
|
||||||
reset)
|
reset)
|
||||||
[ $# -eq 0 ] || [ $# -eq 1 -a "$1" = "--force" ] || usage
|
[ $# -eq 0 ] || [ $# -eq 1 -a "$1" = "--force" ] || usage
|
||||||
! is_plugin_enabled || util_op remove-plugin-network weave || true
|
! is_plugin_v1_enabled || util_op remove-plugin-network weave || true
|
||||||
warn_if_stopping_proxy_in_env
|
warn_if_stopping_proxy_in_env
|
||||||
res=0
|
res=0
|
||||||
[ "$1" = "--force" ] || check_running $CONTAINER_NAME 2>/dev/null || res=$?
|
[ "$1" = "--force" ] || check_running $CONTAINER_NAME 2>/dev/null || res=$?
|
||||||
|
|||||||
Reference in new issue
Block a user