ns_lib: update scaling timeout with the env modifier OSM_VIM_MULTIPLIER_TIMEOUT
[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 }
74
75
76 PARAMS=""
77 RUN_CONFORMANCE_TESTS=false
78
79 while (( "$#" )); do
80 case "$1" in
81 -t|--testingtags)
82 TEST=$2
83 shift 2
84 ;;
85 -p|--packagesbranch)
86 PACKAGES=$2 && download_packages
87 shift 2
88 ;;
89 -o|--osmclientversion)
90 OSMCLIENT=$2 && install_osmclient
91 shift 2
92 ;;
93 -c|--createvim)
94 create_vim
95 shift 1
96 ;;
97 -T)
98 NFV_TESTS_BRANCH=$2 && download_tst010
99 RUN_CONFORMANCE_TESTS=true
100 shift 1
101 ;;
102 -h|--help)
103 echo "OSM TESTS TOOL
104
105 Usage:
106 docker run --rm=true -t osmtests --env-file <env_file> \\
107 -v <path_to_reports>:/reports osmtests \\
108 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
109 -v <path_to_kubeconfig>:/root/.kube/config \\
110 -o <osmclient_version> \\
111 -p <package_branch> \\
112 -t <testing_tags>
113
114 Options:
115 --env-file: It is the environmental file where is described the OSM target and VIM
116 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
117 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
118 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, daily, regression, particular_test]. Default: sanity
119 -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests
120 -c To create a VIM for the tests
121
122 Volumes:
123 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
124 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
125 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
126
127 exit 0
128 ;;
129 -*|--*=)
130 echo "Error: Unsupported flag $1" >&2
131 exit 1
132 ;;
133 *)
134 PARAMS="$PARAMS $1"
135 shift
136 ;;
137 esac
138 done
139
140 eval set -- "$PARAMS"
141
142 if [[ -n "$BRANCH_NAME" ]]; then
143 PACKAGES=$BRANCH_NAME && download_packages
144 OSMCLIENT=$BRANCH_NAME && install_osmclient
145 fi
146
147
148 if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then
149 python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py
150 fi
151
152 if [[ -z "${TEST}" ]]; then
153 printf "Test not provided. \nRunning default test: sanity\n"
154 TEST="sanity"
155 fi
156
157 if [[ -n "${TEST}" ]]; then
158 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
159 exit 0
160 else
161 echo "Wrong test provided"
162 exit 1
163 fi
164
165 exit 1