blob: f5e2d27bff94d61605b1bb66a42269a85f59b581 [file] [log] [blame]
gstepanov3d2a9152015-03-27 15:46:20 +02001function get_arguments() {
gstepanov08c0d7e2015-03-25 23:55:44 +02002
gstepanovb65b9a82015-03-28 18:09:17 +02003 export FUEL_MASTER_IP=$1
koder aka kdanilovfb23a262015-03-27 16:50:58 +02004
gstepanovb65b9a82015-03-28 18:09:17 +02005 if [ -z "${FUEL_MASTER_IP}" ]; then echo "Fuel master node ip is not provided"; fi
6
7 export EXTERNAL_IP=$2
8
9 if [ -z "${EXTERNAL_IP}" ]; then echo "Fuel external ip is not provided"; fi
10
11 export KEY_FILE_NAME=$3
12
13 if [ -z "${KEY_FILE_NAME}" ]; then echo "Key file name is not provided"; fi
14
15 export FILE_TO_TEST=$4
16
17 if [ -z "${KEY_FILE_NAME}" ]; then echo "Key file name is not provided"; fi
18
19 if [ ! -f $KEY_FILE_NAME ];
gstepanov3d2a9152015-03-27 15:46:20 +020020 then
21 echo "File $KEY_FILE_NAME does not exist."
22 fi
gstepanovcddbe3b2015-03-26 19:05:48 +020023
gstepanovb65b9a82015-03-28 18:09:17 +020024 export RESULT_FILE=$5
25
26 if [ -z "${RESULT_FILE}" ]; then echo "Result file name is not provided"; fi
27
28 export FUEL_MASTER_PASSWD=${6:-test37}
29 export TIMEOUT=${7:-360}
30
31
gstepanov3d2a9152015-03-27 15:46:20 +020032 echo "Fuel master IP: $FUEL_MASTER_IP"
33 echo "Fuel master password: $FUEL_MASTER_PASSWD"
34 echo "External IP: $EXTERNAL_IP"
35 echo "Key file name: $KEY_FILE_NAME"
36 echo "Timeout: $TIMEOUT"
37}
gstepanov08c0d7e2015-03-25 23:55:44 +020038
39# note : function will works properly only when image dame is single string without spaces that can brake awk
40function wait_image_active() {
41 image_state="none"
koder aka kdanilov94e3a2c2015-03-27 11:36:34 +020042 image_name="$IMAGE_NAME"
gstepanov08c0d7e2015-03-25 23:55:44 +020043 counter=0
44
gstepanovb65b9a82015-03-28 18:09:17 +020045 while [ ["$image_state" == "active"] ] ; do
gstepanov08c0d7e2015-03-25 23:55:44 +020046 sleep 1
gstepanov3d2a9152015-03-27 15:46:20 +020047 image_state=$(glance image-list | grep "$image_name" | awk '{print $12}')
gstepanov08c0d7e2015-03-25 23:55:44 +020048 echo $image_state
49 counter=$((counter + 1))
50
koder aka kdanilov94e3a2c2015-03-27 11:36:34 +020051 if [ "$counter" -eq "$TIMEOUT" ]
gstepanov08c0d7e2015-03-25 23:55:44 +020052 then
53 echo "Time limit exceed"
54 break
55 fi
56 done
57}
58
59
60function wait_floating_ip() {
gstepanov08c0d7e2015-03-25 23:55:44 +020061 floating_ip="|"
62 vm_name=$VM_NAME
63 counter=0
64
gstepanov3d2a9152015-03-27 15:46:20 +020065 while [ "$floating_ip" != "|" ] ; do
gstepanov08c0d7e2015-03-25 23:55:44 +020066 sleep 1
gstepanov3d2a9152015-03-27 15:46:20 +020067 floating_ip=$(nova floating-ip-list | grep "$vm_name" | awk '{print $13}' | head -1)
gstepanov08c0d7e2015-03-25 23:55:44 +020068 counter=$((counter + 1))
69
70 if [ $counter -eq $TIMEOUT ]
71 then
72 echo "Time limit exceed"
73 break
74 fi
75 done
76}
77
78
79function wait_vm_deleted() {
gstepanov3d2a9152015-03-27 15:46:20 +020080 vm_name=$(nova list| grep "$VM_NAME"| awk '{print $4}'| head -1)
gstepanov08c0d7e2015-03-25 23:55:44 +020081 counter=0
82
83 while [ ! -z $vm_name ] ; do
84 sleep 1
gstepanov3d2a9152015-03-27 15:46:20 +020085 vm_name=$(nova list| grep "$VM_NAME"| awk '{print $4}'| head -1)
gstepanov08c0d7e2015-03-25 23:55:44 +020086 counter=$((counter + 1))
87
gstepanov3d2a9152015-03-27 15:46:20 +020088 if [ "$counter" -eq $TIMEOUT ]
gstepanov08c0d7e2015-03-25 23:55:44 +020089 then
90 echo "Time limit exceed"
91 break
92 fi
93 done
94}
95
gstepanov08c0d7e2015-03-25 23:55:44 +020096
gstepanov3d2a9152015-03-27 15:46:20 +020097function get_floating_ip() {
98 IP=$(nova floating-ip-list | grep "$FLOATING_NET" | awk '{if ($5 == "-") print $2}' | head -n1)
gstepanov08c0d7e2015-03-25 23:55:44 +020099
gstepanov3d2a9152015-03-27 15:46:20 +0200100 if [ -z "$IP" ]; then # fix net name
101 IP=$(nova floating-ip-create "$FLOATING_NET"| awk '{print $2}')
gstepanov08c0d7e2015-03-25 23:55:44 +0200102
gstepanov3d2a9152015-03-27 15:46:20 +0200103 if [ -z "$list" ]; then
104 echo "Cannot allocate new floating ip"
105 exit
106 fi
gstepanov08c0d7e2015-03-25 23:55:44 +0200107 fi
gstepanovb65b9a82015-03-28 18:09:17 +0200108
109 export VM_IP=$IP
110 echo "VM_IP: $VM_IP"
gstepanov3d2a9152015-03-27 15:46:20 +0200111}
gstepanov08c0d7e2015-03-25 23:55:44 +0200112
gstepanovb65b9a82015-03-28 18:09:17 +0200113function run_openrc() {
gstepanov3d2a9152015-03-27 15:46:20 +0200114 source run_vm.sh "$FUEL_MASTER_IP" "$FUEL_MASTER_PASSWD" "$EXTERNAL_IP"
115 source `get_openrc`
gstepanov08c0d7e2015-03-25 23:55:44 +0200116
gstepanov3d2a9152015-03-27 15:46:20 +0200117 list=$(nova list)
118 if [ "$list" == "" ]; then
119 echo "openrc variables are unset or set to the empty string"
120 fi
121
gstepanov3d2a9152015-03-27 15:46:20 +0200122 echo 'AUTH_URL: "$OS_AUTH_URL"'
123}
124
koder aka kdanilovfb23a262015-03-27 16:50:58 +0200125get_arguments $@
gstepanov3d2a9152015-03-27 15:46:20 +0200126
gstepanov3d2a9152015-03-27 15:46:20 +0200127echo "getting openrc from controller node"
gstepanovb65b9a82015-03-28 18:09:17 +0200128run_openrc
koder aka kdanilovfb23a262015-03-27 16:50:58 +0200129
gstepanov3d2a9152015-03-27 15:46:20 +0200130echo "openrc has been activated on your machine"
131get_floating_ip
koder aka kdanilovfb23a262015-03-27 16:50:58 +0200132
gstepanov3d2a9152015-03-27 15:46:20 +0200133echo "floating ip has been found"
gstepanov08c0d7e2015-03-25 23:55:44 +0200134bash prepare.sh
gstepanov3d2a9152015-03-27 15:46:20 +0200135echo "Image has been sended to glance"
gstepanov08c0d7e2015-03-25 23:55:44 +0200136wait_image_active
137echo "Image has been saved"
koder aka kdanilovfb23a262015-03-27 16:50:58 +0200138
139BOOT_LOG_FILE=`tempfile`
140boot_vm | tee "$BOOT_LOG_FILE"
141VOL_ID=$(cat "$BOOT_LOG_FILE" | grep "VOL_ID=" | sed 's/VOL_ID=//')
142rm "$BOOT_LOG_FILE"
143
gstepanov08c0d7e2015-03-25 23:55:44 +0200144echo "VM has been booted"
145wait_floating_ip
146echo "Floating IP has been obtained"
147source `prepare_vm`
148echo "VM has been prepared"
gstepanovcddbe3b2015-03-26 19:05:48 +0200149
gstepanov3d2a9152015-03-27 15:46:20 +0200150# sudo bash ../single_node_test_short.sh $FILE_TO_TEST $RESULT_FILE
gstepanovcddbe3b2015-03-26 19:05:48 +0200151
koder aka kdanilovac16aae2015-03-27 12:28:31 +0200152# ssh $SSH_OPTS -i $KEY_FILE_NAME ubuntu@$VM_IP \
gstepanov3d2a9152015-03-27 15:46:20 +0200153# "cd /tmp/io_scenario; echo 'results' > $RESULT_FILE; \
154# curl -X POST -d @$RESULT_FILE http://http://172.16.52.80/api/test --header 'Content-Type:application/json'"
gstepanovcddbe3b2015-03-26 19:05:48 +0200155
gstepanov3d2a9152015-03-27 15:46:20 +0200156nova delete $VM_NAME
157wait_vm_deleted
158echo "$VM_NAME has been deleted successfully"
159cinder delete $VOL_ID
160echo "Volume has been deleted $VOL_ID"