96d42a0b1bcd0c7ab8325284c81bf799216154d7
[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 mkdir -p ${LAB_DIR}/target
25 YAML_FILE=${LAB_DIR}/target/onap_openstack.yaml
26 ENV_FILE=${LAB_DIR}/target/onap_openstack.env
27 YAML_SRC=${ONAP_WORKDIR}/demo/heat/ONAP/onap_openstack.yaml
28 ENV_SRC=${ONAP_WORKDIR}/demo/heat/ONAP/onap_openstack.env
29
30 # copy heat template to WORKSPACE
31 cp ${YAML_SRC} ${YAML_FILE}
32
33 # generate final env file
34 pushd ${ONAP_WORKDIR}/demo
35 envsubst < ${LAB_DIR}/onap-openstack-template.env | sed -n "1,/${SENTINEL}/p" > ${ENV_FILE}
36 echo "  # Rest of the file was AUTO-GENERATED from" | tee -a ${ENV_FILE}
37 echo "  #" $(git config --get remote.origin.url) heat/ONAP/onap_openstack.env $(git rev-parse HEAD) | tee -a ${ENV_FILE}
38 popd
39 sed "1,/${SENTINEL}/d" ${ENV_SRC} >> ${ENV_FILE}
40 cat ${ENV_FILE}
41
42 sdiff -w 180 ${ENV_SRC} ${ENV_FILE}
43
44 # generate final heat template
45 # add apt proxy to heat template if applicable
46 if [ -x $LAB_DIR/apt-proxy.sh ]; then
47     $LAB_DIR/apt-proxy.sh ${YAML_FILE}
48     sdiff -w 180 ${YAML_SRC} ${YAML_FILE}
49 fi
50
51
52 #exit 0
53
54 #diff ${LAB_DIR}/onap-openstack-template.env ${LAB_DIR}/onap-openstack.env
55
56
57 # tear down old deployment
58 $WORKSPACE/test/ete/scripts/teardown-onap.sh
59
60 # create new stack
61 STACK="ete-$(uuidgen | cut -c-8)"
62 echo "New Stack Name: ${STACK}"
63 openstack stack create -t ${YAML_FILE} -e ${ENV_FILE} $STACK
64
65 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $STACK)" ]; do
66     sleep 20
67 done
68
69 STATUS=$(openstack stack show -c stack_status -f value $STACK)
70 echo $STATUS
71 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
72     exit 1
73 fi
74
75
76 # wait until Robot VM initializes
77 ROBOT_IP=$($WORKSPACE/test/ete/scripts/get-floating-ip.sh onap-robot)
78 echo "ROBOT_IP=${ROBOT_IP}"
79
80 if [ "" == "${ROBOT_IP}" ]; then
81     exit 1
82 fi
83
84 ssh-keygen -R ${ROBOT_IP}
85
86 SSH_KEY=~/.ssh/onap_key
87
88 until ssh -o StrictHostKeychecking=no -i ${SSH_KEY} root@${ROBOT_IP} "docker ps | grep -q openecompete_container"
89 do
90       sleep 2m
91 done