[tor-commits] [chutney/master] Refactor and document the warnings.sh code

teor at torproject.org teor at torproject.org
Fri Feb 24 00:35:01 UTC 2017


commit 9a1085a526e6e66527bba9e28ec1da6dfcc2185e
Author: teor <teor2345 at gmail.com>
Date:   Fri Feb 24 11:17:35 2017 +1100

    Refactor and document the warnings.sh code
    
    Add arguments to test-network.sh for warnings
    Make the enviromental variables strings rather than integers
    
    Fixes #21371.
---
 README                |  9 +++++++++
 tools/test-network.sh | 27 ++++++++++++++++++++++++---
 tools/warnings.sh     | 13 +++++++------
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/README b/README
index 1d7fa1d..7c4f347 100644
--- a/README
+++ b/README
@@ -48,6 +48,15 @@ Address Options:
   --ipv4             CHUTNEY_LISTEN_ADDRESS
   --ipv6             CHUTNEY_LISTEN_ADDRESS_V6
 
+Warning Options:
+  --all-warnings     CHUTNEY_WARNINGS_IGNORE_EXPECTED=false
+                     CHUTNEY_WARNINGS_SUMMARY=false
+  --no-warnings      CHUTNEY_WARNINGS_SKIP=true
+
+Other Options:
+  --coverage         USE_COVERAGE_BINARY=true
+  --dry-run          NETWORK_DRY_RUN=true
+
 Standard Actions:
   ./chutney configure networks/basic
   ./chutney start networks/basic
diff --git a/tools/test-network.sh b/tools/test-network.sh
index 29d5bc1..547858f 100755
--- a/tools/test-network.sh
+++ b/tools/test-network.sh
@@ -5,6 +5,10 @@ ECHO_N="/bin/echo -n"
 # Output is prefixed with the name of the script
 myname=$(basename "$0")
 
+# default to summarising unexpected warnings
+export CHUTNEY_WARNINGS_IGNORE_EXPECTED=${CHUTNEY_WARNINGS_IGNORE_EXPECTED:-true}
+export CHUTNEY_WARNINGS_SUMMARY=${CHUTNEY_WARNINGS_SUMMARY:-true}
+
 until [ -z "$1" ]
 do
   case "$1" in
@@ -91,6 +95,16 @@ do
       # process arguments, but don't call any other scripts
       export NETWORK_DRY_RUN=true
       ;;
+    # we summarise unexpected warnings by default
+    # this shows all warnings per-node
+    --all-warnings)
+      export CHUTNEY_WARNINGS_IGNORE_EXPECTED=false
+      export CHUTNEY_WARNINGS_SUMMARY=false
+      ;;
+    # this skips warnings entirely
+    --no-warnings)
+      export CHUTNEY_WARNINGS_SKIP=true
+      ;;
     *)
       echo "$myname: Sorry, I don't know what to do with '$1'."
       # continue processing arguments during a dry run
@@ -220,13 +234,19 @@ export CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60}
 export CHUTNEY_STOP_TIME=${CHUTNEY_STOP_TIME:-0}
 
 CHUTNEY="$CHUTNEY_PATH/chutney"
+if [ "$CHUTNEY_WARNINGS_SKIP" = true ]; then
+  WARNINGS=true
+else
+  WARNINGS="$CHUTNEY_PATH/tools/warnings.sh"
+fi
+
 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 "$CHUTNEY stop $CHUTNEY_NETWORK"
-  CHUTNEY_WARNINGS_IGNORE_EXPECTED=1 "$CHUTNEY_PATH/tools/warnings.sh"
+  "$WARNINGS"
   exit 0
 fi
 
@@ -237,7 +257,7 @@ if [ "$CHUTNEY_BOOTSTRAP_TIME" -ge 0 ]; then
 else
   echo "Chutney network ready and running. To stop the network, use:"
   echo "$CHUTNEY" stop "$CHUTNEY_NETWORK"
-  CHUTNEY_WARNINGS_IGNORE_EXPECTED=1 "$CHUTNEY_PATH/tools/warnings.sh"
+  "$WARNINGS"
   exit 0
 fi
 
@@ -249,10 +269,11 @@ if [ "$CHUTNEY_STOP_TIME" -ge 0 ]; then
   # work around a bug/feature in make -j2 (or more)
   # where make hangs if any child processes are still alive
   "$CHUTNEY" stop "$CHUTNEY_NETWORK"
+  "$WARNINGS"
   exit "$VERIFY_EXIT_STATUS"
 else
   echo "Chutney network verified and running. To stop the network, use:"
   echo "$CHUTNEY stop $CHUTNEY_NETWORK"
-  CHUTNEY_WARNINGS_IGNORE_EXPECTED=1 "$CHUTNEY_PATH/tools/warnings.sh"
+  "$WARNINGS"
   exit 0
 fi
diff --git a/tools/warnings.sh b/tools/warnings.sh
index 1b7b9f3..6c2cbab 100755
--- a/tools/warnings.sh
+++ b/tools/warnings.sh
@@ -8,8 +8,8 @@
 # Examples: tools/warnings.sh
 #           tools/warnings.sh 000a
 # Environmental variables:
-# CHUTNEY_WARNINGS_IGNORE_EXPECTED: set to 1 to filter out expected warnings
-# CHUTNEY_WARNINGS_SUMMARY: set to 1 to merge warnings from all instances
+# CHUTNEY_WARNINGS_IGNORE_EXPECTED: set to "true" to filter expected warnings
+# CHUTNEY_WARNINGS_SUMMARY: set to "true" to merge warnings from all instances
 
 # make chutney path absolute
 if [ -d "$PWD/$CHUTNEY_PATH" ]; then
@@ -19,14 +19,15 @@ elif [ ! -d "$CHUTNEY_PATH" ]; then
 fi
 
 function show_warnings() {
-    if [ "$CHUTNEY_WARNINGS_SUMMARY" -ne 0 ]; then
+    if [ "$CHUTNEY_WARNINGS_SUMMARY" = true ]; then
         echo "${GREEN}All `basename $1`:${NC}"
         FILE="$1/*/$LOG_FILE"
     else
         echo "${GREEN}Node `basename $1`:${NC}"
         FILE="$1/$LOG_FILE"
     fi
-    if [ "$CHUTNEY_WARNINGS_IGNORE_EXPECTED" -ne 0 -a -e "$IGNORE_FILE" ]; then
+    if [ "$CHUTNEY_WARNINGS_IGNORE_EXPECTED" = true -a \
+        -e "$IGNORE_FILE" ]; then
         CAT="grep -v -f"
         echo " ${GREEN}(Ignoring expected warnings, run chutney/tools/warnings.sh to see all warnings)${NC}"
     else
@@ -37,7 +38,7 @@ function show_warnings() {
     $CAT $IGNORE_FILE $FILE | \
     sed -n -E 's/^.*\[(warn|err)\]//p' | sort | uniq -c | \
     sed -e 's/^\s*//' -e "s/ *\([0-9][0-9]*\) *\(.*\)/ ${YELLOW}Warning:${NC} \2${YELLOW} Number: \1${NC}/"
-    if [ "$CHUTNEY_WARNINGS_SUMMARY" -eq 0 ]; then
+    if [ "$CHUTNEY_WARNINGS_SUMMARY" != true ]; then
         echo ""
     fi
 }
@@ -64,7 +65,7 @@ CHUTNEY_WARNINGS_SUMMARY=${CHUTNEY_WARNINGS_SUMMARY:-0}
 [ -d "$DEST" ] || { echo "$NAME: no logs available"; exit 1; }
 if [ $# -eq 0 ];
 then
-    if [ "$CHUTNEY_WARNINGS_SUMMARY" -ne 0 ]; then
+    if [ "$CHUTNEY_WARNINGS_SUMMARY" = true ]; then
         show_warnings "$DEST"
         exit 0
     fi





More information about the tor-commits mailing list