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