commit 822b30c8e5b2f338c1b208e9252683730f00603d Author: teor teor2345@gmail.com Date: Thu Feb 23 17:25:56 2017 +1100
Make chutney shell scripts support relative paths
Part of #21521.
Remaining work: make chutney python code use CHUTNEY_PATH. --- tools/bootstrap-network.sh | 39 +++++++++++++++++++++++++-------------- tools/hsaddress.sh | 27 +++++++++++++++------------ tools/test-network.sh | 38 +++++++++++++++++++++++++++++--------- tools/warnings.sh | 13 ++++++++----- 4 files changed, 77 insertions(+), 40 deletions(-)
diff --git a/tools/bootstrap-network.sh b/tools/bootstrap-network.sh index ea9d825..438de62 100755 --- a/tools/bootstrap-network.sh +++ b/tools/bootstrap-network.sh @@ -13,35 +13,46 @@ # (default: 'basic') #
+# make chutney path absolute +if [ -d "$PWD/$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH" +elif [ ! -d "$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD" +fi + VOTING_OFFSET=6 -CHUTNEY=./chutney +CHUTNEY="$CHUTNEY_PATH/chutney" myname=$(basename "$0")
-if [ ! -z "$CHUTNEY_PATH" ]; then - cd "$CHUTNEY_PATH" - # tell chutney to use the current directory - export CHUTNEY_PATH=. -fi - -[ -x $CHUTNEY ] || { echo "$myname: missing $CHUTNEY"; exit 1; } -[ -d networks ] || { echo "$myname: missing directory: networks"; exit 1; } +[ -d "$CHUTNEY_PATH" ] || \ + { echo "$myname: missing chutney directory: $CHUTNEY_PATH"; exit 1; } +[ -x "$CHUTNEY" ] || \ + { echo "$myname: missing chutney: $CHUTNEY"; exit 1; } flavour=basic; [ -n "$1" ] && { flavour=$1; shift; }
-$CHUTNEY stop networks/$flavour +export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR" + +[ -e "$CHUTNEY_NETWORK" ] || \ + { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; } + +# Chutney must be launched at $CHUTNEY_PATH, at least until #21521 is fixed +cd "$CHUTNEY_PATH" + +"$CHUTNEY" stop "$CHUTNEY_NETWORK"
echo "$myname: bootstrapping network: $flavour" -$CHUTNEY configure networks/$flavour +"$CHUTNEY" configure "$CHUTNEY_NETWORK"
# TODO: Make 'chutney configure' take an optional offset argument and # use the templating system in Chutney to set this instead of editing # files like this. offset=$(expr ( $(date +%s) + $VOTING_OFFSET ) % 300) CONFOPT="TestingV3AuthVotingStartOffset" -for file in net/nodes/*a/torrc; do +for file in "$CHUTNEY_PATH"/net/nodes/*a/torrc ; do sed -i.bak -e "s/^${CONFOPT}.*$/${CONFOPT} $offset/1" $file done
-$CHUTNEY start networks/$flavour +"$CHUTNEY" start "$CHUTNEY_NETWORK" sleep 1 -$CHUTNEY status networks/$flavour +"$CHUTNEY" status "$CHUTNEY_NETWORK" #echo "tail -F net/nodes/*/notice.log" diff --git a/tools/hsaddress.sh b/tools/hsaddress.sh index b880164..de6f023 100755 --- a/tools/hsaddress.sh +++ b/tools/hsaddress.sh @@ -7,12 +7,15 @@ # Examples: tools/hsaddress.sh # tools/hsaddress.sh 025h
-if [ ! -z "$CHUTNEY_PATH" ]; then - cd "$CHUTNEY_PATH" +# make chutney path absolute +if [ -d "$PWD/$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH" +elif [ ! -d "$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD" fi
NAME=$(basename "$0") -DEST=net/nodes +DEST="$CHUTNEY_PATH/net/nodes" TARGET=hidden_service/hostname
function usage() { @@ -21,28 +24,28 @@ function usage() { }
function show_address() { - cat $1 + cat "$1" }
-[ -d $DEST ] || { echo "$NAME: no nodes available"; exit 1; } +[ -d "$DEST" ] || { echo "$NAME: no nodes available"; exit 1; } if [ $# -eq 0 ]; then # support hOLD for dir in "$DEST"/*h*; do - FILE=${dir}/$TARGET - [ -e $FILE ] || continue + FILE="${dir}/$TARGET" + [ -e "$FILE" ] || continue echo -n "Node `basename ${dir}`: " - show_address $FILE + show_address "$FILE" done elif [ $# -eq 1 ]; then - [ -d $DEST/$1 ] || { echo "$NAME: $1 not found"; exit 1; } + [ -d "$DEST/$1" ] || { echo "$NAME: $1 not found"; exit 1; } # support hOLD [[ "$1" =~ .*h.* ]] || { echo "$NAME: $1 is not a HS"; exit 1; } - FILE=$DEST/$1/$TARGET - [ -e $FILE ] || { echo "$NAME: $FILE not found"; exit 1; } - show_address $FILE + FILE="$DEST/$1/$TARGET" + [ -e "$FILE" ] || { echo "$NAME: $FILE not found"; exit 1; } + show_address "$FILE" else usage fi diff --git a/tools/test-network.sh b/tools/test-network.sh index e3b91f4..29d5bc1 100755 --- a/tools/test-network.sh +++ b/tools/test-network.sh @@ -8,6 +8,7 @@ myname=$(basename "$0") until [ -z "$1" ] do case "$1" in + # the path to the chutney directory --chutney-path) export CHUTNEY_PATH="$2" shift @@ -130,6 +131,11 @@ if [ ! -d "$TOR_DIR" ]; then fi fi
+# make TOR_DIR absolute +if [ -d "$PWD/$TOR_DIR" ]; then + export TOR_DIR="$PWD/$TOR_DIR" +fi + # mandatory: $CHUTNEY_PATH is the path to the chutney launch script # if it's not set: # - if $PWD looks like a chutney directory, set it to $PWD, or @@ -163,6 +169,11 @@ CHUTNEY_PATH=`pwd`/chutney" fi fi
+# make chutney path absolute +if [ -d "$PWD/$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH" +fi + # For picking up the right tor binaries. # If $TOR_DIR isn't set, chutney looks for tor binaries by name or path # using $CHUTNEY_TOR and $CHUTNEY_TOR_GENCERT, and then falls back to @@ -175,11 +186,19 @@ if [ -d "$TOR_DIR" ]; then fi export CHUTNEY_TOR="${TOR_DIR}/src/or/${tor_name}" export CHUTNEY_TOR_GENCERT="${TOR_DIR}/src/tools/${tor_gencert_name}" +else + # make binary paths absolute + if [ -x "$PWD/$CHUTNEY_TOR" ]; then + export CHUTNEY_TOR="$PWD/$CHUTNEY_TOR" + fi + if [ -x "$PWD/$CHUTNEY_TOR_GENCERT" ]; then + export CHUTNEY_TOR_GENCERT="$PWD/$CHUTNEY_TOR_GENCERT" + fi fi
# Set the variables for the chutney network flavour export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs"} -export CHUTNEY_NETWORK="networks/$NETWORK_FLAVOUR" +export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR"
# And finish up if we're doing a dry run if [ "$NETWORK_DRY_RUN" = true ]; then @@ -187,10 +206,10 @@ if [ "$NETWORK_DRY_RUN" = true ]; then return fi
+# Chutney must be launched at $CHUTNEY_PATH, at least until #21521 is fixed cd "$CHUTNEY_PATH" -# tell chutney to use the current directory -export CHUTNEY_PATH=. -./tools/bootstrap-network.sh "$NETWORK_FLAVOUR" || exit 2 + +"$CHUTNEY_PATH/tools/bootstrap-network.sh" "$NETWORK_FLAVOUR" || exit 2
# chutney starts verifying after 20 seconds, keeps on trying for 60 seconds, # and then stops immediately (by default) @@ -200,23 +219,24 @@ export CHUTNEY_START_TIME=${CHUTNEY_START_TIME:-20} export CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60} export CHUTNEY_STOP_TIME=${CHUTNEY_STOP_TIME:-0}
+CHUTNEY="$CHUTNEY_PATH/chutney" if [ "$CHUTNEY_START_TIME" -ge 0 ]; then echo "Waiting ${CHUTNEY_START_TIME} seconds for a consensus containing relays to be generated..." sleep "$CHUTNEY_START_TIME" else echo "Chutney network launched and running. To stop the network, use:" - echo "$PWD/chutney stop $PWD/$CHUTNEY_NETWORK" + echo "$CHUTNEY stop $CHUTNEY_NETWORK" CHUTNEY_WARNINGS_IGNORE_EXPECTED=1 "$CHUTNEY_PATH/tools/warnings.sh" exit 0 fi
if [ "$CHUTNEY_BOOTSTRAP_TIME" -ge 0 ]; then # Chutney will try to verify for $CHUTNEY_BOOTSTRAP_TIME seconds - ./chutney verify "$CHUTNEY_NETWORK" + "$CHUTNEY" verify "$CHUTNEY_NETWORK" VERIFY_EXIT_STATUS="$?" else echo "Chutney network ready and running. To stop the network, use:" - echo "$PWD/chutney stop $PWD/$CHUTNEY_NETWORK" + echo "$CHUTNEY" stop "$CHUTNEY_NETWORK" CHUTNEY_WARNINGS_IGNORE_EXPECTED=1 "$CHUTNEY_PATH/tools/warnings.sh" exit 0 fi @@ -228,11 +248,11 @@ if [ "$CHUTNEY_STOP_TIME" -ge 0 ]; then sleep "$CHUTNEY_STOP_TIME" # work around a bug/feature in make -j2 (or more) # where make hangs if any child processes are still alive - ./chutney stop "$CHUTNEY_NETWORK" + "$CHUTNEY" stop "$CHUTNEY_NETWORK" exit "$VERIFY_EXIT_STATUS" else echo "Chutney network verified and running. To stop the network, use:" - echo "$PWD/chutney stop $PWD/$CHUTNEY_NETWORK" + echo "$CHUTNEY stop $CHUTNEY_NETWORK" CHUTNEY_WARNINGS_IGNORE_EXPECTED=1 "$CHUTNEY_PATH/tools/warnings.sh" exit 0 fi diff --git a/tools/warnings.sh b/tools/warnings.sh index 26eb835..1b7b9f3 100755 --- a/tools/warnings.sh +++ b/tools/warnings.sh @@ -11,8 +11,11 @@ # CHUTNEY_WARNINGS_IGNORE_EXPECTED: set to 1 to filter out expected warnings # CHUTNEY_WARNINGS_SUMMARY: set to 1 to merge warnings from all instances
-if [ ! -z "$CHUTNEY_PATH" ]; then - cd "$CHUTNEY_PATH" +# make chutney path absolute +if [ -d "$PWD/$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH" +elif [ ! -d "$CHUTNEY_PATH" ]; then + export CHUTNEY_PATH="$PWD" fi
function show_warnings() { @@ -47,9 +50,9 @@ function usage() { NC=$(tput sgr0) YELLOW=$(tput setaf 3) GREEN=$(tput setaf 2) -CHUTNEY=./chutney +CHUTNEY="$CHUTNEY_PATH/chutney" NAME=$(basename "$0") -DEST=net/nodes +DEST="$CHUTNEY_PATH/net/nodes" LOG_FILE=info.log # ignore warnings we expect to get every time chutney runs CHUTNEY_WARNINGS_IGNORE_EXPECTED=${CHUTNEY_WARNINGS_IGNORE_EXPECTED:-0} @@ -58,7 +61,7 @@ IGNORE_FILE="$CHUTNEY_PATH/tools/ignore.warnings" # merge all log files into one before counting entries CHUTNEY_WARNINGS_SUMMARY=${CHUTNEY_WARNINGS_SUMMARY:-0}
-[ -d net/nodes ] || { echo "$NAME: no logs available"; exit 1; } +[ -d "$DEST" ] || { echo "$NAME: no logs available"; exit 1; } if [ $# -eq 0 ]; then if [ "$CHUTNEY_WARNINGS_SUMMARY" -ne 0 ]; then