Remove noop code
[integration/csit.git] / scripts / sdc / setup_sdc_for_sanity.sh
1 #!/bin/bash
2
3 function usage {
4     echo "usage: setup_sdc_for_sanity.sh {tad|tud}"
5     echo "setup sdc and run api test suite: setup_sdc_for_sanity.sh tad"
6     echo "setup sdc and run ui test suite: setup_sdc_for_sanity.sh tud"
7 }
8
9 # returns 0: if SDC_LOCAL_IMAGES is set to true value
10 # returns 1: otherwise
11 function using_local_images {
12     SDC_LOCAL_IMAGES=$(echo "${SDC_LOCAL_IMAGES}" | tr '[:upper:]' '[:lower:]')
13
14     case "$SDC_LOCAL_IMAGES" in
15         1|yes|true|Y)
16             return 0
17             ;;
18     esac
19
20     return 1
21 }
22
23 # fail quick if error
24 set -exo pipefail
25
26 echo "This is ${WORKSPACE}/scripts/sdc/setup_sdc_for_sanity.sh"
27
28
29 if [ "$1" != "tad" ] && [ "$1" != "tud" ]; then
30     usage
31     exit 1
32 fi
33
34 # Clone sdc enviroment template
35 mkdir -p ${WORKSPACE}/data/environments/
36 mkdir -p ${WORKSPACE}/data/clone/
37
38 cd ${WORKSPACE}/data/clone
39 if using_local_images && [ -n "$SDC_LOCAL_GITREPO" ] ; then
40     if [ -d "$SDC_LOCAL_GITREPO" ] ; then
41         rm -rf ./sdc
42         cp -a "$SDC_LOCAL_GITREPO" ./sdc
43     else
44         echo "[ERROR]: Local git repo for sdc does not exist: ${SDC_LOCAL_GITREPO}"
45         exit 1
46     fi
47 else
48     git clone --depth 1 http://gerrit.onap.org/r/sdc -b ${GERRIT_BRANCH}
49 fi
50
51 chmod -R 777 ${WORKSPACE}/data/clone
52
53 # set enviroment variables
54
55 export ENV_NAME='CSIT'
56 export MR_IP_ADDR='10.0.0.1'
57 export TEST_SUITE=$1
58
59 ifconfig
60 IP_ADDRESS=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
61 export HOST_IP=$IP_ADDRESS
62
63 # setup enviroment json
64
65 cat ${WORKSPACE}/data/clone/sdc/sdc-os-chef/environments/Template.json | sed "s/yyy/"$IP_ADDRESS"/g" > ${WORKSPACE}/data/environments/$ENV_NAME.json
66 sed -i "s/xxx/"$ENV_NAME"/g" ${WORKSPACE}/data/environments/$ENV_NAME.json
67 sed -i "s/\"ueb_url_list\":.*/\"ueb_url_list\": \""$MR_IP_ADDR","$MR_IP_ADDR"\",/g" ${WORKSPACE}/data/environments/$ENV_NAME.json
68 sed -i "s/\"fqdn\":.*/\"fqdn\": [\""$MR_IP_ADDR"\", \""$MR_IP_ADDR"\"]/g" ${WORKSPACE}/data/environments/$ENV_NAME.json
69
70 cp ${WORKSPACE}/data/clone/sdc/sdc-os-chef/scripts/docker_run.sh ${WORKSPACE}/scripts/sdc/
71
72 source ${WORKSPACE}/data/clone/sdc/version.properties
73 export RELEASE=$major.$minor-STAGING-latest
74
75 if using_local_images ; then
76     if [ -n "$SDC_LOCAL_TAG" ] ; then
77         RELEASE="$SDC_LOCAL_TAG"
78     elif [ -z "$SDC_LOCAL_GITREPO" ] ; then
79         echo "[WARNING]: Local images used but no tag and no source (git repo) provided for them - we will use tag 'latest'"
80         RELEASE=latest
81     fi
82
83     echo "[INFO]: We will use the locally built images (tag: ${RELEASE})"
84     ${WORKSPACE}/scripts/sdc/docker_run.sh \
85         --local \
86         -r ${RELEASE} \
87         -e ${ENV_NAME} \
88         -p 10001 -${TEST_SUITE}
89 else
90     echo "[INFO]: We will download images from the default registry (tag: ${RELEASE})"
91     ${WORKSPACE}/scripts/sdc/docker_run.sh \
92         -r ${RELEASE} \
93         -e ${ENV_NAME} \
94         -p 10001 -${TEST_SUITE}
95 fi
96
97 # This file is sourced in another script which is out of our control...
98 set +e
99 set +o pipefail
100