Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 1 | #!/bin/bash -x |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 2 | |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 3 | if [ "$#" -ne 1 ]; then |
| 4 | echo "Usage: $0 <lab-name>" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 8 | if [ -z "$WORKSPACE" ]; then |
| 9 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 10 | fi |
| 11 | |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 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 | |
Gary Wu | 838c34d | 2017-10-23 14:22:40 -0700 | [diff] [blame] | 19 | source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 20 | |
Gary Wu | b84428e | 2017-10-30 11:09:27 -0700 | [diff] [blame] | 21 | |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 22 | SENTINEL='Docker versions and branches' |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame^] | 23 | |
| 24 | YAML_FILE=${LAB_DIR}/onap_openstack.yaml |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 25 | ENV_FILE=${LAB_DIR}/onap-openstack.env |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame^] | 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 |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 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} |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame^] | 34 | echo " # Rest of the file was AUTO-GENERATED from" | tee -a ${ENV_FILE} |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 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 | |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame^] | 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 | |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 50 | #diff ${LAB_DIR}/onap-openstack-template.env ${LAB_DIR}/onap-openstack.env |
Gary Wu | b84428e | 2017-10-30 11:09:27 -0700 | [diff] [blame] | 51 | |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame^] | 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}" |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 59 | openstack stack create -t ${YAML_FILE} -e ${LAB_DIR}/onap-openstack.env $STACK |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 60 | |
Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 61 | while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $STACK)" ]; do |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 62 | sleep 20 |
Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 63 | done |
| 64 | |
| 65 | STATUS=$(openstack stack show -c stack_status -f value $STACK) |
| 66 | echo $STATUS |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 67 | if [ "CREATE_COMPLETE" != "$STATUS" ]; then |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | |
| 72 | # wait until Robot VM initializes |
Gary Wu | a3f31bd | 2017-11-09 17:11:01 -0800 | [diff] [blame] | 73 | ROBOT_IP=$($WORKSPACE/test/ete/scripts/get-floating-ip.sh onap-robot) |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 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 |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 86 | sleep 2m |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 87 | done |