Merge "Updated the Version of Stating Dockers"
[integration.git] / deployment / heat / onap-oom / scripts / deploy.sh
index c3418fa..c3a73c7 100755 (executable)
@@ -17,10 +17,11 @@ if [ -z "$WORKSPACE" ]; then
 fi
 
 usage() {
-    echo "Usage: $0 [ -n <number of VMs {2-15}> ] [ -s <stack name> ][ -b <branch name> ][ -r ] <env>" 1>&2;
+    echo "Usage: $0 [ -n <number of VMs {2-15}> ][ -s <stack name> ][ -m <manifest> ][ -r ][ -q ] <env>" 1>&2;
 
     echo "n:    Set the number of VM's that will be installed. This number must be between 2 and 15" 1>&2;
     echo "s:    Set the name to be used for stack. This name will be used for naming of resources" 1>&2;
+    echo "m:    The docker manifest to apply; must be either \"docker-manifest-staging.csv\" or \"docker-manifest.csv\"." 1>&2;
     echo "r:    Delete all resources relating to ONAP within enviroment." 1>&2;
     echo "q:    Quiet Delete of all ONAP resources." 1>&2;
 
@@ -28,7 +29,7 @@ usage() {
 }
 
 
-while getopts ":n:s:rq" o; do
+while getopts ":n:s:m:rq" o; do
     case "${o}" in
         n)
             if [[ ${OPTARG} =~ ^[0-9]+$ ]];then
@@ -48,6 +49,13 @@ while getopts ":n:s:rq" o; do
                 usage
             fi
             ;;
+        m)
+            if [ -f $WORKSPACE/version-manifest/src/main/resources/${OPTARG} ]; then
+                docker_manifest=${OPTARG}
+            else
+                usage
+            fi
+            ;;
         r)
             echo "The following command will delete all information relating to onap within your enviroment"
             read -p "Are you certain this is what you want? (type y to confirm):" answer
@@ -112,7 +120,7 @@ for n in $(seq 1 5); do
         ./scripts/gen-onap-oom-yaml.sh $vm_num > onap-oom.yaml~
     fi
 
-    if ! openstack stack create -t ./onap-oom.yaml~ -e $ENV_FILE~ $stack_name; then
+    if ! openstack stack create -t ./onap-oom.yaml~ -e $ENV_FILE~ $stack_name --parameter docker_manifest=$docker_manifest; then
         break
     fi
 
@@ -145,30 +153,39 @@ fi
 
 ssh-keygen -R $RANCHER_IP
 
+sleep 2m
 ssh -o StrictHostKeychecking=no -i $SSH_KEY ubuntu@$RANCHER_IP "sed -u '/Cloud-init.*finished/q' <(tail -n+0 -f /var/log/cloud-init-output.log)"
 
-for n in $(seq 1 6); do
-    echo "Wait count $n of 6"
-    sleep 15m
-    timeout 15m ssh -i $SSH_KEY ubuntu@$RANCHER_IP  'sudo su -l root -c "/root/oom/kubernetes/robot/ete-k8s.sh onap health"'
-    RESULT=$?
-    if [ $RESULT -eq 0 ]; then
-       break
-    fi
+PREV_RESULT=0
+for n in $(seq 1 20); do
+  RESULT=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl -n onap get pods"' | grep -vE 'Running|Complete|NAME' | wc -l)
+  if [[ $? -eq 0 && ( $RESULT -eq 0 || $RESULT -eq $PREV_RESULT ) ]]; then
+    break
+  fi
+  sleep 15m
+  PREV_RESULT=$RESULT
+done
+
+PREV_RESULT=0
+for n in $(seq 1 20); do
+  echo "Wait for HEALTHCHECK count $n of 10"
+  ROBOT_POD=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl --namespace onap get pods"' | grep robot | sed 's/ .*//')
+  ssh -i $SSH_KEY ubuntu@$RANCHER_IP  'sudo su -l root -c "/root/oom/kubernetes/robot/ete-k8s.sh onap health"'
+  RESULT=$?
+  if [[ $RESULT -lt 10 && ( $RESULT -eq 0 || $RESULT -eq $PREV_RESULT ) ]]; then
+    break
+  fi
+  sleep 15m
+  PREV_RESULT=$RESULT
 done
-ROBOT_POD=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl --namespace onap get pods"' | grep robot | sed 's/ .*//')
 if [ "$ROBOT_POD" == "" ]; then
-    exit 1
+  exit 1
 fi
 
 LOG_DIR=$(echo "kubectl exec -n onap $ROBOT_POD -- ls -1t /share/logs | grep health | head -1" | ssh -i $SSH_KEY ubuntu@$RANCHER_IP sudo su)
-if [ "$LOG_DIR" == "" ]; then
-    exit 1
-fi
-
 echo "kubectl cp -n onap $ROBOT_POD:share/logs/$LOG_DIR /tmp/robot/logs/$LOG_DIR" | ssh -i $SSH_KEY ubuntu@$RANCHER_IP sudo su
-rsync -e "ssh -i $SSH_KEY" -avtz ubuntu@$RANCHER_IP:/tmp/robot/logs/$LOG_DIR/ $WORKSPACE/archives/
-
 echo "Browse Robot results at http://$K8S_IP:30209/logs/$LOG_DIR/"
+mkdir -p $WORKSPACE/archives/healthcheck
+rsync -e "ssh -i $SSH_KEY" -avtz ubuntu@$RANCHER_IP:/tmp/robot/logs/$LOG_DIR/ $WORKSPACE/archives/healthcheck
 
 exit 0