test-network-impl.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. if ! "$CHUTNEY_PATH/tools/bootstrap-network.sh" "$NETWORK_FLAVOUR"; then
  3. if test "$?" = 77; then
  4. $ECHO "SKIP: $NETWORK_FLAVOR not supported."
  5. exit 77
  6. fi
  7. CHUTNEY_WARNINGS_IGNORE_EXPECTED=false CHUTNEY_WARNINGS_SUMMARY=false \
  8. "$WARNING_COMMAND"
  9. "$WARNINGS"
  10. $ECHO "bootstrap-network.sh failed"
  11. exit 1
  12. fi
  13. # chutney starts verifying after CHUTNEY_START_TIME seconds,
  14. # keeps on trying for CHUTNEY_BOOTSTRAP_TIME seconds,
  15. # and then stops after CHUTNEY_STOP_TIME seconds.
  16. # Even the fastest chutney networks take 5-10 seconds for their first consensus,
  17. # and then 10 seconds after that for relays to bootstrap and upload descriptors,
  18. # and then 10 seconds after that for clients and onion services to bootstrap.
  19. # But chutney defaults to running a bit more slowly, so it is more reliable,
  20. # and we allow a bit more time, in case the machine is heavily loaded.
  21. export CHUTNEY_START_TIME=${CHUTNEY_START_TIME:-120}
  22. export CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60}
  23. export CHUTNEY_STOP_TIME=${CHUTNEY_STOP_TIME:-0}
  24. CHUTNEY="$CHUTNEY_PATH/chutney"
  25. if [ "$CHUTNEY_START_TIME" -ge 0 ]; then
  26. $ECHO "Waiting $CHUTNEY_START_TIME seconds for a consensus containing relays to be generated..."
  27. # We log bootstrap status for debugging purposes.
  28. # We'll fix bootstrap errors in #20473.
  29. "$CHUTNEY" wait_for_bootstrap "$CHUTNEY_NETWORK" \
  30. || $ECHO "Tor bootstrap failed, ignoring for now."
  31. else
  32. $ECHO "Chutney network launched and running. To stop the network, use:"
  33. $ECHO "$CHUTNEY stop $CHUTNEY_NETWORK"
  34. "$WARNINGS"
  35. exit 0
  36. fi
  37. if [ "$CHUTNEY_BOOTSTRAP_TIME" -ge 0 ]; then
  38. # Chutney will try to verify for $CHUTNEY_BOOTSTRAP_TIME seconds each round
  39. n_rounds=0
  40. # Run CHUTNEY_ROUNDS verification rounds
  41. $ECHO "Running $CHUTNEY_ROUNDS verify rounds..."
  42. while [ "$n_rounds" -lt "$CHUTNEY_ROUNDS" ]; do
  43. n_rounds=$((n_rounds+1))
  44. if ! "$CHUTNEY" verify "$CHUTNEY_NETWORK"; then
  45. CHUTNEY_WARNINGS_IGNORE_EXPECTED=false \
  46. CHUTNEY_WARNINGS_SUMMARY=false \
  47. "$WARNING_COMMAND"
  48. "$WARNINGS"
  49. $ECHO "chutney verify $n_rounds/$CHUTNEY_ROUNDS failed"
  50. exit 1
  51. fi
  52. $ECHO "Completed $n_rounds/$CHUTNEY_ROUNDS verify rounds."
  53. done
  54. else
  55. $ECHO "Chutney network ready and running. To stop the network, use:"
  56. $ECHO "$CHUTNEY stop $CHUTNEY_NETWORK"
  57. "$WARNINGS"
  58. exit 0
  59. fi
  60. if [ "$CHUTNEY_STOP_TIME" -ge 0 ]; then
  61. if [ "$CHUTNEY_STOP_TIME" -gt 0 ]; then
  62. $ECHO "Waiting $CHUTNEY_STOP_TIME seconds before stopping the network..."
  63. fi
  64. sleep "$CHUTNEY_STOP_TIME"
  65. # work around a bug/feature in make -j2 (or more)
  66. # where make hangs if any child processes are still alive
  67. if ! "$CHUTNEY" stop "$CHUTNEY_NETWORK"; then
  68. CHUTNEY_WARNINGS_IGNORE_EXPECTED=false CHUTNEY_WARNINGS_SUMMARY=false \
  69. "$WARNING_COMMAND"
  70. "$WARNINGS"
  71. $ECHO "chutney stop failed"
  72. exit 1
  73. fi
  74. # Give tor time to exit gracefully
  75. sleep 3
  76. else
  77. $ECHO "Chutney network verified and running. To stop the network, use:"
  78. $ECHO "$CHUTNEY stop $CHUTNEY_NETWORK"
  79. "$WARNINGS"
  80. exit 0
  81. fi
  82. "$WARNINGS"
  83. exit 0