Skip to content

Commit

Permalink
Merge pull request #4210 from vespa-engine/toregge/add-option-to-stop…
Browse files Browse the repository at this point in the history
…-running-systemtest-service

Add option to stop docker swarm service from earlier testrun.
  • Loading branch information
toregge authored Oct 2, 2024
2 parents 8b02147 + 5d06043 commit c08f307
Showing 1 changed file with 54 additions and 38 deletions.
92 changes: 54 additions & 38 deletions bin/run-tests-on-swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -64,6 +65,7 @@ NODEWAIT=""
NUMNODES=""
PERFORMANCE=false
RESULTDIR=""
STOP_SERVICE=false
TESTFILES=()
TESTRUNID=""
VERBOSE=false
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c08f307

Please sign in to comment.