Merge "Correction in created message."
[integration.git] / test / ete / scripts / deploy-onap.sh
1 #!/bin/bash -x
2
3 if [ "$#" -lt 1 ]; then
4     echo "Usage: $0 <lab-name> [<demo repo directory>]"
5     exit 1
6 fi
7
8
9 if [ -z "$WORKSPACE" ]; then
10     export WORKSPACE=`git rev-parse --show-toplevel`
11 fi
12
13 LAB_DIR=${WORKSPACE}/test/ete/labs/$1
14
15 if [ ! -d "$LAB_DIR" ]; then
16     echo "Directory $LAB_DIR not found"
17     exit 2
18 fi
19
20 source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh
21
22
23 DEMO_DIR=${ONAP_WORKDIR}/demo
24 if [ "$#" -ge 2 ]; then
25     DEMO_DIR=$2
26 fi
27
28 SENTINEL='Docker versions and branches'
29
30 mkdir -p ${LAB_DIR}/target
31 YAML_FILE=${LAB_DIR}/target/onap_openstack.yaml
32 ENV_FILE=${LAB_DIR}/target/onap_openstack.env
33 YAML_SRC=${DEMO_DIR}/heat/ONAP/onap_openstack.yaml
34 ENV_SRC=${DEMO_DIR}/heat/ONAP/onap_openstack.env
35
36 # copy heat template to WORKSPACE
37 cp ${YAML_SRC} ${YAML_FILE}
38
39 # generate final env file
40 pushd ${DEMO_DIR}
41 envsubst < ${LAB_DIR}/onap-openstack-template.env | sed -n "1,/${SENTINEL}/p" > ${ENV_FILE}
42 echo "  # Rest of the file was AUTO-GENERATED from" | tee -a ${ENV_FILE}
43 echo "  #" $(git config --get remote.origin.url) heat/ONAP/onap_openstack.env $(git rev-parse HEAD) | tee -a ${ENV_FILE}
44 popd
45 sed "1,/${SENTINEL}/d" ${ENV_SRC} >> ${ENV_FILE}
46 cat ${ENV_FILE}
47
48 diff ${ENV_SRC} ${ENV_FILE}
49
50 # generate final heat template
51 # add apt proxy to heat template if applicable
52 if [ -x $LAB_DIR/apt-proxy.sh ]; then
53     $LAB_DIR/apt-proxy.sh ${YAML_FILE}
54     diff ${YAML_SRC} ${YAML_FILE}
55 fi
56
57
58 #exit 0
59
60 #diff ${LAB_DIR}/onap-openstack-template.env ${LAB_DIR}/onap-openstack.env
61
62
63 # tear down old deployment
64 $WORKSPACE/test/ete/scripts/teardown-onap.sh
65
66 # create new stack
67 STACK="ete-$(uuidgen | cut -c-8)"
68 echo "New Stack Name: ${STACK}"
69 if ! openstack stack create -t ${YAML_FILE} -e ${ENV_FILE} $STACK; then
70     exit 1
71 fi
72
73 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $STACK)" ]; do
74     sleep 20
75 done
76
77 STATUS=$(openstack stack show -c stack_status -f value $STACK)
78 echo $STATUS
79 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
80     exit 1
81 fi
82
83
84 # wait until Robot VM initializes
85 ROBOT_IP=$($WORKSPACE/test/ete/scripts/get-floating-ip.sh onap-robot)
86 echo "ROBOT_IP=${ROBOT_IP}"
87
88 if [ "" == "${ROBOT_IP}" ]; then
89     exit 1
90 fi
91
92 ssh-keygen -R ${ROBOT_IP}
93
94 SSH_KEY=~/.ssh/onap_key
95
96 for n in $(seq 1 10); do
97     ssh -o StrictHostKeychecking=no -i ${SSH_KEY} ubuntu@${ROBOT_IP} "sudo docker ps" | grep openecompete_container
98     RESULT=$?
99     if [ $RESULT -eq 0 ]; then
100       break
101     fi
102     sleep 2m
103 done