190889c23b25f71ac93453d115911092eaede5ac
[osm/tests.git] / robot-systest / run_test.sh
1 #!/usr/bin/env bash
2
3 ##
4 # Copyright 2020 ATOS
5 #
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 ##
20
21 cat /dev/zero | ssh-keygen -q -N "" > /dev/null
22
23 install_osmclient(){
24 echo -e "\nInstalling osmclient ${OSMCLIENT}"
25 python3 -m pip install git+https://osm.etsi.org/gerrit/osm/osmclient@${OSMCLIENT}
26 }
27
28 download_packages(){
29 echo -e "\nDownloading packages ${PACKAGES}"
30 rm -rf ${PACKAGES_FOLDER}
31 git clone https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages.git ${PACKAGES_FOLDER}
32 }
33
34 download_tst010(){
35 # Fetch conformance tests
36 git clone --single-branch --branch ${NFV_TESTS_BRANCH} https://forge.etsi.org/rep/nfv/api-tests.git /robot-systest/conformance-tests/repo
37 #python3 -m pip install -r /robot-systest/conformance-tests/repo/requirements.txt
38 python3 -m pip install -r /robot-systest/conformance-tests/requirements.txt
39 }
40
41
42 create_k8scluster(){
43 attempts=3
44 while [ $attempts -ge 0 ] ; do
45 echo -e "\n$( date '+%F_%H:%M:%S' ) Creating K8s Cluster"
46
47 osm k8scluster-add --creds ${K8S_CREDENTIALS} --version "v1" --vim ${VIM_TARGET} --k8s-nets "{\"net1\": \"%{VIM_MGMT_NET}\"}" ${VIM_TARGET} --description "Robot cluster"
48
49 STATUS=""
50 i=0
51 while [[ ${STATUS} != "ENABLED" ]]
52 do
53 ((i++))
54 if [[ $i -eq 5 ]]; then
55 echo "K8s cluster stuck for more than 50 seconds:"
56 osm k8scluster-show ${VIM_TARGET}
57 osm k8scluster-delete ${VIM_TARGET}
58 sleep 5
59 break
60 fi
61 sleep 10
62 STATUS=`osm k8scluster-list | grep ${VIM_TARGET} | awk '{print $8}'`
63 done
64 if [[ ${STATUS} = "ENABLED" ]] ; then
65 break
66 fi
67 ((attempts--))
68 done
69 if [ $attempts -lt 0 ] ; then
70 echo "VIM failed to enter ENABLED state"
71 exit 1
72 fi
73 }
74
75 create_vim(){
76 attempts=3
77 while [ $attempts -ge 0 ] ; do
78 echo -e "\n$( date '+%F_%H:%M:%S' ) Creating VIM ${VIM_TARGET}"
79 osm vim-create --name ${VIM_TARGET} --user ${OS_USERNAME} --password ${OS_PASSWORD} --tenant ${OS_PROJECT_NAME} \
80 --auth_url ${OS_AUTH_URL} --account_type openstack --description vim \
81 --config "{management_network_name: ${VIM_MGMT_NET}, dataplane_physical_net: ${DATAPLANE:-physnet2}}" || true
82 STATUS=""
83 i=0
84 while [[ ${STATUS} != "ENABLED" ]]
85 do
86 ((i++))
87 if [[ $i -eq 5 ]]; then
88 echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}"
89 osm vim-delete --force ${VIM_TARGET}
90 sleep 5
91 break
92 fi
93 sleep 10
94 VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}`
95 echo VIM status: ${VIM_LIST}
96 STATUS=`echo ${VIM_LIST} | grep -io ENABLED`
97 done
98 if [[ ${STATUS} = "ENABLED" ]] ; then
99 break
100 fi
101 ((attempts--))
102 done
103 if [ $attempts -lt 0 ] ; then
104 echo "VIM failed to enter ENABLED state"
105 exit 1
106 fi
107 if [ -n "${SDNC_URL}" ]; then
108 osm sdnc-create --name sdnc-osm --type ${SDNC_TYPE} --user ${SDNC_USER} --password ${SDNC_PASSWORD} --url ${SDNC_URL}
109 COUNTER=0
110 STATUS=""
111 while [ ${COUNTER} -lt 5 ] ; do
112 echo "Checking status of SDNC sdnc-osm to see if it is enabled"
113 STATUS=$(osm sdnc-show sdnc-osm |grep -io ENABLED)
114 if [ "${STATUS}" == "ENABLED" ]; then
115 break
116 fi
117 ((COUNTER++))
118 sleep 10
119 done
120 if [ "${STATUS}" == "ENABLED" ]; then
121 echo "SDNC enabled"
122 else
123 echo "SDNC failed to enter ENABLED state"
124 osm sdnc-show sdnc-osm
125 exit 1
126 fi
127 if [ -f /root/port-mapping.yaml ]; then
128 osm vim-update ${VIM_TARGET} --sdn_controller sdnc-osm --sdn_port_mapping /root/port-mapping.yaml
129 COUNTER2=0
130 RESULT=""
131 while [ ${COUNTER2} -lt 5 ] ; do
132 echo "Checking status of VIM $VIM_TARGET to see if there is port-mapping"
133 osm vim-show $VIM_TARGET |grep sdn-port-mapping
134 if [ $? -eq 0 ]; then
135 RESULT="OK"
136 break
137 fi
138 ((COUNTER2++))
139 sleep 10
140 done
141 if [ "${RESULT}" == "OK" ]; then
142 echo "Port-mapping correctly added"
143 else
144 echo "Port-mapping failed to be added"
145 osm vim-show ${VIM_TARGET}
146 exit 1
147 fi
148 fi
149 fi
150 }
151
152
153 PARAMS=""
154 RUN_CONFORMANCE_TESTS=false
155
156 while (( "$#" )); do
157 case "$1" in
158 -t|--testingtags)
159 TEST=$2
160 shift 2
161 ;;
162 -p|--packagesbranch)
163 PACKAGES=$2 && download_packages
164 shift 2
165 ;;
166 -o|--osmclientversion)
167 OSMCLIENT=$2 && install_osmclient
168 shift 2
169 ;;
170 -c|--createvim)
171 create_vim
172 create_k8scluster
173 shift 1
174 ;;
175 -T)
176 NFV_TESTS_BRANCH=$2 && download_tst010
177 RUN_CONFORMANCE_TESTS=true
178 shift 1
179 ;;
180 -h|--help)
181 echo "OSM TESTS TOOL
182
183 Usage:
184 docker run --rm=true -t osmtests --env-file <env_file> \\
185 -v <path_to_reports>:/reports osmtests \\
186 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
187 -v <path_to_kubeconfig>:/root/.kube/config \\
188 -o <osmclient_version> \\
189 -p <package_branch> \\
190 -t <testing_tags>
191
192 Options:
193 --env-file: It is the environmental file where is described the OSM target and VIM
194 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
195 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
196 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, daily, regression, particular_test]. Default: sanity
197 -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests
198 -c To create a VIM and K8s cluster for the tests
199
200 Volumes:
201 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
202 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
203 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
204
205 exit 0
206 ;;
207 -*|--*=)
208 echo "Error: Unsupported flag $1" >&2
209 exit 1
210 ;;
211 *)
212 PARAMS="$PARAMS $1"
213 shift
214 ;;
215 esac
216 done
217
218 eval set -- "$PARAMS"
219
220 if [[ -n "$BRANCH_NAME" ]]; then
221 PACKAGES=$BRANCH_NAME && download_packages
222 OSMCLIENT=$BRANCH_NAME && install_osmclient
223 fi
224
225
226 if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then
227 python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py
228 fi
229
230 if [[ -z "${TEST}" ]]; then
231 printf "Test not provided. \nRunning default test: sanity\n"
232 TEST="sanity"
233 fi
234
235 if [[ -n "${TEST}" ]]; then
236 pabot --processes 2 -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
237 exit 0
238 else
239 echo "Wrong test provided"
240 exit 1
241 fi
242
243 exit 1