Additional logging
[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} && (cd ${PACKAGES_FOLDER} && \
32 git checkout sol006)
33 }
34
35 download_tst010(){
36 # Fetch conformance tests
37 git clone --single-branch --branch ${NFV_TESTS_BRANCH} https://forge.etsi.org/rep/nfv/api-tests.git /robot-systest/conformance-tests/repo
38 python3 -m pip install -r /robot-systest/conformance-tests/repo/requirements.txt
39 }
40
41 create_vim(){
42
43 attempts=3
44 while [ $attempts -ge 0 ] ; do
45 echo -e "\n$( date '+%F_%H:%M:%S' ) Creating VIM ${VIM_TARGET}"
46 osm vim-create --name ${VIM_TARGET} --user ${OS_USERNAME} --password ${OS_PASSWORD} --tenant ${OS_PROJECT_NAME} \
47 --auth_url ${OS_AUTH_URL} --account_type openstack --description vim \
48 --config "{management_network_name: ${VIM_MGMT_NET}, dataplane_physical_net: ${DATAPLANE:-physnet2}}" || true
49 STATUS="PROCESSING"
50 i=0
51 while [[ ${STATUS} != "ENABLED" ]]
52 do
53 ((i++))
54 if [[ $i -eq 5 ]]; then
55 echo "VIM stuck in ${STATUS} after 50 seconds"
56 osm vim-delete --force ${VIM_TARGET}
57 sleep 5
58 break
59 fi
60 sleep 10
61 VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}`
62 echo VIM status: ${VIM_LIST}
63 STATUS=`echo ${VIM_LIST} | awk '{print $9}'`
64 done
65 if [[ ${STATUS} = "ENABLED" ]] ; then
66 break
67 fi
68 ((attempts--))
69 done
70
71 if [ $attempts -lt 0 ] ; then
72 echo "VIM failed to enter ENABLED state"
73 exit 1
74 fi
75 }
76
77
78 PARAMS=""
79 RUN_CONFORMANCE_TESTS=false
80
81 while (( "$#" )); do
82 case "$1" in
83 -t|--testingtags)
84 TEST=$2
85 shift 2
86 ;;
87 -p|--packagesbranch)
88 PACKAGES=$2 && download_packages
89 shift 2
90 ;;
91 -o|--osmclientversion)
92 OSMCLIENT=$2 && install_osmclient
93 shift 2
94 ;;
95 -c|--createvim)
96 create_vim
97 shift 1
98 ;;
99 -T)
100 NFV_TESTS_BRANCH=$2 && download_tst010
101 RUN_CONFORMANCE_TESTS=true
102 shift 1
103 ;;
104 -h|--help)
105 echo "OSM TESTS TOOL
106
107 Usage:
108 docker run --rm=true -t osmtests --env-file <env_file> \\
109 -v <path_to_reports>:/reports osmtests \\
110 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
111 -v <path_to_kubeconfig>:/root/.kube/config \\
112 -o <osmclient_version> \\
113 -p <package_branch> \\
114 -t <testing_tags>
115
116 Options:
117 --env-file: It is the environmental file where is described the OSM target and VIM
118 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
119 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
120 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, regression, particular_test]. Default: sanity
121 -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests
122 -c To create a VIM for the tests
123
124 Volumes:
125 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
126 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
127 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
128
129 exit 0
130 ;;
131 -*|--*=)
132 echo "Error: Unsupported flag $1" >&2
133 exit 1
134 ;;
135 *)
136 PARAMS="$PARAMS $1"
137 shift
138 ;;
139 esac
140 done
141
142 eval set -- "$PARAMS"
143
144 if [[ -n "$BRANCH_NAME" ]]; then
145 PACKAGES=$BRANCH_NAME && download_packages
146 OSMCLIENT=$BRANCH_NAME && install_osmclient
147 fi
148
149
150 if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then
151 python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py
152 fi
153
154 if [[ -z "${TEST}" ]]; then
155 printf "Test not provided. \nRunning default test: sanity\n"
156 TEST="sanity"
157 fi
158
159 if [[ -n "${TEST}" ]]; then
160 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
161 exit 0
162 else
163 echo "Wrong test provided"
164 exit 1
165 fi
166
167 exit 1