blob: 8f5a225b86fc1cddb70116973a2077df893463c3 [file] [log] [blame]
tierno96d9cd42016-07-13 12:28:19 +02001#!/bin/bash
2
3##
tierno92021022018-09-12 16:29:23 +02004# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
tierno96d9cd42016-07-13 12:28:19 +02005# This file is part of openmano
6# All Rights Reserved.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# 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, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
19#
20# For those usages not covered by the Apache License, Version 2.0 please
21# contact with: nfvlabs@tid.es
22##
23
24#This script can be used as a basic test of openmano.
25#WARNING: It destroy the database content
26
27
28function usage(){
29 echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] <action>\n test openmano using openvim as a VIM"
30 echo -e " the OPENVIM_HOST, OPENVIM_PORT shell variables indicate openvim location"
tierno72f35a52016-07-15 13:18:30 +020031 echo -e " by default localhost:9080"
tierno75dc6782017-05-05 15:53:41 +020032 echo -e " <action> is a list of the following items (by default 'reset add-openvim create delete del-openvim')"
33 echo -e " reset resets the openmano database content and creates osm tenant"
34 echo -e " add-openvim adds and attaches a local openvim datacenter"
35 echo -e " del-openvim detaches and deletes the local openvim datacenter"
36 echo -e " create creates VNFs, scenarios and instances"
37 echo -e " delete deletes the created instances, scenarios and VNFs"
tierno4d73b392017-05-25 14:19:48 +020038 echo -e " delete-all deletes ALL the existing instances, scenarios and vnf at the current tenant"
tierno96d9cd42016-07-13 12:28:19 +020039 echo -e " OPTIONS:"
40 echo -e " -f --force does not prompt for confirmation"
41 echo -e " -h --help shows this help"
tierno76841842016-09-27 09:18:28 +000042 echo -e " --screen forces to run openmano (and openvim) service in a screen"
tierno96d9cd42016-07-13 12:28:19 +020043 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
44 echo -e " ~/.bashrc to be available by openmano CLI"
tierno75dc6782017-05-05 15:53:41 +020045 echo -e " --install-openvim installs openvim in test mode"
46 echo -e " --init-openvim --initopenvim if openvim runs locally, initopenvim is called to clean openvim"\
47 "database, create osm tenant and add fake hosts"
tierno96d9cd42016-07-13 12:28:19 +020048}
49
50function is_valid_uuid(){
51 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
52 return 1
53}
54
55#detect if is called with a source to use the 'exit'/'return' command for exiting
tierno76841842016-09-27 09:18:28 +000056DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
57DIRmano=$(dirname $DIRNAME)
58DIRscript=${DIRmano}/scripts
59
tierno75dc6782017-05-05 15:53:41 +020060#detect paths of executables, preceding the relative paths
61openmano=openmano && [[ -x "${DIRmano}/openmano" ]] && openmano="${DIRmano}/openmano"
62service_openmano=service-openmano && [[ -x "$DIRscript/service-openmano" ]] &&
63 service_openmano="$DIRscript/service-openmano"
64initopenvim="initopenvim"
65openvim="openvim"
66
tiernob6884bd2016-07-15 14:09:47 +020067[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
tierno96d9cd42016-07-13 12:28:19 +020068
tierno96d9cd42016-07-13 12:28:19 +020069
tierno76841842016-09-27 09:18:28 +000070#process options
tierno75dc6782017-05-05 15:53:41 +020071source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim:initopenvim install-openvim screen" \
72 $* || $_exit 1
tierno205d1022016-07-21 11:26:22 +020073
tierno76841842016-09-27 09:18:28 +000074#help
75[ -n "$option_help" ] && usage && $_exit 0
76
77#check correct arguments
78force_param="" && [[ -n "$option_force" ]] && force_param=" -f"
79insert_bashrc_param="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param=" --insert-bashrc"
80screen_mano_param="" && [[ -n "$option_screen" ]] && screen_mano_param=" --screen-name=mano"
81screen_vim_param="" && [[ -n "$option_screen" ]] && screen_vim_param=" --screen-name=vim"
82
83action_list=""
84
85for argument in $params
tierno96d9cd42016-07-13 12:28:19 +020086do
tierno75dc6782017-05-05 15:53:41 +020087 if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] ||
tierno4d73b392017-05-25 14:19:48 +020088 [[ $argument == add-openvim ]] || [[ $argument == del-openvim ]] || [[ $argument == delete-all ]] ||
89 [[ -z "$argument" ]]
tierno96d9cd42016-07-13 12:28:19 +020090 then
tierno205d1022016-07-21 11:26:22 +020091 action_list="$action_list $argument"
92 continue
tierno96d9cd42016-07-13 12:28:19 +020093 fi
tierno205d1022016-07-21 11:26:22 +020094 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
tierno96d9cd42016-07-13 12:28:19 +020095done
96
tiernob6884bd2016-07-15 14:09:47 +020097export OPENMANO_HOST=localhost
98export OPENMANO_PORT=9090
tierno76841842016-09-27 09:18:28 +000099[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc
100[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc
tiernob6884bd2016-07-15 14:09:47 +0200101
102
tierno96d9cd42016-07-13 12:28:19 +0200103#by default action should be reset and create
tierno75dc6782017-05-05 15:53:41 +0200104[[ -z $action_list ]] && action_list="reset add-openvim create delete del-openvim"
tiernoaa5832d2016-12-07 16:20:25 +0100105
106if [[ -n "$option_install_openvim" ]]
107then
tierno75dc6782017-05-05 15:53:41 +0200108 echo
109 echo "action: install openvim"
110 echo "################################"
tiernoa6003ee2016-12-21 16:18:00 +0100111 mkdir -p ${DIRNAME}/local
112 pushd ${DIRNAME}/local
113 echo "installing openvim at ${DIRNAME}/openvim ... "
tiernoaa5832d2016-12-07 16:20:25 +0100114 wget -O install-openvim.sh "https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=blob_plain;f=scripts/install-openvim.sh"
115 chmod +x install-openvim.sh
116 sudo ./install-openvim.sh --no-install-packages --force --quiet --develop
tierno75dc6782017-05-05 15:53:41 +0200117 openvim="${DIRNAME}/local/openvim/openvim"
118 #force inito-penvim
119 option_init_openvim="-"
120 initopenvim="${DIRNAME}/local/openvim/scripts/initopenvim"
tiernoaa5832d2016-12-07 16:20:25 +0100121 popd
122fi
tierno75dc6782017-05-05 15:53:41 +0200123
124if [[ -n "$option_init_openvim" ]]
125then
126 echo
127 echo "action: init openvim"
128 echo "################################"
129 ${initopenvim} ${force_param}${insert_bashrc_param}${screen_vim_param} || \
130 echo "WARNING openvim cannot be initialized. The rest of test can fail!"
131fi
tierno96d9cd42016-07-13 12:28:19 +0200132
tierno72f35a52016-07-15 13:18:30 +0200133#check openvim client variables are set
134#fail=""
135#[[ -z $OPENVIM_HOST ]] && echo "OPENVIM_HOST variable not defined" >&2 && fail=1
136#[[ -z $OPENVIM_PORT ]] && echo "OPENVIM_PORT variable not defined" >&2 && fail=1
137#[[ -n $fail ]] && $_exit 1
138
139
tierno96d9cd42016-07-13 12:28:19 +0200140for action in $action_list
141do
tierno75dc6782017-05-05 15:53:41 +0200142 echo
143 echo "action: $action"
144 echo "################################"
tierno96d9cd42016-07-13 12:28:19 +0200145#if [[ $action == "install-openvim" ]]
146 #echo "Installing and starting openvim"
147 #mkdir -p temp
148 #pushd temp
149 #wget https://github.com/nfvlabs/openvim/raw/v0.4/scripts/install-openvim.sh
150 #chmod -x install-openvim.sh
151#fi
152
153if [[ $action == "reset" ]]
154then
155
156 #ask for confirmation if argument is not -f --force
tierno72f35a52016-07-15 13:18:30 +0200157 force_=y
tierno76841842016-09-27 09:18:28 +0000158 [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
tierno96d9cd42016-07-13 12:28:19 +0200159 [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
160
161 echo "Stopping openmano"
tierno75dc6782017-05-05 15:53:41 +0200162 $service_openmano mano stop${screen_mano_param}
tierno96d9cd42016-07-13 12:28:19 +0200163 echo "Initializing openmano database"
tierno75dc6782017-05-05 15:53:41 +0200164 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
tierno96d9cd42016-07-13 12:28:19 +0200165 echo "Starting openmano"
tierno75dc6782017-05-05 15:53:41 +0200166 $service_openmano mano start${screen_mano_param}
tierno96d9cd42016-07-13 12:28:19 +0200167 echo
tierno75dc6782017-05-05 15:53:41 +0200168 printf "%-50s" "Creating openmano tenant 'osm': "
169 result=`$openmano tenant-create osm --description="created by basictest.sh"`
tierno96d9cd42016-07-13 12:28:19 +0200170 nfvotenant=`echo $result |gawk '{print $1}'`
171 #check a valid uuid is obtained
172 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
tierno75dc6782017-05-05 15:53:41 +0200173 export OPENMANO_TENANT=osm
174 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=osm" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200175 echo $nfvotenant
176
tierno75dc6782017-05-05 15:53:41 +0200177elif [[ $action == "delete" ]]
178then
179 result=`openmano tenant-list osm`
180 nfvotenant=`echo $result |gawk '{print $1}'`
181 #check a valid uuid is obtained
182 is_valid_uuid $nfvotenant || ! echo "Tenant osm not found. Already delete?" >&2 || $_exit 1
183 export OPENMANO_TENANT=$nfvotenant
184 $openmano instance-scenario-delete -f simple-instance || echo "fail"
185 $openmano instance-scenario-delete -f complex-instance || echo "fail"
186 $openmano instance-scenario-delete -f complex2-instance || echo "fail"
187 $openmano instance-scenario-delete -f complex3-instance || echo "fail"
188 $openmano instance-scenario-delete -f complex4-instance || echo "fail"
189 $openmano instance-scenario-delete -f complex5-instance || echo "fail"
tiernof1ba57e2017-09-07 12:23:19 +0200190 $openmano instance-scenario-delete -f 3vdu_2vnf_nsd-instance || echo "fail"
tierno75dc6782017-05-05 15:53:41 +0200191 $openmano scenario-delete -f simple || echo "fail"
192 $openmano scenario-delete -f complex || echo "fail"
193 $openmano scenario-delete -f complex2 || echo "fail"
194 $openmano scenario-delete -f complex3 || echo "fail"
195 $openmano scenario-delete -f complex4 || echo "fail"
196 $openmano scenario-delete -f complex5 || echo "fail"
tiernof1ba57e2017-09-07 12:23:19 +0200197 $openmano scenario-delete -f osm_id=3vdu_2vnf_nsd || echo "fail"
tierno75dc6782017-05-05 15:53:41 +0200198 $openmano vnf-delete -f linux || echo "fail"
199 $openmano vnf-delete -f linux_2VMs_v02 || echo "fail"
200 $openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
201 $openmano vnf-delete -f dataplaneVNF_2VMs_v02 || echo "fail"
tierno4d73b392017-05-25 14:19:48 +0200202 $openmano vnf-delete -f dataplaneVNF1 || echo "fail"
tierno75dc6782017-05-05 15:53:41 +0200203 $openmano vnf-delete -f dataplaneVNF2 || echo "fail"
204 $openmano vnf-delete -f dataplaneVNF3 || echo "fail"
tierno4d73b392017-05-25 14:19:48 +0200205 $openmano vnf-delete -f dataplaneVNF4 || echo "fail"
tiernof1ba57e2017-09-07 12:23:19 +0200206 $openmano vnf-delete -f osm_id=3vdu_vnfd || echo "fail"
tierno4d73b392017-05-25 14:19:48 +0200207
208elif [[ $action == "delete-all" ]]
209then
210 for i in instance-scenario scenario vnf
211 do
212 for f in `$openmano $i-list | awk '{print $1}'`
213 do
214 [[ -n "$f" ]] && [[ "$f" != No ]] && $openmano ${i}-delete -f ${f}
215 done
216 done
tierno75dc6782017-05-05 15:53:41 +0200217
218elif [[ $action == "del-openvim" ]]
219then
220 $openmano datacenter-detach local-openvim || echo "fail"
221 $openmano datacenter-delete -f local-openvim || echo "fail"
222
223elif [[ $action == "add-openvim" ]]
224then
225
226 printf "%-50s" "Creating datacenter 'local-openvim' at openmano:"
tierno96d9cd42016-07-13 12:28:19 +0200227 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
228 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
229 URL_ADMIN_PARAM=""
tierno8008c3a2016-10-13 15:34:28 +0000230 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
tierno75dc6782017-05-05 15:53:41 +0200231 result=`$openmano datacenter-create local-openvim "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" \
232 --type=openvim${URL_ADMIN_PARAM} --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200233 datacenter=`echo $result |gawk '{print $1}'`
234 #check a valid uuid is obtained
235 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
236 echo $datacenter
tierno75dc6782017-05-05 15:53:41 +0200237 export OPENMANO_DATACENTER=local-openvim
238 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=local-openvim" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200239
240 printf "%-50s" "Attaching openmano tenant to the datacenter:"
tierno75dc6782017-05-05 15:53:41 +0200241 result=`$openmano datacenter-attach local-openvim --vim-tenant-name=osm --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200242 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
243 echo OK
244
245 printf "%-50s" "Updating external nets in openmano: "
tierno75dc6782017-05-05 15:53:41 +0200246 result=`$openmano datacenter-netmap-delete -f --all`
tierno96d9cd42016-07-13 12:28:19 +0200247 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
tierno75dc6782017-05-05 15:53:41 +0200248 result=`$openmano datacenter-netmap-import -f`
tierno96d9cd42016-07-13 12:28:19 +0200249 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
250 echo OK
tiernof1ba57e2017-09-07 12:23:19 +0200251 result=`$openmano datacenter-netmap-create --name=default --vim-name=mgmt`
252 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
253 echo OK
tierno96d9cd42016-07-13 12:28:19 +0200254
tierno75dc6782017-05-05 15:53:41 +0200255elif [[ $action == "create" ]]
256then
tiernoed854572017-10-03 16:18:09 +0200257 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
tierno96d9cd42016-07-13 12:28:19 +0200258 do
259 printf "%-50s" "Creating VNF '${VNF}': "
tierno75dc6782017-05-05 15:53:41 +0200260 result=`$openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
tierno96d9cd42016-07-13 12:28:19 +0200261 vnf=`echo $result |gawk '{print $1}'`
262 #check a valid uuid is obtained
263 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
264 echo $vnf
265 done
tiernoed854572017-10-03 16:18:09 +0200266
267 printf "%-50s" "Creating VNF '${VNF}': "
268 result=`$openmano vnf-create $DIRmano/vnfs/examples/v3_3vdu_vnfd.yaml --image-name=cirros034`
269 vnf=`echo $result |gawk '{print $1}'`
270 #check a valid uuid is obtained
271 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
272 echo $vnf
273
tiernof1ba57e2017-09-07 12:23:19 +0200274 for NS in simple complex complex2 complex3 complex4 complex5 v3_3vdu_2vnf_nsd
tierno96d9cd42016-07-13 12:28:19 +0200275 do
276 printf "%-50s" "Creating scenario '${NS}':"
tierno75dc6782017-05-05 15:53:41 +0200277 result=`$openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
tierno96d9cd42016-07-13 12:28:19 +0200278 scenario=`echo $result |gawk '{print $1}'`
279 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
280 echo $scenario
281 done
282
tiernof1ba57e2017-09-07 12:23:19 +0200283 for IS in simple complex complex2 complex3 complex5 osm_id=3vdu_2vnf_nsd
tierno96d9cd42016-07-13 12:28:19 +0200284 do
285 printf "%-50s" "Creating instance-scenario '${IS}':"
tiernof1ba57e2017-09-07 12:23:19 +0200286 result=`$openmano instance-scenario-create --scenario ${IS} --name ${IS#osm_id=}-instance`
tierno96d9cd42016-07-13 12:28:19 +0200287 instance=`echo $result |gawk '{print $1}'`
288 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
289 echo $instance
290 done
291
garciadeblas9f8456e2016-09-05 05:02:59 +0200292 printf "%-50s" "Creating instance-scenario 'complex4':"
tierno75dc6782017-05-05 15:53:41 +0200293 result=`$openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
garciadeblas9f8456e2016-09-05 05:02:59 +0200294 instance=`echo $result |gawk '{print $1}'`
295 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
296 echo $instance
297
tierno96d9cd42016-07-13 12:28:19 +0200298 echo
299 #echo "Check virtual machines are deployed"
300 #vms_error=`openvim vm-list | grep ERROR | wc -l`
301 #vms=`openvim vm-list | wc -l`
302 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
303 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
304fi
305done
306
307echo
308echo DONE
309
310