blob: 3b2b35355b45768a36f9a69aa41881261107a7e3 [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"
tierno96d9cd42016-07-13 12:28:19 +020032 echo -e " <action> is a list of the following items (by default 'reset create delete')"
33 echo -e " reset reset the openmano database content"
34 echo -e " create creates items"
35 echo -e " delete delete created items"
36 echo -e " OPTIONS:"
37 echo -e " -f --force does not prompt for confirmation"
38 echo -e " -h --help shows this help"
tierno76841842016-09-27 09:18:28 +000039 echo -e " --screen forces to run openmano (and openvim) service in a screen"
tierno96d9cd42016-07-13 12:28:19 +020040 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
41 echo -e " ~/.bashrc to be available by openmano CLI"
tiernoaa5832d2016-12-07 16:20:25 +010042 echo -e " --install-openvim install openvim in test mode"
tierno72f35a52016-07-15 13:18:30 +020043 echo -e " --init-openvim if openvim runs locally, an init is called to clean openvim"
44 echo -e " database and add fake hosts"
tierno96d9cd42016-07-13 12:28:19 +020045}
46
47function is_valid_uuid(){
48 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
49 return 1
50}
51
52#detect if is called with a source to use the 'exit'/'return' command for exiting
tierno76841842016-09-27 09:18:28 +000053DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
54DIRmano=$(dirname $DIRNAME)
55DIRscript=${DIRmano}/scripts
56
tiernob6884bd2016-07-15 14:09:47 +020057[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
tierno96d9cd42016-07-13 12:28:19 +020058
tierno96d9cd42016-07-13 12:28:19 +020059
tierno76841842016-09-27 09:18:28 +000060#process options
tiernoaa5832d2016-12-07 16:20:25 +010061source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim install-openvim screen" $* || $_exit 1
tierno205d1022016-07-21 11:26:22 +020062
tierno76841842016-09-27 09:18:28 +000063#help
64[ -n "$option_help" ] && usage && $_exit 0
65
66#check correct arguments
67force_param="" && [[ -n "$option_force" ]] && force_param=" -f"
68insert_bashrc_param="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param=" --insert-bashrc"
69screen_mano_param="" && [[ -n "$option_screen" ]] && screen_mano_param=" --screen-name=mano"
70screen_vim_param="" && [[ -n "$option_screen" ]] && screen_vim_param=" --screen-name=vim"
71
72action_list=""
73
74for argument in $params
tierno96d9cd42016-07-13 12:28:19 +020075do
tierno8008c3a2016-10-13 15:34:28 +000076 if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] || [[ -z "$argument" ]]
tierno96d9cd42016-07-13 12:28:19 +020077 then
tierno205d1022016-07-21 11:26:22 +020078 action_list="$action_list $argument"
79 continue
tierno96d9cd42016-07-13 12:28:19 +020080 fi
tierno205d1022016-07-21 11:26:22 +020081 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
tierno96d9cd42016-07-13 12:28:19 +020082done
83
tiernob6884bd2016-07-15 14:09:47 +020084export OPENMANO_HOST=localhost
85export OPENMANO_PORT=9090
tierno76841842016-09-27 09:18:28 +000086[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc
87[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc
tiernob6884bd2016-07-15 14:09:47 +020088
89
tierno96d9cd42016-07-13 12:28:19 +020090#by default action should be reset and create
91[[ -z $action_list ]] && action_list="reset create delete"
tiernoaa5832d2016-12-07 16:20:25 +010092
93if [[ -n "$option_install_openvim" ]]
94then
tiernoa6003ee2016-12-21 16:18:00 +010095 mkdir -p ${DIRNAME}/local
96 pushd ${DIRNAME}/local
97 echo "installing openvim at ${DIRNAME}/openvim ... "
tiernoaa5832d2016-12-07 16:20:25 +010098 wget -O install-openvim.sh "https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=blob_plain;f=scripts/install-openvim.sh"
99 chmod +x install-openvim.sh
100 sudo ./install-openvim.sh --no-install-packages --force --quiet --develop
tiernoa6003ee2016-12-21 16:18:00 +0100101 export alias initopenvim="${PWD}/openvim/scripts/initopenvim.sh"
102 export alias openvim="${PWD}/openvim/scripts/openvim"
103 option_init_openvim=""
104 ${DIRNAME}/local/openvim/scripts/initopenvim.sh${force_param}${insert_bashrc_param}${screen_vim_param} || echo "WARNING openvim cannot be initialized. The rest of test can fail!"
105
tiernoaa5832d2016-12-07 16:20:25 +0100106 popd
107fi
tierno76841842016-09-27 09:18:28 +0000108[[ -z "$option_init_openvim" ]] || initopenvim${force_param}${insert_bashrc_param}${screen_vim_param} || echo "WARNING openvim cannot be initialized. The rest of test can fail!"
tierno96d9cd42016-07-13 12:28:19 +0200109
tierno72f35a52016-07-15 13:18:30 +0200110#check openvim client variables are set
111#fail=""
112#[[ -z $OPENVIM_HOST ]] && echo "OPENVIM_HOST variable not defined" >&2 && fail=1
113#[[ -z $OPENVIM_PORT ]] && echo "OPENVIM_PORT variable not defined" >&2 && fail=1
114#[[ -n $fail ]] && $_exit 1
115
116
tierno96d9cd42016-07-13 12:28:19 +0200117for action in $action_list
118do
119#if [[ $action == "install-openvim" ]]
120 #echo "Installing and starting openvim"
121 #mkdir -p temp
122 #pushd temp
123 #wget https://github.com/nfvlabs/openvim/raw/v0.4/scripts/install-openvim.sh
124 #chmod -x install-openvim.sh
125#fi
126
127if [[ $action == "reset" ]]
128then
129
130 #ask for confirmation if argument is not -f --force
tierno72f35a52016-07-15 13:18:30 +0200131 force_=y
tierno76841842016-09-27 09:18:28 +0000132 [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
tierno96d9cd42016-07-13 12:28:19 +0200133 [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
134
135 echo "Stopping openmano"
tierno76841842016-09-27 09:18:28 +0000136 $DIRscript/service-openmano.sh mano stop${screen_mano_param}
tierno96d9cd42016-07-13 12:28:19 +0200137 echo "Initializing openmano database"
garciadeblas0c317ee2016-08-29 12:33:06 +0200138 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw --createdb
tierno96d9cd42016-07-13 12:28:19 +0200139 echo "Starting openmano"
tierno76841842016-09-27 09:18:28 +0000140 $DIRscript/service-openmano.sh mano start${screen_mano_param}
tierno96d9cd42016-07-13 12:28:19 +0200141 echo
142
143elif [[ $action == "delete" ]]
144then
145 result=`openmano tenant-list TEST-tenant`
146 nfvotenant=`echo $result |gawk '{print $1}'`
147 #check a valid uuid is obtained
148 is_valid_uuid $nfvotenant || ! echo "Tenant TEST-tenant not found. Already delete?" >&2 || $_exit 1
149 export OPENMANO_TENANT=$nfvotenant
150 ${DIRmano}/openmano instance-scenario-delete -f simple-instance || echo "fail"
151 ${DIRmano}/openmano instance-scenario-delete -f complex-instance || echo "fail"
152 ${DIRmano}/openmano instance-scenario-delete -f complex2-instance || echo "fail"
garciadeblas6460dfa2016-09-07 12:31:41 +0200153 ${DIRmano}/openmano instance-scenario-delete -f complex3-instance || echo "fail"
154 ${DIRmano}/openmano instance-scenario-delete -f complex4-instance || echo "fail"
garciadeblas9f8456e2016-09-05 05:02:59 +0200155 ${DIRmano}/openmano scenario-delete -f simple || echo "fail"
156 ${DIRmano}/openmano scenario-delete -f complex || echo "fail"
157 ${DIRmano}/openmano scenario-delete -f complex2 || echo "fail"
158 ${DIRmano}/openmano scenario-delete -f complex3 || echo "fail"
159 ${DIRmano}/openmano scenario-delete -f complex4 || echo "fail"
160 ${DIRmano}/openmano vnf-delete -f linux || echo "fail"
161 ${DIRmano}/openmano vnf-delete -f linux_2VMs_v02 || echo "fail"
162 ${DIRmano}/openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
163 ${DIRmano}/openmano vnf-delete -f dataplaneVNF_2VMs_v02 || echo "fail"
garciadeblas9a241aa2016-09-30 12:25:59 +0200164 ${DIRmano}/openmano vnf-delete -f dataplaneVNF4 || echo "fail"
garciadeblas9f8456e2016-09-05 05:02:59 +0200165 ${DIRmano}/openmano vnf-delete -f dataplaneVNF2 || echo "fail"
166 ${DIRmano}/openmano vnf-delete -f dataplaneVNF3 || echo "fail"
167 ${DIRmano}/openmano datacenter-detach TEST-dc || echo "fail"
168 ${DIRmano}/openmano datacenter-delete -f TEST-dc || echo "fail"
169 ${DIRmano}/openmano tenant-delete -f TEST-tenant || echo "fail"
tierno96d9cd42016-07-13 12:28:19 +0200170 echo
171
172elif [[ $action == "create" ]]
173then
174 printf "%-50s" "Creating openmano tenant 'TEST-tenant': "
175 result=`${DIRmano}/openmano tenant-create TEST-tenant --description="created by basictest.sh"`
176 nfvotenant=`echo $result |gawk '{print $1}'`
177 #check a valid uuid is obtained
178 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
179 export OPENMANO_TENANT=$nfvotenant
tierno76841842016-09-27 09:18:28 +0000180 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200181 echo $nfvotenant
182
183 printf "%-50s" "Creating datacenter 'TEST-dc' in openmano:"
184 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
185 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
186 URL_ADMIN_PARAM=""
tierno8008c3a2016-10-13 15:34:28 +0000187 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
188 result=`${DIRmano}/openmano datacenter-create TEST-dc "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" --type=openvim${URL_ADMIN_PARAM} --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200189 datacenter=`echo $result |gawk '{print $1}'`
190 #check a valid uuid is obtained
191 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
192 echo $datacenter
193 export OPENMANO_DATACENTER=$datacenter
tierno76841842016-09-27 09:18:28 +0000194 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200195
196 printf "%-50s" "Attaching openmano tenant to the datacenter:"
tierno8008c3a2016-10-13 15:34:28 +0000197 result=`${DIRmano}/openmano datacenter-attach TEST-dc --config="{test: no use just for test}"`
tierno96d9cd42016-07-13 12:28:19 +0200198 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
199 echo OK
200
201 printf "%-50s" "Updating external nets in openmano: "
202 result=`${DIRmano}/openmano datacenter-netmap-delete -f --all`
203 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
tierno5acf7202016-08-29 14:28:13 +0200204 result=`${DIRmano}/openmano datacenter-netmap-import -f`
tierno96d9cd42016-07-13 12:28:19 +0200205 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
206 echo OK
207
garciadeblas9a241aa2016-09-30 12:25:59 +0200208 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
tierno96d9cd42016-07-13 12:28:19 +0200209 do
210 printf "%-50s" "Creating VNF '${VNF}': "
211 result=`$DIRmano/openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
212 vnf=`echo $result |gawk '{print $1}'`
213 #check a valid uuid is obtained
214 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
215 echo $vnf
216 done
garciadeblasa4bb7ac2016-10-03 20:13:29 +0200217 for NS in simple complex complex2 complex3 complex4
tierno96d9cd42016-07-13 12:28:19 +0200218 do
219 printf "%-50s" "Creating scenario '${NS}':"
220 result=`$DIRmano/openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
221 scenario=`echo $result |gawk '{print $1}'`
222 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
223 echo $scenario
224 done
225
garciadeblasa4bb7ac2016-10-03 20:13:29 +0200226 for IS in simple complex complex2 complex3
tierno96d9cd42016-07-13 12:28:19 +0200227 do
228 printf "%-50s" "Creating instance-scenario '${IS}':"
229 result=`$DIRmano/openmano instance-scenario-create --scenario ${IS} --name ${IS}-instance`
230 instance=`echo $result |gawk '{print $1}'`
231 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
232 echo $instance
233 done
234
garciadeblas9f8456e2016-09-05 05:02:59 +0200235 printf "%-50s" "Creating instance-scenario 'complex4':"
236 result=`$DIRmano/openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
237 instance=`echo $result |gawk '{print $1}'`
238 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
239 echo $instance
240
tierno96d9cd42016-07-13 12:28:19 +0200241 echo
242 #echo "Check virtual machines are deployed"
243 #vms_error=`openvim vm-list | grep ERROR | wc -l`
244 #vms=`openvim vm-list | wc -l`
245 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
246 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
247fi
248done
249
250echo
251echo DONE
252
253