Removed unused 'privatekey' variable in EPA04 and EPA05 tests
[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 }
39
40 create_vim(){
41
42 attempts=3
43 while [ $attempts -ge 0 ] ; do
44 echo -e "\n$( date '+%F_%H:%M:%S' ) Creating VIM ${VIM_TARGET}"
45 osm vim-create --name ${VIM_TARGET} --user ${OS_USERNAME} --password ${OS_PASSWORD} --tenant ${OS_PROJECT_NAME} \
46 --auth_url ${OS_AUTH_URL} --account_type openstack --description vim \
47 --config "{management_network_name: ${VIM_MGMT_NET}, dataplane_physical_net: ${DATAPLANE:-physnet2}}" || true
48 STATUS=""
49 i=0
50 while [[ ${STATUS} != "ENABLED" ]]
51 do
52 ((i++))
53 if [[ $i -eq 5 ]]; then
54 echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}"
55 osm vim-delete --force ${VIM_TARGET}
56 sleep 5
57 break
58 fi
59 sleep 10
60 VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}`
61 echo VIM status: ${VIM_LIST}
62 STATUS=`echo ${VIM_LIST} | grep -io ENABLED`
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 if [ -n "${SDNC_URL}" ]; then
74 osm sdnc-create --name sdnc-osm --type ${SDNC_TYPE} --user ${SDNC_USER} --password ${SDNC_PASSWORD} --url ${SDNC_URL}
75 COUNTER=0
76 STATUS=""
77 while [ ${COUNTER} -lt 5 ] ; do
78 echo "Checking status of SDNC sdnc-osm to see if it is enabled"
79 STATUS=$(osm sdnc-show sdnc-osm |grep -io ENABLED)
80 if [ "${STATUS}" == "ENABLED" ]; then
81 break
82 fi
83 ((COUNTER++))
84 sleep 10
85 done
86 if [ "${STATUS}" == "ENABLED" ]; then
87 echo "SDNC enabled"
88 else
89 echo "SDNC failed to enter ENABLED state"
90 osm sdnc-show sdnc-osm
91 exit 1
92 fi
93 if [ -f /root/port-mapping.yaml ]; then
94 osm vim-update ${VIM_TARGET} --sdn_controller sdnc-osm --sdn_port_mapping /root/port-mapping.yaml
95 COUNTER2=0
96 RESULT=""
97 while [ ${COUNTER2} -lt 5 ] ; do
98 echo "Checking status of VIM $VIM_TARGET to see if there is port-mapping"
99 osm vim-show $VIM_TARGET |grep sdn-port-mapping
100 if [ $? -eq 0 ]; then
101 RESULT="OK"
102 break
103 fi
104 ((COUNTER2++))
105 sleep 10
106 done
107 if [ "${RESULT}" == "OK" ]; then
108 echo "Port-mapping correctly added"
109 else
110 echo "Port-mapping failed to be added"
111 osm vim-show ${VIM_TARGET}
112 exit 1
113 fi
114 fi
115 fi
116 }
117
118
119 PARAMS=""
120 RUN_CONFORMANCE_TESTS=false
121
122 while (( "$#" )); do
123 case "$1" in
124 -t|--testingtags)
125 TEST=$2
126 shift 2
127 ;;
128 -p|--packagesbranch)
129 PACKAGES=$2 && download_packages
130 shift 2
131 ;;
132 -o|--osmclientversion)
133 OSMCLIENT=$2 && install_osmclient
134 shift 2
135 ;;
136 -c|--createvim)
137 create_vim
138 shift 1
139 ;;
140 -T)
141 NFV_TESTS_BRANCH=$2 && download_tst010
142 RUN_CONFORMANCE_TESTS=true
143 shift 1
144 ;;
145 -h|--help)
146 echo "OSM TESTS TOOL
147
148 Usage:
149 docker run --rm=true -t osmtests --env-file <env_file> \\
150 -v <path_to_reports>:/reports osmtests \\
151 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
152 -v <path_to_kubeconfig>:/root/.kube/config \\
153 -o <osmclient_version> \\
154 -p <package_branch> \\
155 -t <testing_tags>
156
157 Options:
158 --env-file: It is the environmental file where is described the OSM target and VIM
159 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
160 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
161 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, daily, regression, particular_test]. Default: sanity
162 -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests
163 -c To create a VIM for the tests
164
165 Volumes:
166 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
167 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
168 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
169
170 exit 0
171 ;;
172 -*|--*=)
173 echo "Error: Unsupported flag $1" >&2
174 exit 1
175 ;;
176 *)
177 PARAMS="$PARAMS $1"
178 shift
179 ;;
180 esac
181 done
182
183 eval set -- "$PARAMS"
184
185 if [[ -n "$BRANCH_NAME" ]]; then
186 PACKAGES=$BRANCH_NAME && download_packages
187 OSMCLIENT=$BRANCH_NAME && install_osmclient
188 fi
189
190
191 if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then
192 python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py
193 fi
194
195 if [[ -z "${TEST}" ]]; then
196 printf "Test not provided. \nRunning default test: sanity\n"
197 TEST="sanity"
198 fi
199
200 if [[ -n "${TEST}" ]]; then
201 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
202 exit 0
203 else
204 echo "Wrong test provided"
205 exit 1
206 fi
207
208 exit 1