Add hosts config
[bottlenecks.git] / utils / infra_setup / heat_template / HOT_create_instance.sh
index 8ca54b0..4de29b3 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
-set -ex
+set -x
+
+GERRIT_REFSPEC_DEBUG=$1
 
 bottlenecks_env_prepare()
 {
@@ -11,6 +13,11 @@ bottlenecks_env_prepare()
     mkdir -p ${BOTTLENECKS_REPO_DIR}
     git config --global http.sslVerify false
     git clone ${BOTTLENECKS_REPO} ${BOTTLENECKS_REPO_DIR}
+    if [ x"$GERRIT_REFSPEC_DEBUG" != x ]; then
+        cd ${BOTTLENECKS_REPO_DIR}
+        git fetch $BOTTLENECKS_REPO $GERRIT_REFSPEC_DEBUG && git checkout FETCH_HEAD
+        cd -
+    fi
 
     source $BOTTLENECKS_REPO_DIR/rubbos/rubbos_scripts/1-1-1/scripts/env_preparation.sh
     chmod 600 $KEY_PATH/bottlenecks_key
@@ -24,13 +31,26 @@ wait_heat_stack_complete() {
         if [ x$status = x"CREATE_COMPLETE" ]; then
             echo "bottlenecks stacke create complete"
             heat stack-show bottlenecks
+            nova list | grep rubbos_
             break;
+        elif [ x$status = x"CREATE_FAILED" ]; then
+            echo "bottlenecks stacke create failed !!!"
+            heat stack-show bottlenecks
+            exit 1
+        fi
+
+        if [ $BOTTLENECKS_DEBUG = True ]; then
+            heat stack-show bottlenecks
+            nova list | grep rubbos_
+            for i in $(nova list | grep rubbos_ | grep ERROR | awk '{print $2}')
+            do
+                 nova show $i
+            done
         fi
-        echo "bottlenecks stack status $status"
         sleep 1
         let retry+=1
         if [[ $retry -ge $1 ]];then
-            echo "Heat stack create timeout!!!"
+            echo "Heat stack create timeout, status $status !!!"
             exit 1
         fi
     done
@@ -40,7 +60,7 @@ wait_rubbos_control_ok() {
     control_ip=$(nova list | grep rubbos_control | awk '{print $13}')
 
     retry=0
-    until timeout 1s ssh $ssh_args ec2-user@$control_ip "exit" >/dev/null 2>&1
+    until timeout 3s ssh $ssh_args ec2-user@$control_ip "exit" >/dev/null 2>&1
     do
         echo "retry connect rubbos control $retry"
         sleep 1
@@ -60,6 +80,27 @@ bottlenecks_check_instance_ok()
     wait_heat_stack_complete 120
     wait_rubbos_control_ok 300
     nova list | grep rubbos_
+    if [ $BOTTLENECKS_DEBUG = True ]; then
+        date
+        while true
+        do
+            for i in rubbos_benchmark rubbos_client1 rubbos_client2 rubbos_client3 \
+                     rubbos_client4 rubbos_control rubbos_httpd rubbos_mysql1 rubbos_tomcat1
+            do
+               echo "logging $i"
+               nova console-log $i | tail -n 2 | grep Cloud-init | grep finished
+               if [ $? != 0 ]; then
+                   break
+               fi
+               if [ $i = rubbos_tomcat1 ]; then
+                   echo "all vm Cloud-init finished!"
+                   date
+                   return
+               fi
+            done
+            sleep 10
+        done
+    fi
 }
 
 bottlenecks_create_instance()
@@ -70,7 +111,7 @@ bottlenecks_create_instance()
     nova keypair-add --pub_key $KEY_PATH/bottlenecks_key.pub $KEY_NAME
 
     echo "create flavor"
-    nova flavor-create $FLAVOR_NAME 200 2048 10 1
+    nova flavor-create $FLAVOR_NAME 200 4096 20 4
 
     echo "use heat template to create stack"
     cd $HOT_PATH
@@ -90,6 +131,12 @@ bottlenecks_rubbos_run()
           echo "$i=$ip" >> $BOTTLENECKS_REPO_DIR/utils/infra_setup/vm_dev_setup/hosts.conf
     done
 
+    nameserver_ip=$(grep -m 1 '^nameserver' \
+        /etc/resolv.conf | awk '{ print $2 '})
+    echo "nameserver_ip=$nameserver_ip" >> $BOTTLENECKS_REPO_DIR/utils/infra_setup/vm_dev_setup/hosts.conf
+
+    echo "GERRIT_REFSPEC_DEBUG=$GERRIT_REFSPEC_DEBUG" >> $BOTTLENECKS_REPO_DIR/utils/infra_setup/vm_dev_setup/hosts.conf
+
     scp $ssh_args -r \
         $BOTTLENECKS_REPO_DIR/utils/infra_setup/vm_dev_setup \
         ec2-user@$control_ip:/tmp
@@ -161,10 +208,11 @@ main()
 {
     echo "create instances with heat template"
 
+    BOTTLENECKS_DEBUG=True
     BOTTLENECKS_REPO=https://gerrit.opnfv.org/gerrit/bottlenecks
     BOTTLENECKS_REPO_DIR=/tmp/opnfvrepo/bottlenecks
-    #IMAGE_URL=http://artifacts.opnfv.org/bottlenecks/rubbos/bottlenecks-trusty-server.img
-    IMAGE_URL=https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
+    IMAGE_URL=http://artifacts.opnfv.org/bottlenecks/rubbos/bottlenecks-trusty-server.img
+    #IMAGE_URL=https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
     IMAGE_NAME=bottlenecks-trusty-server
     KEY_PATH=$BOTTLENECKS_REPO_DIR/utils/infra_setup/bottlenecks_key
     HOT_PATH=$BOTTLENECKS_REPO_DIR/utils/infra_setup/heat_template
@@ -184,5 +232,5 @@ main()
 }
 
 main
-set +ex
+set +x