4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
24 #This script can be used as a basic test of openmano.
25 #WARNING: It destroy the database content
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"
31 echo -e " by default localhost:9080"
32 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"
37 echo -e " -f --force does not prompt for confirmation"
38 echo -e " -h --help shows this help"
39 echo -e " --screen forces to run openmano (and openvim) service in a screen"
40 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
41 echo -e " ~/.bashrc to be available by openmano CLI"
42 echo -e " --install-openvim install openvim in test mode"
43 echo -e " --init-openvim if openvim runs locally, an init is called to clean openvim"
44 echo -e " database and add fake hosts"
47 function is_valid_uuid
(){
48 echo "$1" |
grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
52 #detect if is called with a source to use the 'exit'/'return' command for exiting
53 DIRNAME
=$
(dirname $
(readlink
-f ${BASH_SOURCE[0]}))
54 DIRmano
=$
(dirname $DIRNAME)
55 DIRscript
=${DIRmano}/scripts
57 [[ ${BASH_SOURCE[0]} != $0 ]] && _exit
="return" || _exit
="exit"
61 source ${DIRscript}/get-options.sh
"force:f help:h insert-bashrc init-openvim install-openvim screen" $
* ||
$_exit 1
64 [ -n "$option_help" ] && usage
&& $_exit 0
66 #check correct arguments
67 force_param
="" && [[ -n "$option_force" ]] && force_param
=" -f"
68 insert_bashrc_param
="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param
=" --insert-bashrc"
69 screen_mano_param
="" && [[ -n "$option_screen" ]] && screen_mano_param
=" --screen-name=mano"
70 screen_vim_param
="" && [[ -n "$option_screen" ]] && screen_vim_param
=" --screen-name=vim"
74 for argument
in $params
76 if [[ $argument == reset ]] ||
[[ $argument == create
]] ||
[[ $argument == delete
]] ||
[[ -z "$argument" ]]
78 action_list
="$action_list $argument"
81 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
84 export OPENMANO_HOST
=localhost
85 export OPENMANO_PORT
=9090
86 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~
/.bashrc
87 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~
/.bashrc
90 #by default action should be reset and create
91 [[ -z $action_list ]] && action_list
="reset create delete"
93 if [[ -n "$option_install_openvim" ]]
95 mkdir
-p ${DIRNAME}/local
96 pushd ${DIRNAME}/local
97 echo "installing openvim at ${DIRNAME}/openvim ... "
98 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
101 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!"
108 [[ -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!"
110 #check openvim client variables are set
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
117 for action
in $action_list
119 #if [[ $action == "install-openvim" ]]
120 #echo "Installing and starting openvim"
123 #wget https://github.com/nfvlabs/openvim/raw/v0.4/scripts/install-openvim.sh
124 #chmod -x install-openvim.sh
127 if [[ $action == "reset" ]]
130 #ask for confirmation if argument is not -f --force
132 [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
133 [[ $force_ != y
]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
135 echo "Stopping openmano"
136 $DIRscript/service-openmano.sh mano stop
${screen_mano_param}
137 echo "Initializing openmano database"
138 $DIRmano/database_utils
/init_mano_db.sh
-u mano
-p manopw
--createdb
139 echo "Starting openmano"
140 $DIRscript/service-openmano.sh mano start
${screen_mano_param}
143 elif [[ $action == "delete" ]]
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"
153 ${DIRmano}/openmano instance-scenario-delete
-f complex3-instance ||
echo "fail"
154 ${DIRmano}/openmano instance-scenario-delete
-f complex4-instance ||
echo "fail"
155 ${DIRmano}/openmano instance-scenario-delete
-f complex5-instance ||
echo "fail"
156 ${DIRmano}/openmano scenario-delete
-f simple ||
echo "fail"
157 ${DIRmano}/openmano scenario-delete
-f complex ||
echo "fail"
158 ${DIRmano}/openmano scenario-delete
-f complex2 ||
echo "fail"
159 ${DIRmano}/openmano scenario-delete
-f complex3 ||
echo "fail"
160 ${DIRmano}/openmano scenario-delete
-f complex4 ||
echo "fail"
161 ${DIRmano}/openmano scenario-delete
-f complex5 ||
echo "fail"
162 ${DIRmano}/openmano vnf-delete
-f linux ||
echo "fail"
163 ${DIRmano}/openmano vnf-delete
-f linux_2VMs_v02 ||
echo "fail"
164 ${DIRmano}/openmano vnf-delete
-f dataplaneVNF_2VMs ||
echo "fail"
165 ${DIRmano}/openmano vnf-delete
-f dataplaneVNF_2VMs_v02 ||
echo "fail"
166 ${DIRmano}/openmano vnf-delete
-f dataplaneVNF4 ||
echo "fail"
167 ${DIRmano}/openmano vnf-delete
-f dataplaneVNF2 ||
echo "fail"
168 ${DIRmano}/openmano vnf-delete
-f dataplaneVNF3 ||
echo "fail"
169 ${DIRmano}/openmano datacenter-detach TEST-dc ||
echo "fail"
170 ${DIRmano}/openmano datacenter-delete
-f TEST-dc ||
echo "fail"
171 ${DIRmano}/openmano tenant-delete
-f TEST-tenant ||
echo "fail"
174 elif [[ $action == "create" ]]
176 printf "%-50s" "Creating openmano tenant 'TEST-tenant': "
177 result
=`${DIRmano}/openmano tenant-create TEST-tenant --description="created by basictest.sh"`
178 nfvotenant
=`echo $result |gawk '{print $1}'`
179 #check a valid uuid is obtained
180 ! is_valid_uuid
$nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
181 export OPENMANO_TENANT
=$nfvotenant
182 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~
/.bashrc
185 printf "%-50s" "Creating datacenter 'TEST-dc' in openmano:"
186 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST
=localhost
187 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT
=9080
189 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM
=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
190 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}"`
191 datacenter
=`echo $result |gawk '{print $1}'`
192 #check a valid uuid is obtained
193 ! is_valid_uuid
$datacenter && echo "FAIL" && echo " $result" && $_exit 1
195 export OPENMANO_DATACENTER
=$datacenter
196 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~
/.bashrc
198 printf "%-50s" "Attaching openmano tenant to the datacenter:"
199 result
=`${DIRmano}/openmano datacenter-attach TEST-dc --config="{test: no use just for test}"`
200 [[ $?
!= 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
203 printf "%-50s" "Updating external nets in openmano: "
204 result
=`${DIRmano}/openmano datacenter-netmap-delete -f --all`
205 [[ $?
!= 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
206 result
=`${DIRmano}/openmano datacenter-netmap-import -f`
207 [[ $?
!= 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
210 for VNF
in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
212 printf "%-50s" "Creating VNF '${VNF}': "
213 result
=`$DIRmano/openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
214 vnf
=`echo $result |gawk '{print $1}'`
215 #check a valid uuid is obtained
216 ! is_valid_uuid
$vnf && echo FAIL
&& echo " $result" && $_exit 1
219 for NS
in simple complex complex2 complex3 complex4 complex5
221 printf "%-50s" "Creating scenario '${NS}':"
222 result
=`$DIRmano/openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
223 scenario
=`echo $result |gawk '{print $1}'`
224 ! is_valid_uuid
$scenario && echo FAIL
&& echo " $result" && $_exit 1
228 for IS
in simple complex complex2 complex3 complex5
230 printf "%-50s" "Creating instance-scenario '${IS}':"
231 result
=`$DIRmano/openmano instance-scenario-create --scenario ${IS} --name ${IS}-instance`
232 instance
=`echo $result |gawk '{print $1}'`
233 ! is_valid_uuid
$instance && echo FAIL
&& echo " $result" && $_exit 1
237 printf "%-50s" "Creating instance-scenario 'complex4':"
238 result
=`$DIRmano/openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
239 instance
=`echo $result |gawk '{print $1}'`
240 ! is_valid_uuid
$instance && echo FAIL
&& echo " $result" && $_exit 1
244 #echo "Check virtual machines are deployed"
245 #vms_error=`openvim vm-list | grep ERROR | wc -l`
246 #vms=`openvim vm-list | wc -l`
247 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
248 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1