Adding basic E2E test for workflow designer
[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 echo "lets check what is ${1} ${2}"
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         ENABLE_SIMULATOR="--simulator"
62         # this is mandatory
63         ;;
64     *)
65         export TEST_SUITE=""
66         ENABLE_SIMULATOR="--simulator"
67     #     # usage
68     #     exit 1
69         ;;
70 esac
71 echo "Lets check is simulator is enabled or not ${ENABLE_SIMULATOR}"
72 # Clone sdc enviroment template
73 mkdir -p "${WORKSPACE}/data/environments/"
74 mkdir -p "${WORKSPACE}/data/clone/"
75
76 cd "${WORKSPACE}/data/clone"
77 if using_local_images && [ -n "$SDC_LOCAL_GITREPO" ] ; then
78     SDC_LOCAL_GITREPO=$(realpath "$SDC_LOCAL_GITREPO")
79     if [ -d "$SDC_LOCAL_GITREPO" ] ; then
80         rm -rf ./sdc
81         cp -a "$SDC_LOCAL_GITREPO" ./sdc
82         # echo "[skipping copying git repo of sdc]"
83     else
84         echo "[ERROR]: Local git repo for sdc does not exist: ${SDC_LOCAL_GITREPO}"
85         exit 1
86     fi
87 else
88     git clone --depth 1 "https://gerrit.onap.org/r/sdc" -b ${GERRIT_BRANCH}
89 fi
90
91 # TODO: why?
92 chmod -R 777 "${WORKSPACE}/data/clone"
93
94 # set enviroment variables
95
96 export ENV_NAME='CSIT'
97 export MR_IP_ADDR='10.0.0.1'
98
99 ip a
100 IP_ADDRESS=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
101 export HOST_IP="$IP_ADDRESS"
102
103 # setup enviroment json
104 # TODO: use jq or find a better way altogether...
105 cp "${WORKSPACE}/data/clone/sdc/sdc-os-chef/environments/Template.json" \
106     "${WORKSPACE}/data/environments/$ENV_NAME.json"
107 sed -i \
108     -e "s/xxx/${ENV_NAME}/g" \
109     -e "s/yyy/${IP_ADDRESS}/g" \
110     -e "s/\"ueb_url_list\":.*/\"ueb_url_list\": \"${MR_IP_ADDR},${MR_IP_ADDR}\",/g" \
111     -e "s/\"fqdn\":.*/\"fqdn\": [\"${MR_IP_ADDR}\", \"${MR_IP_ADDR}\"]/g" \
112     "${WORKSPACE}/data/environments/$ENV_NAME.json"
113 if using_https ; then
114     # this is very fragile (as all above) and relies on the current state of Template.json in another project...
115     # using jq filters would be much better approach and no need for some "yyy"...
116     sed -i \
117         -e 's/"disableHttp":[[:space:]]*"\?[[:alnum:]]*"\?/"disableHttp": true/' \
118         "${WORKSPACE}/data/environments/$ENV_NAME.json"
119 fi
120
121 cp "${WORKSPACE}/data/clone/sdc/sdc-os-chef/scripts/docker_run.sh" "${WORKSPACE}/scripts/sdc/"
122
123 source "${WORKSPACE}/data/clone/sdc/version.properties"
124 export RELEASE="${major}.${minor}-STAGING-latest"
125
126 if using_local_images ; then
127     if [ -n "$SDC_LOCAL_TAG" ] ; then
128         RELEASE="$SDC_LOCAL_TAG"
129     elif [ -z "$SDC_LOCAL_GITREPO" ] ; then
130         echo "[WARNING]: Local images used but no tag and no source (git repo) provided for them - we will use tag 'latest'"
131         RELEASE=latest
132     fi
133
134     echo "[INFO]: We will use the locally built images (tag: ${RELEASE})"
135     "${WORKSPACE}/scripts/sdc/docker_run.sh" \
136         --local \
137         -r "${RELEASE}" \
138         -e "${ENV_NAME}" \
139         -p 10001 ${TEST_SUITE} ${ENABLE_SIMULATOR}
140 else
141     echo "[INFO]: We will download images from the default registry (tag: ${RELEASE})"
142     ${WORKSPACE}/scripts/sdc/docker_run.sh \
143         -r "${RELEASE}" \
144         -e "${ENV_NAME}" \
145         -p 10001 ${TEST_SUITE} ${ENABLE_SIMULATOR}
146 fi
147
148 # final step if the robot test needs to be adjusted
149 # TODO: again grab the values from Template directly with jq
150 # jq should be mandatory installed package (is it?)
151 if using_https ; then
152     ROBOT_VARIABLES="${ROBOT_VARIABLES} \
153         -v SDC_FE_PROTOCOL:https \
154         -v SDC_FE_PORT:9443 \
155         -v SDC_BE_PROTOCOL:https \
156         -v SDC_BE_PORT:8443 \
157         -v SDC_ONBOARDING_BE_PROTOCOL:https \
158         -v SDC_ONBOARDING_BE_PORT:8443 \
159         "
160 else
161     ROBOT_VARIABLES="${ROBOT_VARIABLES} \
162         -v SDC_FE_PROTOCOL:http \
163         -v SDC_FE_PORT:8181 \
164         -v SDC_BE_PROTOCOL:http \
165         -v SDC_BE_PORT:8080 \
166         -v SDC_ONBOARDING_BE_PROTOCOL:http \
167         -v SDC_ONBOARDING_BE_PORT:8081 \
168         "
169 fi
170
171 # This file is sourced in another script which is out of our control...
172 set +e
173 set +o pipefail
174