You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

  1. #!/bin/bash
  2. # Check reachability of all running VIRL VMs by logging in on the telnet console port and expect a prompt that includes the host name
  3. # usage
  4. if [ ! $# -gt 2 ] ; then
  5. echo -e "usage: $0 <username> <timeout for telnet connection to each node> <simulation> [debug level], e.g.,\n"
  6. echo "$0 guest VIRLBENCH-223721@smb-WaZLhH 5"
  7. exit -1
  8. fi
  9. # get the IP address of eth0
  10. IP=$(ip addr show | grep eth0 | grep inet | tr -s " " | cut -d " " -f 3 | cut -d "/" -f 1)
  11. RUNNING=true
  12. USERNAME=$1
  13. TIMEOUT=$2
  14. SIMULATION=$3
  15. if [ $4 ]; then
  16. DEBUG=$4
  17. else
  18. DEBUG=0
  19. fi
  20. while $RUNNING = true
  21. do
  22. # Check if all nodes are ready-to-use using expect
  23. # get the telnet ports of all nodes in all simulations
  24. VM_PORTS=$(./ports-vms.py $USERNAME $SIMULATION)
  25. # connect to every telnet port of each node and expect the hostname in the prompt
  26. VMS_UNUSABLE=0
  27. for VM_PORT in $VM_PORTS
  28. do
  29. VM_TELNET_PORT=$(echo $VM_PORT | cut -d "=" -f 2)
  30. VM_NAME=$(echo $VM_PORT | cut -d "=" -f 1)
  31. # connect to every telnet port and check whether it can be used by pressing return
  32. # twice and expecting the hostname to appear in the resulting prompt each time
  33. if [ $DEBUG -lt 2 ]; then
  34. ./test-virl-telnet-connection $IP $VM_TELNET_PORT $VM_NAME $TIMEOUT >/dev/null
  35. else
  36. ./test-virl-telnet-connection $IP $VM_TELNET_PORT $VM_NAME $TIMEOUT
  37. fi
  38. EXPECT_EXITCODE=$?
  39. if [ $EXPECT_EXITCODE -eq 5 ] ; then
  40. VMS_UNUSABLE=$(expr $VMS_UNUSABLE + 1)
  41. if [ $DEBUG -gt 0 ]; then echo "$VM_NAME ($VM_TELNET_PORT) still unusable"; fi
  42. fi
  43. done
  44. if [ $VMS_UNUSABLE -gt 0 ]; then
  45. if [ $DEBUG -gt 0 ]; then echo "$VMS_UNUSABLE VMs are still unusable"; fi
  46. else
  47. RUNNING=false
  48. fi
  49. sleep 1
  50. done
  51. DATE=$(date)
  52. echo "Finished at $DATE"