blob: a279ff04af3f6042a67d8b604deefc4ad13150a6 [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
Felipe Vicens55b61582020-06-24 21:23:44 +020035create_vim(){
beierlm9fc2b842020-06-26 14:57:09 -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
43 STATUS="PROCESSING"
44 i=0
45 while [[ ${STATUS} != "ENABLED" ]]
46 do
47 ((i++))
48 if [[ $i -eq 5 ]]; then
49 echo "VIM stuck in PROCESSING after 50 seconds"
50 osm vim-delete ${VIM_TARGET}
51 sleep 5
52 break
53 fi
54 sleep 10
55 STATUS=`osm vim-list --long | grep ${VIM_TARGET} | awk '{print $9}'`
56 done
57 if [[ ${STATUS} = "ENABLED" ]] ; then
58 break
Felipe Vicens02300c02020-07-02 12:19:28 +020059 fi
beierlm9fc2b842020-06-26 14:57:09 -040060 ((attempts--))
Felipe Vicens02300c02020-07-02 12:19:28 +020061 done
beierlm9fc2b842020-06-26 14:57:09 -040062
63 if [ $attempts -lt 0 ] ; then
64 echo "VIM failed to enter ENABLED state"
65 exit 1
66 fi
Felipe Vicens55b61582020-06-24 21:23:44 +020067}
68
beierlm9fc2b842020-06-26 14:57:09 -040069
Felipe Vicensf96bb452020-06-22 08:12:30 +020070PARAMS=""
71
72while (( "$#" )); do
73 case "$1" in
74 -t|--testingtags)
75 TEST=$2
76 shift 2
77 ;;
78 -p|--packagesbranch)
79 PACKAGES=$2 && download_packages
80 shift 2
81 ;;
82 -o|--osmclientversion)
Felipe Vicens24e3d152020-06-25 21:52:06 +020083 OSMCLIENT=$2 && install_osmclient
Felipe Vicensf96bb452020-06-22 08:12:30 +020084 shift 2
85 ;;
Felipe Vicens55b61582020-06-24 21:23:44 +020086 -c|--createvim)
87 create_vim
88 shift 1
89 ;;
Felipe Vicensf96bb452020-06-22 08:12:30 +020090 -h|--help)
91 echo "OSM TESTS TOOL
92
93Usage:
94 docker run --rm=true -t osmtests --env-file <env_file> \\
Felipe Vicens5c54d272020-06-23 15:55:08 +020095 -v <path_to_reports>:/reports osmtests \\
96 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
97 -v <path_to_kubeconfig>:/root/.kube/config \\
98 -o <osmclient_version> \\
99 -p <package_branch> \\
100 -t <testing_tags>
Felipe Vicens6366c682020-06-25 20:12:16 +0200101
Felipe Vicensf96bb452020-06-22 08:12:30 +0200102Options:
103 --env-file: It is the environmental file where is described the OSM target and VIM
104 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
105 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
106 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, regression, particular_test]. Default: sanity
Felipe Vicens55b61582020-06-24 21:23:44 +0200107 -c To create a VIM for the tests
Felipe Vicensf96bb452020-06-22 08:12:30 +0200108
109Volumes:
110 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
Felipe Vicens5c54d272020-06-23 15:55:08 +0200111 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
112 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
Felipe Vicensf96bb452020-06-22 08:12:30 +0200113
114 exit 0
115 ;;
116 -*|--*=)
117 echo "Error: Unsupported flag $1" >&2
118 exit 1
119 ;;
120 *)
121 PARAMS="$PARAMS $1"
122 shift
123 ;;
124 esac
125done
126
127eval set -- "$PARAMS"
128
Felipe Vicens24e3d152020-06-25 21:52:06 +0200129if [[ -n "$BRANCH_NAME" ]]; then
130 PACKAGES=$BRANCH_NAME && download_packages
131 OSMCLIENT=$BRANCH_NAME && install_osmclient
Felipe Vicens6366c682020-06-25 20:12:16 +0200132fi
133
134if [[ -z "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200135 printf "Test not provided. \nRunning default test: sanity\n"
136 TEST="sanity"
137fi
138
Felipe Vicens6366c682020-06-25 20:12:16 +0200139if [[ -n "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200140 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
141 exit 0
142else
143 echo "Wrong test provided"
144 exit 1
145fi
146
147exit 1