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