blob: 22803e4077ccde5f4d5cc8e5bfae715267a2d455 [file] [log] [blame]
Felipe Vicensf96bb452020-06-22 08:12:30 +02001#!/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
21cat /dev/zero | ssh-keygen -q -N "" > /dev/null
22
23install_osmclient(){
24 echo -e "\nInstalling osmclient ${OSMCLIENT}"
25 python3 -m pip install git+https://osm.etsi.org/gerrit/osm/osmclient@${OSMCLIENT}
26}
27
28download_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} && \
garciaale82f05de2020-12-01 12:29:31 -030032 git checkout sol006)
Felipe Vicensf96bb452020-06-22 08:12:30 +020033}
34
Frank Brydene570b102020-09-07 08:45:54 +000035download_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
Felipe Vicens55b61582020-06-24 21:23:44 +020041create_vim(){
beierlm9fc2b842020-06-26 14:57:09 -040042
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
beierlm6cc2bd12020-12-03 11:44:47 -050049 STATUS=""
beierlm9fc2b842020-06-26 14:57:09 -040050 i=0
51 while [[ ${STATUS} != "ENABLED" ]]
52 do
53 ((i++))
54 if [[ $i -eq 5 ]]; then
beierlm6cc2bd12020-12-03 11:44:47 -050055 echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}"
Frank Brydene570b102020-09-07 08:45:54 +000056 osm vim-delete --force ${VIM_TARGET}
beierlm9fc2b842020-06-26 14:57:09 -040057 sleep 5
58 break
59 fi
60 sleep 10
beierlm1d535af2020-12-03 09:28:28 -050061 VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}`
62 echo VIM status: ${VIM_LIST}
beierlm6cc2bd12020-12-03 11:44:47 -050063 STATUS=`echo ${VIM_LIST} | grep -io ENABLED`
beierlm9fc2b842020-06-26 14:57:09 -040064 done
65 if [[ ${STATUS} = "ENABLED" ]] ; then
66 break
Felipe Vicens02300c02020-07-02 12:19:28 +020067 fi
beierlm9fc2b842020-06-26 14:57:09 -040068 ((attempts--))
Felipe Vicens02300c02020-07-02 12:19:28 +020069 done
beierlm9fc2b842020-06-26 14:57:09 -040070 if [ $attempts -lt 0 ] ; then
71 echo "VIM failed to enter ENABLED state"
72 exit 1
73 fi
Felipe Vicens55b61582020-06-24 21:23:44 +020074}
75
beierlm9fc2b842020-06-26 14:57:09 -040076
Felipe Vicensf96bb452020-06-22 08:12:30 +020077PARAMS=""
Frank Brydene570b102020-09-07 08:45:54 +000078RUN_CONFORMANCE_TESTS=false
Felipe Vicensf96bb452020-06-22 08:12:30 +020079
80while (( "$#" )); do
81 case "$1" in
82 -t|--testingtags)
83 TEST=$2
84 shift 2
85 ;;
86 -p|--packagesbranch)
87 PACKAGES=$2 && download_packages
88 shift 2
89 ;;
90 -o|--osmclientversion)
Felipe Vicens24e3d152020-06-25 21:52:06 +020091 OSMCLIENT=$2 && install_osmclient
Felipe Vicensf96bb452020-06-22 08:12:30 +020092 shift 2
93 ;;
Felipe Vicens55b61582020-06-24 21:23:44 +020094 -c|--createvim)
95 create_vim
96 shift 1
97 ;;
Frank Brydene570b102020-09-07 08:45:54 +000098 -T)
99 NFV_TESTS_BRANCH=$2 && download_tst010
100 RUN_CONFORMANCE_TESTS=true
101 shift 1
102 ;;
Felipe Vicensf96bb452020-06-22 08:12:30 +0200103 -h|--help)
104 echo "OSM TESTS TOOL
105
106Usage:
107 docker run --rm=true -t osmtests --env-file <env_file> \\
Felipe Vicens5c54d272020-06-23 15:55:08 +0200108 -v <path_to_reports>:/reports osmtests \\
109 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
110 -v <path_to_kubeconfig>:/root/.kube/config \\
111 -o <osmclient_version> \\
112 -p <package_branch> \\
113 -t <testing_tags>
Felipe Vicens6366c682020-06-25 20:12:16 +0200114
Felipe Vicensf96bb452020-06-22 08:12:30 +0200115Options:
116 --env-file: It is the environmental file where is described the OSM target and VIM
117 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
118 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
119 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, regression, particular_test]. Default: sanity
Frank Brydene570b102020-09-07 08:45:54 +0000120 -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests
Felipe Vicens55b61582020-06-24 21:23:44 +0200121 -c To create a VIM for the tests
Felipe Vicensf96bb452020-06-22 08:12:30 +0200122
123Volumes:
124 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
Felipe Vicens5c54d272020-06-23 15:55:08 +0200125 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
126 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
Felipe Vicensf96bb452020-06-22 08:12:30 +0200127
128 exit 0
129 ;;
130 -*|--*=)
131 echo "Error: Unsupported flag $1" >&2
132 exit 1
133 ;;
134 *)
135 PARAMS="$PARAMS $1"
136 shift
137 ;;
138 esac
139done
140
141eval set -- "$PARAMS"
142
Felipe Vicens24e3d152020-06-25 21:52:06 +0200143if [[ -n "$BRANCH_NAME" ]]; then
144 PACKAGES=$BRANCH_NAME && download_packages
145 OSMCLIENT=$BRANCH_NAME && install_osmclient
Felipe Vicens6366c682020-06-25 20:12:16 +0200146fi
147
Frank Brydene570b102020-09-07 08:45:54 +0000148
149if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then
150 python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py
151fi
152
Felipe Vicens6366c682020-06-25 20:12:16 +0200153if [[ -z "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200154 printf "Test not provided. \nRunning default test: sanity\n"
155 TEST="sanity"
156fi
157
Felipe Vicens6366c682020-06-25 20:12:16 +0200158if [[ -n "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200159 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
160 exit 0
161else
162 echo "Wrong test provided"
163 exit 1
164fi
165
166exit 1