blob: b7528873b591f3c0f0db780b4532ca76b2df1385 [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} && \
32 git checkout ${PACKAGES})
33}
34
beierlm3f0e8842020-06-26 14:57:09 -040035create_vim(){
beierlm71b8bea2020-07-13 14:25:56 -040036
37 attempts=3
38 while [ $attempts -ge 0 ] ; do
39 echo -e "\n$( date '+%F_%H:%M:%S' ) Creating VIM ${VIM_TARGET}"
40 osm vim-create --name ${VIM_TARGET} --user ${OS_USERNAME} --password ${OS_PASSWORD} --tenant ${OS_PROJECT_NAME} \
41 --auth_url ${OS_AUTH_URL} --account_type openstack --description vim \
42 --config "{management_network_name: ${VIM_MGMT_NET}, dataplane_physical_net: ${DATAPLANE:-physnet2}}" || true
beierlm4bf47d02021-01-19 14:24:45 -050043 STATUS=""
beierlm71b8bea2020-07-13 14:25:56 -040044 i=0
45 while [[ ${STATUS} != "ENABLED" ]]
46 do
47 ((i++))
48 if [[ $i -eq 5 ]]; then
beierlm4bf47d02021-01-19 14:24:45 -050049 echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}"
fjvicens44d697d2020-08-13 17:23:29 +020050 osm vim-delete --force ${VIM_TARGET}
beierlm71b8bea2020-07-13 14:25:56 -040051 sleep 5
52 break
53 fi
54 sleep 10
beierlm4bf47d02021-01-19 14:24:45 -050055 VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}`
56 echo VIM status: ${VIM_LIST}
57 STATUS=`echo ${VIM_LIST} | grep -io ENABLED`
beierlm71b8bea2020-07-13 14:25:56 -040058 done
Mark Beierl4b545242020-07-15 14:50:22 -040059 if [[ ${STATUS} = "ENABLED" ]] ; then
60 break
61 fi
beierlm71b8bea2020-07-13 14:25:56 -040062 ((attempts--))
garciaale207a7972020-07-02 17:42:00 -040063 done
beierlm71b8bea2020-07-13 14:25:56 -040064 if [ $attempts -lt 0 ] ; then
65 echo "VIM failed to enter ENABLED state"
66 exit 1
67 fi
beierlm3f0e8842020-06-26 14:57:09 -040068}
69
beierlm71b8bea2020-07-13 14:25:56 -040070
Felipe Vicensf96bb452020-06-22 08:12:30 +020071PARAMS=""
72
73while (( "$#" )); do
74 case "$1" in
75 -t|--testingtags)
76 TEST=$2
77 shift 2
78 ;;
79 -p|--packagesbranch)
80 PACKAGES=$2 && download_packages
81 shift 2
82 ;;
83 -o|--osmclientversion)
beierlm3f0e8842020-06-26 14:57:09 -040084 OSMCLIENT=$2 && install_osmclient
Felipe Vicensf96bb452020-06-22 08:12:30 +020085 shift 2
86 ;;
beierlm3f0e8842020-06-26 14:57:09 -040087 -c|--createvim)
88 create_vim
89 shift 1
90 ;;
Felipe Vicensf96bb452020-06-22 08:12:30 +020091 -h|--help)
92 echo "OSM TESTS TOOL
93
94Usage:
95 docker run --rm=true -t osmtests --env-file <env_file> \\
Felipe Vicens5c54d272020-06-23 15:55:08 +020096 -v <path_to_reports>:/reports osmtests \\
97 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
98 -v <path_to_kubeconfig>:/root/.kube/config \\
99 -o <osmclient_version> \\
100 -p <package_branch> \\
101 -t <testing_tags>
beierlm3f0e8842020-06-26 14:57:09 -0400102
Felipe Vicensf96bb452020-06-22 08:12:30 +0200103Options:
104 --env-file: It is the environmental file where is described the OSM target and VIM
105 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
106 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
107 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, regression, particular_test]. Default: sanity
beierlm3f0e8842020-06-26 14:57:09 -0400108 -c To create a VIM for the tests
Felipe Vicensf96bb452020-06-22 08:12:30 +0200109
110Volumes:
111 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
Felipe Vicens5c54d272020-06-23 15:55:08 +0200112 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
113 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
Felipe Vicensf96bb452020-06-22 08:12:30 +0200114
115 exit 0
116 ;;
117 -*|--*=)
118 echo "Error: Unsupported flag $1" >&2
119 exit 1
120 ;;
121 *)
122 PARAMS="$PARAMS $1"
123 shift
124 ;;
125 esac
126done
127
128eval set -- "$PARAMS"
129
beierlm3f0e8842020-06-26 14:57:09 -0400130if [[ -n "$BRANCH_NAME" ]]; then
131 PACKAGES=$BRANCH_NAME && download_packages
132 OSMCLIENT=$BRANCH_NAME && install_osmclient
133fi
134
135if [[ -z "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200136 printf "Test not provided. \nRunning default test: sanity\n"
137 TEST="sanity"
138fi
139
beierlm3f0e8842020-06-26 14:57:09 -0400140if [[ -n "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200141 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
142 exit 0
143else
144 echo "Wrong test provided"
145 exit 1
146fi
147
148exit 1