monitor_entrypoint.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/
  3. # --- Test Parameters ---
  4. test_namefile=$(ls *.name)
  5. test_name="${test_namefile%.*}" # test network id
  6. nwconf=$(ls *.conf) # blank test network config file
  7. nwid="${nwconf%.*}" # test network id
  8. netcon_wait_time=25 # wait for test container to come online
  9. app_timeout_time=15 # app-specific timeout
  10. file_path=/opt/results/ # test result output file path (fs shared between host and containers)
  11. file_base="$test_name".txt # test result output file
  12. fail=FAIL. # appended to result file in event of failure
  13. ok=OK. # appended to result file in event of success
  14. tmp_ext=.tmp # temporary filetype used for sharing test data between containers
  15. address_file="$file_path$test_name"_addr"$tmp_ext" # file shared between host and containers for sharing address (optional)
  16. bigfile_name=bigfile # large, random test transfer file
  17. rx_md5sumfile="$file_path"rx_"$bigfile_name"_md5sum"$tmp_ext"
  18. tx_md5sumfile="$file_path"tx_"$bigfile_name"_md5sum"$tmp_ext"
  19. # --- Network Config ---
  20. echo '*** ZeroTier Network Containers Test Monitor'
  21. chown -R daemon /var/lib/zerotier-one
  22. chgrp -R daemon /var/lib/zerotier-one
  23. su daemon -s /bin/bash -c '/zerotier-one -d -U -p9993 >>/tmp/zerotier-one.out 2>&1'
  24. echo '*** Waiting for initial identity generation...'
  25. while [ ! -s /var/lib/zerotier-one/identity.secret ]; do
  26. sleep 0.2
  27. done
  28. echo '*** Waiting for network config...'
  29. virtip4=""
  30. while [ ! -s /var/lib/zerotier-one/networks.d/"$nwconf" ]; do
  31. sleep 0.2
  32. done
  33. while [ -z "$virtip4" ]; do
  34. sleep 0.2
  35. virtip4=`/zerotier-cli listnetworks | grep -F $nwid | cut -d ' ' -f 9 | sed 's/,/\n/g' | grep -F '.' | cut -d / -f 1`
  36. done
  37. echo '*** Starting Test...'
  38. echo '*** Up and running at' $virtip4 ' on network: ' $nwid
  39. echo '*** Sleeping for (' "$netcon_wait_time" 's ) while we wait for the Network Container to come online...'
  40. sleep "$netcon_wait_time"s
  41. ncvirtip=$(<$address_file)
  42. # --- Test section ---
  43. echo '*** Curling from intercepted server at' $ncvirtip
  44. rm -rf "$file_path"*."$file_base"
  45. touch "$bigfile_name"
  46. # Perform test
  47. # curl --connect-timeout "$app_timeout_time" -v -o "$file_path$file_base" http://"$ncvirtip"/index.html
  48. # Large transfer test
  49. curl --connect-timeout "$app_timeout_time" -v -o "$bigfile_name" http://"$ncvirtip"/"$bigfile_name"
  50. # Check md5
  51. md5sum < "$bigfile_name" >> "$rx_md5sumfile"
  52. rx_md5sum=$(<$rx_md5sumfile)
  53. tx_md5sum=$(<$tx_md5sumfile)
  54. echo '*** Comparing md5: ' "$rx_md5sum" ' and ' "$tx_md5sum"
  55. if [ $rx_md5sum != $tx_md5sum ];
  56. then
  57. echo 'MD5 FAIL'
  58. touch "$file_path$fail$test_name.txt"
  59. printf 'Test: md5 sum did not match!\n' >> "$file_path$fail$test_name.txt"
  60. else
  61. echo 'MD5 OK'
  62. touch "$file_path$ok$test_name.txt"
  63. printf 'Test: md5 sum ok!\n' >> "$file_path$ok$test_name.txt"
  64. fi