blob: dd77f8e4962d7696224015242ef292377477251c [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}
garciadeblas28ce11e2021-03-02 16:15:17 +000031 git clone https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages.git ${PACKAGES_FOLDER}
Felipe Vicensf96bb452020-06-22 08:12:30 +020032}
33
Frank Brydene570b102020-09-07 08:45:54 +000034download_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
Felipe Vicens55b61582020-06-24 21:23:44 +020040create_vim(){
beierlm9fc2b842020-06-26 14:57:09 -040041
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
beierlm6cc2bd12020-12-03 11:44:47 -050048 STATUS=""
beierlm9fc2b842020-06-26 14:57:09 -040049 i=0
50 while [[ ${STATUS} != "ENABLED" ]]
51 do
52 ((i++))
53 if [[ $i -eq 5 ]]; then
beierlm6cc2bd12020-12-03 11:44:47 -050054 echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}"
Frank Brydene570b102020-09-07 08:45:54 +000055 osm vim-delete --force ${VIM_TARGET}
beierlm9fc2b842020-06-26 14:57:09 -040056 sleep 5
57 break
58 fi
59 sleep 10
beierlm1d535af2020-12-03 09:28:28 -050060 VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}`
61 echo VIM status: ${VIM_LIST}
beierlm6cc2bd12020-12-03 11:44:47 -050062 STATUS=`echo ${VIM_LIST} | grep -io ENABLED`
beierlm9fc2b842020-06-26 14:57:09 -040063 done
64 if [[ ${STATUS} = "ENABLED" ]] ; then
65 break
Felipe Vicens02300c02020-07-02 12:19:28 +020066 fi
beierlm9fc2b842020-06-26 14:57:09 -040067 ((attempts--))
Felipe Vicens02300c02020-07-02 12:19:28 +020068 done
beierlm9fc2b842020-06-26 14:57:09 -040069 if [ $attempts -lt 0 ] ; then
70 echo "VIM failed to enter ENABLED state"
71 exit 1
72 fi
garciadeblas419af642021-04-14 16:45:24 +020073 if [ -n "${SDNC_URL}" ]; then
74 osm sdnc-create --name sdnc-osm --type ${SDNC_TYPE} --user ${SDNC_USER} --password ${SDNC_PASSWORD} --url ${SDNC_URL}
75 COUNTER=0
76 STATUS=""
77 while [ ${COUNTER} -lt 5 ] ; do
78 echo "Checking status of SDNC sdnc-osm to see if it is enabled"
79 STATUS=$(osm sdnc-show sdnc-osm |grep -io ENABLED)
80 if [ "${STATUS}" == "ENABLED" ]; then
81 break
82 fi
83 ((COUNTER++))
84 sleep 10
85 done
86 if [ "${STATUS}" == "ENABLED" ]; then
87 echo "SDNC enabled"
88 else
89 echo "SDNC failed to enter ENABLED state"
90 osm sdnc-show sdnc-osm
91 exit 1
92 fi
93 if [ -f /root/port-mapping.yaml ]; then
94 osm vim-update ${VIM_TARGET} --sdn_controller sdnc-osm --sdn_port_mapping /root/port-mapping.yaml
95 COUNTER2=0
96 RESULT=""
97 while [ ${COUNTER2} -lt 5 ] ; do
98 echo "Checking status of VIM $VIM_TARGET to see if there is port-mapping"
99 osm vim-show $VIM_TARGET |grep sdn-port-mapping
100 if [ $? -eq 0 ]; then
101 RESULT="OK"
102 break
103 fi
104 ((COUNTER2++))
105 sleep 10
106 done
107 if [ "${RESULT}" == "OK" ]; then
108 echo "Port-mapping correctly added"
109 else
110 echo "Port-mapping failed to be added"
111 osm vim-show ${VIM_TARGET}
112 exit 1
113 fi
114 fi
115 fi
Felipe Vicens55b61582020-06-24 21:23:44 +0200116}
117
beierlm9fc2b842020-06-26 14:57:09 -0400118
Felipe Vicensf96bb452020-06-22 08:12:30 +0200119PARAMS=""
Frank Brydene570b102020-09-07 08:45:54 +0000120RUN_CONFORMANCE_TESTS=false
Felipe Vicensf96bb452020-06-22 08:12:30 +0200121
122while (( "$#" )); do
123 case "$1" in
124 -t|--testingtags)
125 TEST=$2
126 shift 2
127 ;;
128 -p|--packagesbranch)
129 PACKAGES=$2 && download_packages
130 shift 2
131 ;;
132 -o|--osmclientversion)
Felipe Vicens24e3d152020-06-25 21:52:06 +0200133 OSMCLIENT=$2 && install_osmclient
Felipe Vicensf96bb452020-06-22 08:12:30 +0200134 shift 2
135 ;;
Felipe Vicens55b61582020-06-24 21:23:44 +0200136 -c|--createvim)
137 create_vim
138 shift 1
139 ;;
Frank Brydene570b102020-09-07 08:45:54 +0000140 -T)
141 NFV_TESTS_BRANCH=$2 && download_tst010
142 RUN_CONFORMANCE_TESTS=true
143 shift 1
144 ;;
Felipe Vicensf96bb452020-06-22 08:12:30 +0200145 -h|--help)
146 echo "OSM TESTS TOOL
147
148Usage:
149 docker run --rm=true -t osmtests --env-file <env_file> \\
Felipe Vicens5c54d272020-06-23 15:55:08 +0200150 -v <path_to_reports>:/reports osmtests \\
151 -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\
152 -v <path_to_kubeconfig>:/root/.kube/config \\
153 -o <osmclient_version> \\
154 -p <package_branch> \\
155 -t <testing_tags>
Felipe Vicens6366c682020-06-25 20:12:16 +0200156
Felipe Vicensf96bb452020-06-22 08:12:30 +0200157Options:
158 --env-file: It is the environmental file where is described the OSM target and VIM
159 -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest
160 -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master
garciadeblas4cf45d72021-04-08 13:52:22 +0200161 -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, daily, regression, particular_test]. Default: sanity
Frank Brydene570b102020-09-07 08:45:54 +0000162 -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests
Felipe Vicens55b61582020-06-24 21:23:44 +0200163 -c To create a VIM for the tests
Felipe Vicensf96bb452020-06-22 08:12:30 +0200164
165Volumes:
166 <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host
Felipe Vicens5c54d272020-06-23 15:55:08 +0200167 <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host
aktas8e0504f2021-09-06 13:23:35 +0300168 <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters"
Felipe Vicensf96bb452020-06-22 08:12:30 +0200169
170 exit 0
171 ;;
172 -*|--*=)
173 echo "Error: Unsupported flag $1" >&2
174 exit 1
175 ;;
176 *)
177 PARAMS="$PARAMS $1"
178 shift
179 ;;
180 esac
181done
182
183eval set -- "$PARAMS"
184
Felipe Vicens24e3d152020-06-25 21:52:06 +0200185if [[ -n "$BRANCH_NAME" ]]; then
186 PACKAGES=$BRANCH_NAME && download_packages
187 OSMCLIENT=$BRANCH_NAME && install_osmclient
Felipe Vicens6366c682020-06-25 20:12:16 +0200188fi
189
Frank Brydene570b102020-09-07 08:45:54 +0000190
191if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then
192 python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py
193fi
194
Felipe Vicens6366c682020-06-25 20:12:16 +0200195if [[ -z "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200196 printf "Test not provided. \nRunning default test: sanity\n"
197 TEST="sanity"
198fi
199
Felipe Vicens6366c682020-06-25 20:12:16 +0200200if [[ -n "${TEST}" ]]; then
Felipe Vicensf96bb452020-06-22 08:12:30 +0200201 robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/
202 exit 0
203else
204 echo "Wrong test provided"
205 exit 1
206fi
207
208exit 1