Guest User

Untitled

a guest
Apr 8th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #!/bin/bash
  2. # Testcase:
  3. VM_IP="192.168.0.12"
  4. VM_USERNAME="ubuntu"
  5.  
  6. checkConnection() {
  7. echo "Wait for ssh-server of instance to start"
  8. (( check_timeout = 120 ))
  9. while (( check_timeout > 0 )); do
  10. ping -c 1 $VM_IP &>/dev/null
  11. if [ $? -eq 0 ]; then
  12. ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
  13. ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no "exit" &>/dev/null
  14. if [ $? -eq 0 ]; then
  15. echo "Instance's ssh-server is running."
  16. sleep 1
  17. return 0
  18. fi
  19. fi
  20. (( check_timeout-- ))
  21. sleep 1
  22. done
  23. echo "Instance's ssh-server isn't running."
  24. return 1
  25. }
  26.  
  27. checkConnectionByPing() {
  28. (( check_timeout = 120 ))
  29. while (( check_timeout > 0 )); do
  30. ping -c 1 $VM_IP &>/dev/null
  31. if [ $? -eq 0 ]; then
  32. return 0
  33. fi
  34. (( check_timeout-- ))
  35. sleep 1
  36. done
  37. return 1
  38. }
  39.  
  40. # Preparation
  41. echo "Creating instance..."
  42. . ./auth-demo.sh
  43. INSTANCE_ID=$(./instance-create.sh ubuntu16.04-server ubuntu.server 10 compute3 $VM_IP)
  44. CLUSTER_ID="$(./cluster-create.sh vm-testing compute3)"
  45. ./cluster-add-instance.sh $CLUSTER_ID $INSTANCE_ID
  46. checkConnection
  47.  
  48. # Hang Guset OS
  49. echo "Crash guest os"
  50. ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
  51. ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no \
  52. "cloud-init status --wait;echo 1 | sudo tee --append /proc/sys/kernel/sysrq; echo s | sudo tee --append /proc/sysrq-trigger;sleep 5; echo c | sudo tee --append /proc/sysrq-trigger;"
  53.  
  54. # wait for HASS to reboot instance
  55. if checkConnectionByPing ;then
  56. echo "Pass"
  57. PASS=0
  58. else
  59. echo "Fail"
  60. PASS=1
  61. fi
  62.  
  63. # clean up
  64. ./instance-delete.sh $INSTANCE_ID && ./cluster-delete.sh $CLUSTER_ID
  65.  
  66. exit $PASS
Add Comment
Please, Sign In to add comment