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