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 |
| 31 | YAML_FILE=${LAB_DIR}/target/onap_openstack.yaml |
| 32 | ENV_FILE=${LAB_DIR}/target/onap_openstack.env |
Gary Wu | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame^] | 33 | YAML_SRC=${DEMO_DIR}/heat/ONAP/onap_openstack.yaml |
| 34 | ENV_SRC=${DEMO_DIR}/heat/ONAP/onap_openstack.env |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 35 | |
| 36 | # copy heat template to WORKSPACE |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 37 | cp ${YAML_SRC} ${YAML_FILE} |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 38 | |
| 39 | # generate final env file |
Gary Wu | 4e98013 | 2018-05-17 15:38:07 -0700 | [diff] [blame^] | 40 | pushd ${DEMO_DIR} |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 41 | 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] | 42 | 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] | 43 | echo " #" $(git config --get remote.origin.url) heat/ONAP/onap_openstack.env $(git rev-parse HEAD) | tee -a ${ENV_FILE} |
| 44 | popd |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 45 | sed "1,/${SENTINEL}/d" ${ENV_SRC} >> ${ENV_FILE} |
Gary Wu | 3cad6f3 | 2017-11-15 23:29:11 -0800 | [diff] [blame] | 46 | cat ${ENV_FILE} |
| 47 | |
Gary Wu | a254fab | 2018-04-03 07:52:28 -0700 | [diff] [blame] | 48 | diff ${ENV_SRC} ${ENV_FILE} |
Gary Wu | b57cc8f | 2018-01-12 01:17:32 -0800 | [diff] [blame] | 49 | |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 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} |
Gary Wu | a254fab | 2018-04-03 07:52:28 -0700 | [diff] [blame] | 54 | diff ${YAML_SRC} ${YAML_FILE} |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 55 | fi |
| 56 | |
| 57 | |
| 58 | #exit 0 |
| 59 | |
Gary Wu | f823343 | 2018-01-05 13:16:26 -0800 | [diff] [blame] | 60 | #diff ${LAB_DIR}/onap-openstack-template.env ${LAB_DIR}/onap-openstack.env |
Gary Wu | b84428e | 2017-10-30 11:09:27 -0700 | [diff] [blame] | 61 | |
Gary Wu | d83efff | 2018-01-09 16:47:30 -0800 | [diff] [blame] | 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}" |
Gary Wu | a254fab | 2018-04-03 07:52:28 -0700 | [diff] [blame] | 69 | if ! openstack stack create -t ${YAML_FILE} -e ${ENV_FILE} $STACK; then |
| 70 | exit 1 |
| 71 | fi |
Gary Wu | 874794d | 2017-10-13 12:27:39 -0700 | [diff] [blame] | 72 | |
Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 73 | 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] | 74 | sleep 20 |
Gary Wu | f5fef8b | 2017-11-09 10:59:46 -0800 | [diff] [blame] | 75 | done |
| 76 | |
| 77 | STATUS=$(openstack stack show -c stack_status -f value $STACK) |
| 78 | echo $STATUS |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 79 | if [ "CREATE_COMPLETE" != "$STATUS" ]; then |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | |
| 84 | # wait until Robot VM initializes |
Gary Wu | a3f31bd | 2017-11-09 17:11:01 -0800 | [diff] [blame] | 85 | ROBOT_IP=$($WORKSPACE/test/ete/scripts/get-floating-ip.sh onap-robot) |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 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 | |
Gary Wu | 3e4eede | 2018-04-17 17:33:07 -0700 | [diff] [blame] | 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 |
Gary Wu | 778b41b | 2017-11-09 12:08:24 -0800 | [diff] [blame] | 103 | done |