Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Testcase:
- VM_IP="192.168.0.12"
- VM_USERNAME="ubuntu"
- checkConnection() {
- echo "Wait for ssh-server of instance to start"
- (( check_timeout = 120 ))
- while (( check_timeout > 0 )); do
- ping -c 1 $VM_IP &>/dev/null
- if [ $? -eq 0 ]; then
- ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
- ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no "exit" &>/dev/null
- if [ $? -eq 0 ]; then
- echo "Instance's ssh-server is running."
- sleep 1
- return 0
- fi
- fi
- (( check_timeout-- ))
- sleep 1
- done
- echo "Instance's ssh-server isn't running."
- return 1
- }
- checkConnectionByPing() {
- (( check_timeout = 120 ))
- while (( check_timeout > 0 )); do
- ping -c 1 $VM_IP &>/dev/null
- if [ $? -eq 0 ]; then
- return 0
- fi
- (( check_timeout-- ))
- sleep 1
- done
- return 1
- }
- # Preparation
- echo "Creating instance..."
- . ./auth-demo.sh
- INSTANCE_ID=$(./instance-create.sh ubuntu16.04-server ubuntu.server 10 compute3 $VM_IP)
- CLUSTER_ID="$(./cluster-create.sh vm-testing compute3)"
- ./cluster-add-instance.sh $CLUSTER_ID $INSTANCE_ID
- checkConnection
- # Hang Guset OS
- echo "Crash guest os"
- ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
- ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no \
- "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;"
- # wait for HASS to reboot instance
- if checkConnectionByPing ;then
- echo "Pass"
- PASS=0
- else
- echo "Fail"
- PASS=1
- fi
- # clean up
- ./instance-delete.sh $INSTANCE_ID && ./cluster-delete.sh $CLUSTER_ID
- exit $PASS
Add Comment
Please, Sign In to add comment