2d644c3f7d18e5667182cabd129e0fceeea3e286
[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 # arg: <variable name>
10 # returns 0: if <variable name> is set to true value
11 # returns 1: otherwise
12 function is_true {
13     _value=$(eval echo "\$${1}" | tr '[:upper:]' '[:lower:]')
14
15     case "$_value" in
16         1|yes|true|Y)
17             return 0
18             ;;
19     esac
20
21     return 1
22 }
23
24 # returns 0: if SDC_LOCAL_IMAGES is set to true value
25 # returns 1: otherwise
26 function using_local_images {
27     is_true SDC_LOCAL_IMAGES
28 }
29
30 # returns 0: if SDC_TEST_HTTPS is set to true value
31 # returns 1: otherwise
32 function using_https {
33     is_true SDC_TEST_HTTPS
34 }
35
36 # fail quick if error
37 set -exo pipefail
38
39 echo "This is ${WORKSPACE}/scripts/sdc/setup_sdc_for_sanity.sh"
40
41
42 if [ "$1" != "tad" ] && [ "$1" != "tud" ]; then
43     usage
44     exit 1
45 fi
46
47 # Clone sdc enviroment template
48 mkdir -p "${WORKSPACE}/data/environments/"
49 mkdir -p "${WORKSPACE}/data/clone/"
50
51 cd "${WORKSPACE}/data/clone"
52 if using_local_images && [ -n "$SDC_LOCAL_GITREPO" ] ; then
53     if [ -d "$SDC_LOCAL_GITREPO" ] ; then
54         rm -rf ./sdc
55         cp -a "$SDC_LOCAL_GITREPO" ./sdc
56     else
57         echo "[ERROR]: Local git repo for sdc does not exist: ${SDC_LOCAL_GITREPO}"
58         exit 1
59     fi
60 else
61     git clone --depth 1 http://gerrit.onap.org/r/sdc -b ${GERRIT_BRANCH}
62 fi
63
64 # TODO: why?
65 chmod -R 777 "${WORKSPACE}/data/clone"
66
67 # set enviroment variables
68
69 export ENV_NAME='CSIT'
70 export MR_IP_ADDR='10.0.0.1'
71 export TEST_SUITE="$1"
72
73 ifconfig
74 IP_ADDRESS=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
75 export HOST_IP="$IP_ADDRESS"
76
77 # setup enviroment json
78 # TODO: use jq or find a better way altogether...
79 cp "${WORKSPACE}/data/clone/sdc/sdc-os-chef/environments/Template.json" \
80     "${WORKSPACE}/data/environments/$ENV_NAME.json"
81 sed -i \
82     -e "s/xxx/${ENV_NAME}/g" \
83     -e "s/yyy/${IP_ADDRESS}/g" \
84     -e "s/\"ueb_url_list\":.*/\"ueb_url_list\": \"${MR_IP_ADDR},${MR_IP_ADDR}\",/g" \
85     -e "s/\"fqdn\":.*/\"fqdn\": [\"${MR_IP_ADDR}\", \"${MR_IP_ADDR}\"]/g" \
86     "${WORKSPACE}/data/environments/$ENV_NAME.json"
87 if using_https ; then
88     # this is very fragile (as all above) and relies on the current state of Template.json in another project...
89     # using jq filters would be much better approach and no need for some "yyy"...
90     sed -i \
91         -e 's/"disableHttp":[[:space:]]*"\?[[:alnum:]]*"\?/"disableHttp": true/' \
92         "${WORKSPACE}/data/environments/$ENV_NAME.json"
93 fi
94
95 cp "${WORKSPACE}/data/clone/sdc/sdc-os-chef/scripts/docker_run.sh" "${WORKSPACE}/scripts/sdc/"
96
97 source "${WORKSPACE}/data/clone/sdc/version.properties"
98 export RELEASE="${major}.${minor}-STAGING-latest"
99
100 if using_local_images ; then
101     if [ -n "$SDC_LOCAL_TAG" ] ; then
102         RELEASE="$SDC_LOCAL_TAG"
103     elif [ -z "$SDC_LOCAL_GITREPO" ] ; then
104         echo "[WARNING]: Local images used but no tag and no source (git repo) provided for them - we will use tag 'latest'"
105         RELEASE=latest
106     fi
107
108     echo "[INFO]: We will use the locally built images (tag: ${RELEASE})"
109     "${WORKSPACE}/scripts/sdc/docker_run.sh" \
110         --local \
111         -r "${RELEASE}" \
112         -e "${ENV_NAME}" \
113         -p 10001 "-${TEST_SUITE}"
114 else
115     echo "[INFO]: We will download images from the default registry (tag: ${RELEASE})"
116     ${WORKSPACE}/scripts/sdc/docker_run.sh \
117         -r "${RELEASE}" \
118         -e "${ENV_NAME}" \
119         -p 10001 "-${TEST_SUITE}"
120 fi
121
122 # final step if the robot test needs to be adjusted
123 # TODO: again grab the values from Template directly with jq
124 # jq should be mandatory installed package (is it?)
125 if using_https ; then
126     ROBOT_VARIABLES="${ROBOT_VARIABLES} \
127         -v SDC_FE_PROTOCOL:https \
128         -v SDC_FE_PORT:9443 \
129         -v SDC_BE_PROTOCOL:https \
130         -v SDC_BE_PORT:8443 \
131         -v SDC_ONBOARDING_BE_PROTOCOL:https \
132         -v SDC_ONBOARDING_BE_PORT:8443 \
133         "
134 else
135     ROBOT_VARIABLES="${ROBOT_VARIABLES} \
136         -v SDC_FE_PROTOCOL:http \
137         -v SDC_FE_PORT:8181 \
138         -v SDC_BE_PROTOCOL:http \
139         -v SDC_BE_PORT:8080 \
140         -v SDC_ONBOARDING_BE_PROTOCOL:http \
141         -v SDC_ONBOARDING_BE_PORT:8081 \
142         "
143 fi
144
145 # This file is sourced in another script which is out of our control...
146 set +e
147 set +o pipefail
148