gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 1 | function get_arguments() { |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 2 | |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 3 | export FUEL_MASTER_IP=$1 |
koder aka kdanilov | fb23a26 | 2015-03-27 16:50:58 +0200 | [diff] [blame] | 4 | |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 5 | 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 ]; |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 20 | then |
| 21 | echo "File $KEY_FILE_NAME does not exist." |
| 22 | fi |
gstepanov | cddbe3b | 2015-03-26 19:05:48 +0200 | [diff] [blame] | 23 | |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 24 | 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 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 32 | 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 | } |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 38 | |
| 39 | # note : function will works properly only when image dame is single string without spaces that can brake awk |
| 40 | function wait_image_active() { |
| 41 | image_state="none" |
koder aka kdanilov | 94e3a2c | 2015-03-27 11:36:34 +0200 | [diff] [blame] | 42 | image_name="$IMAGE_NAME" |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 43 | counter=0 |
| 44 | |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 45 | while [ ["$image_state" == "active"] ] ; do |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 46 | sleep 1 |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 47 | image_state=$(glance image-list | grep "$image_name" | awk '{print $12}') |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 48 | echo $image_state |
| 49 | counter=$((counter + 1)) |
| 50 | |
koder aka kdanilov | 94e3a2c | 2015-03-27 11:36:34 +0200 | [diff] [blame] | 51 | if [ "$counter" -eq "$TIMEOUT" ] |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 52 | then |
| 53 | echo "Time limit exceed" |
| 54 | break |
| 55 | fi |
| 56 | done |
| 57 | } |
| 58 | |
| 59 | |
| 60 | function wait_floating_ip() { |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 61 | floating_ip="|" |
| 62 | vm_name=$VM_NAME |
| 63 | counter=0 |
| 64 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 65 | while [ "$floating_ip" != "|" ] ; do |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 66 | sleep 1 |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 67 | floating_ip=$(nova floating-ip-list | grep "$vm_name" | awk '{print $13}' | head -1) |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 68 | 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 | |
| 79 | function wait_vm_deleted() { |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 80 | vm_name=$(nova list| grep "$VM_NAME"| awk '{print $4}'| head -1) |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 81 | counter=0 |
| 82 | |
| 83 | while [ ! -z $vm_name ] ; do |
| 84 | sleep 1 |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 85 | vm_name=$(nova list| grep "$VM_NAME"| awk '{print $4}'| head -1) |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 86 | counter=$((counter + 1)) |
| 87 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 88 | if [ "$counter" -eq $TIMEOUT ] |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 89 | then |
| 90 | echo "Time limit exceed" |
| 91 | break |
| 92 | fi |
| 93 | done |
| 94 | } |
| 95 | |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 96 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 97 | function get_floating_ip() { |
| 98 | IP=$(nova floating-ip-list | grep "$FLOATING_NET" | awk '{if ($5 == "-") print $2}' | head -n1) |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 99 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 100 | if [ -z "$IP" ]; then # fix net name |
| 101 | IP=$(nova floating-ip-create "$FLOATING_NET"| awk '{print $2}') |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 102 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 103 | if [ -z "$list" ]; then |
| 104 | echo "Cannot allocate new floating ip" |
gstepanov | d282663 | 2015-04-02 15:01:18 +0300 | [diff] [blame] | 105 | # exit |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 106 | fi |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 107 | fi |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 108 | |
gstepanov | d282663 | 2015-04-02 15:01:18 +0300 | [diff] [blame] | 109 | echo $FLOATING_NET |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 110 | export VM_IP=$IP |
| 111 | echo "VM_IP: $VM_IP" |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 112 | } |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 113 | |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 114 | function run_openrc() { |
gstepanov | d282663 | 2015-04-02 15:01:18 +0300 | [diff] [blame] | 115 | source run_vm.sh "$FUEL_MASTER_IP" "$FUEL_MASTER_PASSWD" "$EXTERNAL_IP" novanetwork nova |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 116 | source `get_openrc` |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 117 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 118 | list=$(nova list) |
| 119 | if [ "$list" == "" ]; then |
| 120 | echo "openrc variables are unset or set to the empty string" |
| 121 | fi |
| 122 | |
gstepanov | d282663 | 2015-04-02 15:01:18 +0300 | [diff] [blame] | 123 | echo "AUTH_URL: $OS_AUTH_URL" |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 124 | } |
| 125 | |
koder aka kdanilov | fb23a26 | 2015-03-27 16:50:58 +0200 | [diff] [blame] | 126 | get_arguments $@ |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 127 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 128 | echo "getting openrc from controller node" |
gstepanov | b65b9a8 | 2015-03-28 18:09:17 +0200 | [diff] [blame] | 129 | run_openrc |
koder aka kdanilov | fb23a26 | 2015-03-27 16:50:58 +0200 | [diff] [blame] | 130 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 131 | echo "openrc has been activated on your machine" |
| 132 | get_floating_ip |
koder aka kdanilov | fb23a26 | 2015-03-27 16:50:58 +0200 | [diff] [blame] | 133 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 134 | echo "floating ip has been found" |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 135 | bash prepare.sh |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 136 | echo "Image has been sended to glance" |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 137 | wait_image_active |
| 138 | echo "Image has been saved" |
koder aka kdanilov | fb23a26 | 2015-03-27 16:50:58 +0200 | [diff] [blame] | 139 | |
| 140 | BOOT_LOG_FILE=`tempfile` |
| 141 | boot_vm | tee "$BOOT_LOG_FILE" |
| 142 | VOL_ID=$(cat "$BOOT_LOG_FILE" | grep "VOL_ID=" | sed 's/VOL_ID=//') |
| 143 | rm "$BOOT_LOG_FILE" |
| 144 | |
gstepanov | 08c0d7e | 2015-03-25 23:55:44 +0200 | [diff] [blame] | 145 | echo "VM has been booted" |
| 146 | wait_floating_ip |
| 147 | echo "Floating IP has been obtained" |
| 148 | source `prepare_vm` |
| 149 | echo "VM has been prepared" |
gstepanov | cddbe3b | 2015-03-26 19:05:48 +0200 | [diff] [blame] | 150 | |
gstepanov | 3d2a915 | 2015-03-27 15:46:20 +0200 | [diff] [blame] | 151 | # sudo bash ../single_node_test_short.sh $FILE_TO_TEST $RESULT_FILE |
gstepanov | cddbe3b | 2015-03-26 19:05:48 +0200 | [diff] [blame] | 152 | |
gstepanov | d282663 | 2015-04-02 15:01:18 +0300 | [diff] [blame] | 153 | ssh $SSH_OPTS -i $KEY_FILE_NAME ubuntu@$VM_IP \ |
| 154 | "cd /tmp/io_scenario;" |
gstepanov | cddbe3b | 2015-03-26 19:05:48 +0200 | [diff] [blame] | 155 | |
gstepanov | d282663 | 2015-04-02 15:01:18 +0300 | [diff] [blame] | 156 | # echo 'results' > $RESULT_FILE; \ |
| 157 | # curl -X POST -d @$RESULT_FILE http://http://172.16.52.80/api/test --header 'Content-Type:application/json' |
| 158 | |
| 159 | # nova delete $VM_NAME |
| 160 | # wait_vm_deleted |
| 161 | # echo "$VM_NAME has been deleted successfully" |
| 162 | # cinder delete $VOL_ID |
| 163 | # echo "Volume has been deleted $VOL_ID" |