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