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 | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame] | 3 | if [ "$#" -lt 1 ]; then |
| 4 | echo "Usage: $0 <lab-name> [<demo repo directory>]" |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 5 | exit 1 |
| 6 | fi |
| 7 | |
Gary Wu | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame] | 8 | |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 9 | if [ -z "$WORKSPACE" ]; then |
| 10 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 11 | fi |
| 12 | |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 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 | |
Gary Wu | 838c34d | 2017-10-23 14:22:40 -0700 | [diff] [blame] | 20 | source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 21 | |
Gary Wu | b84428e | 2017-10-30 11:09:27 -0700 | [diff] [blame] | 22 | |
Gary Wu | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame] | 23 | DEMO_DIR=${ONAP_WORKDIR}/demo |
| 24 | if [ "$#" -ge 2 ]; then |
| 25 | DEMO_DIR=$2 |
| 26 | fi |
| 27 | |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 28 | SENTINEL='Docker versions and branches' |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 29 | |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 30 | mkdir -p ${LAB_DIR}/target |
Gary Wu | 2845d14 | 2018-08-01 12:02:37 -0700 | [diff] [blame] | 31 | rsync -avt $DEMO_DIR/heat/ONAP/ ${LAB_DIR}/target/ |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 32 | YAML_FILE=${LAB_DIR}/target/onap_openstack.yaml |
| 33 | ENV_FILE=${LAB_DIR}/target/onap_openstack.env |
Gary Wu | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame] | 34 | YAML_SRC=${DEMO_DIR}/heat/ONAP/onap_openstack.yaml |
| 35 | ENV_SRC=${DEMO_DIR}/heat/ONAP/onap_openstack.env |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 36 | |
| 37 | # copy heat template to WORKSPACE |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 38 | cp ${YAML_SRC} ${YAML_FILE} |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 39 | |
| 40 | # generate final env file |
Gary Wu | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame] | 41 | pushd ${DEMO_DIR} |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 42 | 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] | 43 | 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] | 44 | echo " #" $(git config --get remote.origin.url) heat/ONAP/onap_openstack.env $(git rev-parse HEAD) | tee -a ${ENV_FILE} |
| 45 | popd |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 46 | sed "1,/${SENTINEL}/d" ${ENV_SRC} >> ${ENV_FILE} |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 47 | cat ${ENV_FILE} |
| 48 | |
Gary Wu | a254fab | 2018-04-03 07:52:28 -0700 | [diff] [blame] | 49 | diff ${ENV_SRC} ${ENV_FILE} |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 50 | |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 51 | # generate final heat template |
| 52 | # add apt proxy to heat template if applicable |
| 53 | if [ -x $LAB_DIR/apt-proxy.sh ]; then |
| 54 | $LAB_DIR/apt-proxy.sh ${YAML_FILE} |
Gary Wu | a254fab | 2018-04-03 07:52:28 -0700 | [diff] [blame] | 55 | diff ${YAML_SRC} ${YAML_FILE} |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | |
| 59 | #exit 0 |
| 60 | |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 61 | #diff ${LAB_DIR}/onap-openstack-template.env ${LAB_DIR}/onap-openstack.env |
Gary Wu | b84428e | 2017-10-30 11:09:27 -0700 | [diff] [blame] | 62 | |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 63 | |
| 64 | # tear down old deployment |
Gary Wu | f88c630 | 2018-08-08 12:55:58 -0700 | [diff] [blame] | 65 | $WORKSPACE/test/ete/scripts/teardown-onap.sh -q |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 66 | |
| 67 | # create new stack |
Gary Wu | cbb3d88 | 2018-08-01 07:50:30 -0700 | [diff] [blame] | 68 | STACK="onap-heat-$(uuidgen | cut -c-4)" |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 69 | echo "New Stack Name: ${STACK}" |
Gary Wu | a254fab | 2018-04-03 07:52:28 -0700 | [diff] [blame] | 70 | if ! openstack stack create -t ${YAML_FILE} -e ${ENV_FILE} $STACK; then |
| 71 | exit 1 |
| 72 | fi |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 73 | |
Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 74 | 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] | 75 | sleep 20 |
Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 76 | done |
| 77 | |
| 78 | STATUS=$(openstack stack show -c stack_status -f value $STACK) |
| 79 | echo $STATUS |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 80 | if [ "CREATE_COMPLETE" != "$STATUS" ]; then |
| 81 | exit 1 |
| 82 | fi |
| 83 | |
| 84 | |
| 85 | # wait until Robot VM initializes |
Gary Wu | a3f31bd | 2017-11-09 17:11:01 -0800 | [diff] [blame] | 86 | ROBOT_IP=$($WORKSPACE/test/ete/scripts/get-floating-ip.sh onap-robot) |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 87 | echo "ROBOT_IP=${ROBOT_IP}" |
| 88 | |
| 89 | if [ "" == "${ROBOT_IP}" ]; then |
| 90 | exit 1 |
| 91 | fi |
| 92 | |
| 93 | ssh-keygen -R ${ROBOT_IP} |
| 94 | |
| 95 | SSH_KEY=~/.ssh/onap_key |
| 96 | |
Gary Wu | 3e4eede | 2018-04-17 17:33:07 -0700 | [diff] [blame] | 97 | for n in $(seq 1 10); do |
| 98 | ssh -o StrictHostKeychecking=no -i ${SSH_KEY} ubuntu@${ROBOT_IP} "sudo docker ps" | grep openecompete_container |
| 99 | RESULT=$? |
| 100 | if [ $RESULT -eq 0 ]; then |
| 101 | break |
| 102 | fi |
| 103 | sleep 2m |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 104 | done |