diff --git a/bin/run-tests-on-swarm.sh b/bin/run-tests-on-swarm.sh index 819e9446b..c9a752501 100755 --- a/bin/run-tests-on-swarm.sh +++ b/bin/run-tests-on-swarm.sh @@ -30,6 +30,7 @@ usage() { echo "--service-constraint Constraint on where a service node is scheduled" echo "--service-reserve-memory Reserve memory for each service node" echo "--service-ramdisk Use tmpfs in each service node" + echo "--stop Stop docker swarm service from earlier testrun and exit." echo "-t, --testrunid Identifier for this testrun. Will be autogenerated if not specified." echo "-v, --verbose Print debug output" echo "-w, --nodewait Seconds to wait for required set of nodes to be available." @@ -64,6 +65,7 @@ NODEWAIT="" NUMNODES="" PERFORMANCE=false RESULTDIR="" +STOP_SERVICE=false TESTFILES=() TESTRUNID="" VERBOSE=false @@ -137,6 +139,10 @@ case $key in SERVICE_EXTRA_ARGS+=("--reserve-memory" "$2") shift; shift ;; + --stop) + STOP_SERVICE=true + shift + ;; -t|--testrunid) TESTRUNID="$2" shift; shift @@ -156,6 +162,54 @@ case $key in esac done +log() { + echo "[$(date -u +'%Y-%m-%d %H:%M:%S %z')] $*" +} + +log_debug() { + if [[ $VERBOSE != 0 ]]; then + log "DEBUG" $1 + fi +} + +# Remove service and network +docker_cleanup() { + docker rm -f $TESTRUNNER &> /dev/null || true + docker rm -f $CONFIGSERVER &> /dev/null || true + + if docker service ps $SERVICE &> /dev/null; then + if ! docker service rm $SERVICE &> /dev/null; then + log_debug "Could not remove service $SERVICE" + else + while [[ -n $(docker ps | grep "$SERVICE\.[0-9].*") ]]; do + log_debug "Waiting for service $SERVICE to shut down." + sleep 2 + done + log_debug "Removed service $SERVICE." + fi + fi + + if docker network inspect $NETWORK &> /dev/null; then + if ! docker network rm $NETWORK &> /dev/null; then + log_debug "Could not remove network $NETWORK" + else + while [[ -n $(docker network ls | grep "$NETWORK.*swarm") ]]; do + log_debug "Waiting for network $NETWORK to be removed." + sleep 2 + done + log_debug "Removed network $NETWORK." + fi + fi +} + +if $STOP_SERVICE; then + CONFIGSERVER="$USER-configserver" + VERBOSE=true + docker_cleanup + echo Tests stopped + exit 0 +fi + if [[ ${#POSITIONAL[@]} > 0 ]]; then set -- "${POSITIONAL[@]}" fi @@ -240,14 +294,6 @@ fi TESTRUNNER_OPTS="$TESTRUNNER_OPTS -b $BASEDIR -V $VESPAVERSION" -log() { - echo "[$(date -u +'%Y-%m-%d %H:%M:%S %z')] $*" -} -log_debug() { - if [[ $VERBOSE != 0 ]]; then - log "DEBUG" $1 - fi -} log_info() { log "INFO" $1 } @@ -275,36 +321,6 @@ if [[ ${#POSITIONAL[@]} > 0 ]]; then fi log_debug "" -# Remove service and network -docker_cleanup() { - docker rm -f $TESTRUNNER &> /dev/null || true - docker rm -f $CONFIGSERVER &> /dev/null || true - - if docker service ps $SERVICE &> /dev/null; then - if ! docker service rm $SERVICE &> /dev/null; then - log_debug "Could not remove service $SERVICE" - else - while [[ -n $(docker ps | grep "$SERVICE\.[0-9].*") ]]; do - log_debug "Waiting for service $SERVICE to shut down." - sleep 2 - done - log_debug "Removed service $SERVICE." - fi - fi - - if docker network inspect $NETWORK &> /dev/null; then - if ! docker network rm $NETWORK &> /dev/null; then - log_debug "Could not remove network $NETWORK" - else - while [[ -n $(docker network ls | grep "$NETWORK.*swarm") ]]; do - log_debug "Waiting for network $NETWORK to be removed." - sleep 2 - done - log_debug "Removed network $NETWORK." - fi - fi -} - docker_cleanup if ! docker network create --driver overlay --attachable $NETWORK &> /dev/null; then