blob: 3af91a71528c5a9f03cf09f694a21d8b6acb6765 [file] [log] [blame]
tierno96d9cd42016-07-13 12:28:19 +02001#!/bin/bash
2
3##
4# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5# 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"
190 $openmano scenario-delete -f simple || echo "fail"
191 $openmano scenario-delete -f complex || echo "fail"
192 $openmano scenario-delete -f complex2 || echo "fail"
193 $openmano scenario-delete -f complex3 || echo "fail"
194 $openmano scenario-delete -f complex4 || echo "fail"
195 $openmano scenario-delete -f complex5 || echo "fail"
196 $openmano vnf-delete -f linux || echo "fail"
197 $openmano vnf-delete -f linux_2VMs_v02 || echo "fail"
198 $openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
199 $openmano vnf-delete -f dataplaneVNF_2VMs_v02 || echo "fail"
tierno4d73b392017-05-25 14:19:48 +0200200 $openmano vnf-delete -f dataplaneVNF1 || echo "fail"
tierno75dc6782017-05-05 15:53:41 +0200201 $openmano vnf-delete -f dataplaneVNF2 || echo "fail"
202 $openmano vnf-delete -f dataplaneVNF3 || echo "fail"
tierno4d73b392017-05-25 14:19:48 +0200203 $openmano vnf-delete -f dataplaneVNF4 || echo "fail"
204
205elif [[ $action == "delete-all" ]]
206then
207 for i in instance-scenario scenario vnf
208 do
209 for f in `$openmano $i-list | awk '{print $1}'`
210 do
211 [[ -n "$f" ]] && [[ "$f" != No ]] && $openmano ${i}-delete -f ${f}
212 done
213 done
tierno75dc6782017-05-05 15:53:41 +0200214
215elif [[ $action == "del-openvim" ]]
216then
217 $openmano datacenter-detach local-openvim || echo "fail"
218 $openmano datacenter-delete -f local-openvim || echo "fail"
219
220elif [[ $action == "add-openvim" ]]
221then
222
223 printf "%-50s" "Creating datacenter 'local-openvim' at openmano:"
tierno96d9cd42016-07-13 12:28:19 +0200224 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
225 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
226 URL_ADMIN_PARAM=""
tierno8008c3a2016-10-13 15:34:28 +0000227 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
tierno75dc6782017-05-05 15:53:41 +0200228 result=`$openmano datacenter-create local-openvim "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" \
229 --type=openvim${URL_ADMIN_PARAM} --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200230 datacenter=`echo $result |gawk '{print $1}'`
231 #check a valid uuid is obtained
232 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
233 echo $datacenter
tierno75dc6782017-05-05 15:53:41 +0200234 export OPENMANO_DATACENTER=local-openvim
235 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=local-openvim" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200236
237 printf "%-50s" "Attaching openmano tenant to the datacenter:"
tierno75dc6782017-05-05 15:53:41 +0200238 result=`$openmano datacenter-attach local-openvim --vim-tenant-name=osm --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200239 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
240 echo OK
241
242 printf "%-50s" "Updating external nets in openmano: "
tierno75dc6782017-05-05 15:53:41 +0200243 result=`$openmano datacenter-netmap-delete -f --all`
tierno96d9cd42016-07-13 12:28:19 +0200244 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
tierno75dc6782017-05-05 15:53:41 +0200245 result=`$openmano datacenter-netmap-import -f`
tierno96d9cd42016-07-13 12:28:19 +0200246 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
247 echo OK
248
tierno75dc6782017-05-05 15:53:41 +0200249elif [[ $action == "create" ]]
250then
garciadeblas9a241aa2016-09-30 12:25:59 +0200251 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
tierno96d9cd42016-07-13 12:28:19 +0200252 do
253 printf "%-50s" "Creating VNF '${VNF}': "
tierno75dc6782017-05-05 15:53:41 +0200254 result=`$openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
tierno96d9cd42016-07-13 12:28:19 +0200255 vnf=`echo $result |gawk '{print $1}'`
256 #check a valid uuid is obtained
257 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
258 echo $vnf
259 done
garciadeblas14480452017-01-10 13:08:07 +0100260 for NS in simple complex complex2 complex3 complex4 complex5
tierno96d9cd42016-07-13 12:28:19 +0200261 do
262 printf "%-50s" "Creating scenario '${NS}':"
tierno75dc6782017-05-05 15:53:41 +0200263 result=`$openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
tierno96d9cd42016-07-13 12:28:19 +0200264 scenario=`echo $result |gawk '{print $1}'`
265 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
266 echo $scenario
267 done
268
garciadeblas14480452017-01-10 13:08:07 +0100269 for IS in simple complex complex2 complex3 complex5
tierno96d9cd42016-07-13 12:28:19 +0200270 do
271 printf "%-50s" "Creating instance-scenario '${IS}':"
tierno75dc6782017-05-05 15:53:41 +0200272 result=`$openmano instance-scenario-create --scenario ${IS} --name ${IS}-instance`
tierno96d9cd42016-07-13 12:28:19 +0200273 instance=`echo $result |gawk '{print $1}'`
274 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
275 echo $instance
276 done
277
garciadeblas9f8456e2016-09-05 05:02:59 +0200278 printf "%-50s" "Creating instance-scenario 'complex4':"
tierno75dc6782017-05-05 15:53:41 +0200279 result=`$openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
garciadeblas9f8456e2016-09-05 05:02:59 +0200280 instance=`echo $result |gawk '{print $1}'`
281 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
282 echo $instance
283
tierno96d9cd42016-07-13 12:28:19 +0200284 echo
285 #echo "Check virtual machines are deployed"
286 #vms_error=`openvim vm-list | grep ERROR | wc -l`
287 #vms=`openvim vm-list | wc -l`
288 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
289 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
290fi
291done
292
293echo
294echo DONE
295
296