Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to stop docker swarm service from earlier testrun. #4210

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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