blob: e38b208dd617f0296e331288208b137c649a30ad [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"
tierno96d9cd42016-07-13 12:28:19 +020038 echo -e " OPTIONS:"
39 echo -e " -f --force does not prompt for confirmation"
40 echo -e " -h --help shows this help"
tierno76841842016-09-27 09:18:28 +000041 echo -e " --screen forces to run openmano (and openvim) service in a screen"
tierno96d9cd42016-07-13 12:28:19 +020042 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
43 echo -e " ~/.bashrc to be available by openmano CLI"
tierno75dc6782017-05-05 15:53:41 +020044 echo -e " --install-openvim installs openvim in test mode"
45 echo -e " --init-openvim --initopenvim if openvim runs locally, initopenvim is called to clean openvim"\
46 "database, create osm tenant and add fake hosts"
tierno96d9cd42016-07-13 12:28:19 +020047}
48
49function is_valid_uuid(){
50 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
51 return 1
52}
53
54#detect if is called with a source to use the 'exit'/'return' command for exiting
tierno76841842016-09-27 09:18:28 +000055DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
56DIRmano=$(dirname $DIRNAME)
57DIRscript=${DIRmano}/scripts
58
tierno75dc6782017-05-05 15:53:41 +020059#detect paths of executables, preceding the relative paths
60openmano=openmano && [[ -x "${DIRmano}/openmano" ]] && openmano="${DIRmano}/openmano"
61service_openmano=service-openmano && [[ -x "$DIRscript/service-openmano" ]] &&
62 service_openmano="$DIRscript/service-openmano"
63initopenvim="initopenvim"
64openvim="openvim"
65
tiernob6884bd2016-07-15 14:09:47 +020066[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
tierno96d9cd42016-07-13 12:28:19 +020067
tierno96d9cd42016-07-13 12:28:19 +020068
tierno76841842016-09-27 09:18:28 +000069#process options
tierno75dc6782017-05-05 15:53:41 +020070source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim:initopenvim install-openvim screen" \
71 $* || $_exit 1
tierno205d1022016-07-21 11:26:22 +020072
tierno76841842016-09-27 09:18:28 +000073#help
74[ -n "$option_help" ] && usage && $_exit 0
75
76#check correct arguments
77force_param="" && [[ -n "$option_force" ]] && force_param=" -f"
78insert_bashrc_param="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param=" --insert-bashrc"
79screen_mano_param="" && [[ -n "$option_screen" ]] && screen_mano_param=" --screen-name=mano"
80screen_vim_param="" && [[ -n "$option_screen" ]] && screen_vim_param=" --screen-name=vim"
81
82action_list=""
83
84for argument in $params
tierno96d9cd42016-07-13 12:28:19 +020085do
tierno75dc6782017-05-05 15:53:41 +020086 if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] ||
87 [[ $argument == add-openvim ]] || [[ $argument == del-openvim ]] || [[ -z "$argument" ]]
tierno96d9cd42016-07-13 12:28:19 +020088 then
tierno205d1022016-07-21 11:26:22 +020089 action_list="$action_list $argument"
90 continue
tierno96d9cd42016-07-13 12:28:19 +020091 fi
tierno205d1022016-07-21 11:26:22 +020092 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
tierno96d9cd42016-07-13 12:28:19 +020093done
94
tiernob6884bd2016-07-15 14:09:47 +020095export OPENMANO_HOST=localhost
96export OPENMANO_PORT=9090
tierno76841842016-09-27 09:18:28 +000097[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc
98[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc
tiernob6884bd2016-07-15 14:09:47 +020099
100
tierno96d9cd42016-07-13 12:28:19 +0200101#by default action should be reset and create
tierno75dc6782017-05-05 15:53:41 +0200102[[ -z $action_list ]] && action_list="reset add-openvim create delete del-openvim"
tiernoaa5832d2016-12-07 16:20:25 +0100103
104if [[ -n "$option_install_openvim" ]]
105then
tierno75dc6782017-05-05 15:53:41 +0200106 echo
107 echo "action: install openvim"
108 echo "################################"
tiernoa6003ee2016-12-21 16:18:00 +0100109 mkdir -p ${DIRNAME}/local
110 pushd ${DIRNAME}/local
111 echo "installing openvim at ${DIRNAME}/openvim ... "
tiernoaa5832d2016-12-07 16:20:25 +0100112 wget -O install-openvim.sh "https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=blob_plain;f=scripts/install-openvim.sh"
113 chmod +x install-openvim.sh
114 sudo ./install-openvim.sh --no-install-packages --force --quiet --develop
tierno75dc6782017-05-05 15:53:41 +0200115 openvim="${DIRNAME}/local/openvim/openvim"
116 #force inito-penvim
117 option_init_openvim="-"
118 initopenvim="${DIRNAME}/local/openvim/scripts/initopenvim"
tiernoaa5832d2016-12-07 16:20:25 +0100119 popd
120fi
tierno75dc6782017-05-05 15:53:41 +0200121
122if [[ -n "$option_init_openvim" ]]
123then
124 echo
125 echo "action: init openvim"
126 echo "################################"
127 ${initopenvim} ${force_param}${insert_bashrc_param}${screen_vim_param} || \
128 echo "WARNING openvim cannot be initialized. The rest of test can fail!"
129fi
tierno96d9cd42016-07-13 12:28:19 +0200130
tierno72f35a52016-07-15 13:18:30 +0200131#check openvim client variables are set
132#fail=""
133#[[ -z $OPENVIM_HOST ]] && echo "OPENVIM_HOST variable not defined" >&2 && fail=1
134#[[ -z $OPENVIM_PORT ]] && echo "OPENVIM_PORT variable not defined" >&2 && fail=1
135#[[ -n $fail ]] && $_exit 1
136
137
tierno96d9cd42016-07-13 12:28:19 +0200138for action in $action_list
139do
tierno75dc6782017-05-05 15:53:41 +0200140 echo
141 echo "action: $action"
142 echo "################################"
tierno96d9cd42016-07-13 12:28:19 +0200143#if [[ $action == "install-openvim" ]]
144 #echo "Installing and starting openvim"
145 #mkdir -p temp
146 #pushd temp
147 #wget https://github.com/nfvlabs/openvim/raw/v0.4/scripts/install-openvim.sh
148 #chmod -x install-openvim.sh
149#fi
150
151if [[ $action == "reset" ]]
152then
153
154 #ask for confirmation if argument is not -f --force
tierno72f35a52016-07-15 13:18:30 +0200155 force_=y
tierno76841842016-09-27 09:18:28 +0000156 [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
tierno96d9cd42016-07-13 12:28:19 +0200157 [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
158
159 echo "Stopping openmano"
tierno75dc6782017-05-05 15:53:41 +0200160 $service_openmano mano stop${screen_mano_param}
tierno96d9cd42016-07-13 12:28:19 +0200161 echo "Initializing openmano database"
tierno75dc6782017-05-05 15:53:41 +0200162 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
tierno96d9cd42016-07-13 12:28:19 +0200163 echo "Starting openmano"
tierno75dc6782017-05-05 15:53:41 +0200164 $service_openmano mano start${screen_mano_param}
tierno96d9cd42016-07-13 12:28:19 +0200165 echo
tierno75dc6782017-05-05 15:53:41 +0200166 printf "%-50s" "Creating openmano tenant 'osm': "
167 result=`$openmano tenant-create osm --description="created by basictest.sh"`
tierno96d9cd42016-07-13 12:28:19 +0200168 nfvotenant=`echo $result |gawk '{print $1}'`
169 #check a valid uuid is obtained
170 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
tierno75dc6782017-05-05 15:53:41 +0200171 export OPENMANO_TENANT=osm
172 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=osm" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200173 echo $nfvotenant
174
tierno75dc6782017-05-05 15:53:41 +0200175elif [[ $action == "delete" ]]
176then
177 result=`openmano tenant-list osm`
178 nfvotenant=`echo $result |gawk '{print $1}'`
179 #check a valid uuid is obtained
180 is_valid_uuid $nfvotenant || ! echo "Tenant osm not found. Already delete?" >&2 || $_exit 1
181 export OPENMANO_TENANT=$nfvotenant
182 $openmano instance-scenario-delete -f simple-instance || echo "fail"
183 $openmano instance-scenario-delete -f complex-instance || echo "fail"
184 $openmano instance-scenario-delete -f complex2-instance || echo "fail"
185 $openmano instance-scenario-delete -f complex3-instance || echo "fail"
186 $openmano instance-scenario-delete -f complex4-instance || echo "fail"
187 $openmano instance-scenario-delete -f complex5-instance || echo "fail"
188 $openmano scenario-delete -f simple || echo "fail"
189 $openmano scenario-delete -f complex || echo "fail"
190 $openmano scenario-delete -f complex2 || echo "fail"
191 $openmano scenario-delete -f complex3 || echo "fail"
192 $openmano scenario-delete -f complex4 || echo "fail"
193 $openmano scenario-delete -f complex5 || echo "fail"
194 $openmano vnf-delete -f linux || echo "fail"
195 $openmano vnf-delete -f linux_2VMs_v02 || echo "fail"
196 $openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
197 $openmano vnf-delete -f dataplaneVNF_2VMs_v02 || echo "fail"
198 $openmano vnf-delete -f dataplaneVNF4 || echo "fail"
199 $openmano vnf-delete -f dataplaneVNF2 || echo "fail"
200 $openmano vnf-delete -f dataplaneVNF3 || echo "fail"
201
202elif [[ $action == "del-openvim" ]]
203then
204 $openmano datacenter-detach local-openvim || echo "fail"
205 $openmano datacenter-delete -f local-openvim || echo "fail"
206
207elif [[ $action == "add-openvim" ]]
208then
209
210 printf "%-50s" "Creating datacenter 'local-openvim' at openmano:"
tierno96d9cd42016-07-13 12:28:19 +0200211 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
212 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
213 URL_ADMIN_PARAM=""
tierno8008c3a2016-10-13 15:34:28 +0000214 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
tierno75dc6782017-05-05 15:53:41 +0200215 result=`$openmano datacenter-create local-openvim "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" \
216 --type=openvim${URL_ADMIN_PARAM} --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200217 datacenter=`echo $result |gawk '{print $1}'`
218 #check a valid uuid is obtained
219 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
220 echo $datacenter
tierno75dc6782017-05-05 15:53:41 +0200221 export OPENMANO_DATACENTER=local-openvim
222 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=local-openvim" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200223
224 printf "%-50s" "Attaching openmano tenant to the datacenter:"
tierno75dc6782017-05-05 15:53:41 +0200225 result=`$openmano datacenter-attach local-openvim --vim-tenant-name=osm --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200226 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
227 echo OK
228
229 printf "%-50s" "Updating external nets in openmano: "
tierno75dc6782017-05-05 15:53:41 +0200230 result=`$openmano datacenter-netmap-delete -f --all`
tierno96d9cd42016-07-13 12:28:19 +0200231 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
tierno75dc6782017-05-05 15:53:41 +0200232 result=`$openmano datacenter-netmap-import -f`
tierno96d9cd42016-07-13 12:28:19 +0200233 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
234 echo OK
235
tierno75dc6782017-05-05 15:53:41 +0200236elif [[ $action == "create" ]]
237then
garciadeblas9a241aa2016-09-30 12:25:59 +0200238 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
tierno96d9cd42016-07-13 12:28:19 +0200239 do
240 printf "%-50s" "Creating VNF '${VNF}': "
tierno75dc6782017-05-05 15:53:41 +0200241 result=`$openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
tierno96d9cd42016-07-13 12:28:19 +0200242 vnf=`echo $result |gawk '{print $1}'`
243 #check a valid uuid is obtained
244 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
245 echo $vnf
246 done
garciadeblas14480452017-01-10 13:08:07 +0100247 for NS in simple complex complex2 complex3 complex4 complex5
tierno96d9cd42016-07-13 12:28:19 +0200248 do
249 printf "%-50s" "Creating scenario '${NS}':"
tierno75dc6782017-05-05 15:53:41 +0200250 result=`$openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
tierno96d9cd42016-07-13 12:28:19 +0200251 scenario=`echo $result |gawk '{print $1}'`
252 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
253 echo $scenario
254 done
255
garciadeblas14480452017-01-10 13:08:07 +0100256 for IS in simple complex complex2 complex3 complex5
tierno96d9cd42016-07-13 12:28:19 +0200257 do
258 printf "%-50s" "Creating instance-scenario '${IS}':"
tierno75dc6782017-05-05 15:53:41 +0200259 result=`$openmano instance-scenario-create --scenario ${IS} --name ${IS}-instance`
tierno96d9cd42016-07-13 12:28:19 +0200260 instance=`echo $result |gawk '{print $1}'`
261 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
262 echo $instance
263 done
264
garciadeblas9f8456e2016-09-05 05:02:59 +0200265 printf "%-50s" "Creating instance-scenario 'complex4':"
tierno75dc6782017-05-05 15:53:41 +0200266 result=`$openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
garciadeblas9f8456e2016-09-05 05:02:59 +0200267 instance=`echo $result |gawk '{print $1}'`
268 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
269 echo $instance
270
tierno96d9cd42016-07-13 12:28:19 +0200271 echo
272 #echo "Check virtual machines are deployed"
273 #vms_error=`openvim vm-list | grep ERROR | wc -l`
274 #vms=`openvim vm-list | wc -l`
275 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
276 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
277fi
278done
279
280echo
281echo DONE
282
283