Fix 1475 - Incorrect description in instantiating error
[osm/RO.git] / RO / test / basictest.sh
1 #!/bin/bash
2
3 ##
4 # Copyright 2015 Telefonica Investigacion 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
28 function 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"
31 echo -e " by default localhost:9080"
32 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"
38 echo -e " delete-all deletes ALL the existing instances, scenarios and vnf at the current tenant"
39 echo -e " OPTIONS:"
40 echo -e " -f --force does not prompt for confirmation"
41 echo -e " -h --help shows this help"
42 echo -e " --screen forces to run openmano (and openvim) service in a screen"
43 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
44 echo -e " ~/.bashrc to be available by openmano CLI"
45 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"
48 }
49
50 function 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
56 DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
57 DIRmano=$(dirname $DIRNAME)
58 DIRscript=${DIRmano}/scripts
59
60 #detect paths of executables, preceding the relative paths
61 openmano=openmano && [[ -x "${DIRmano}/openmano" ]] && openmano="${DIRmano}/openmano"
62 service_openmano=service-openmano && [[ -x "$DIRscript/service-openmano" ]] &&
63 service_openmano="$DIRscript/service-openmano"
64 initopenvim="initopenvim"
65 openvim="openvim"
66
67 [[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
68
69
70 #process options
71 source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim:initopenvim install-openvim screen" \
72 $* || $_exit 1
73
74 #help
75 [ -n "$option_help" ] && usage && $_exit 0
76
77 #check correct arguments
78 force_param="" && [[ -n "$option_force" ]] && force_param=" -f"
79 insert_bashrc_param="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param=" --insert-bashrc"
80 screen_mano_param="" && [[ -n "$option_screen" ]] && screen_mano_param=" --screen-name=mano"
81 screen_vim_param="" && [[ -n "$option_screen" ]] && screen_vim_param=" --screen-name=vim"
82
83 action_list=""
84
85 for argument in $params
86 do
87 if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] ||
88 [[ $argument == add-openvim ]] || [[ $argument == del-openvim ]] || [[ $argument == delete-all ]] ||
89 [[ -z "$argument" ]]
90 then
91 action_list="$action_list $argument"
92 continue
93 fi
94 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
95 done
96
97 export OPENMANO_HOST=localhost
98 export OPENMANO_PORT=9090
99 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc
100 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc
101
102
103 #by default action should be reset and create
104 [[ -z $action_list ]] && action_list="reset add-openvim create delete del-openvim"
105
106 if [[ -n "$option_install_openvim" ]]
107 then
108 echo
109 echo "action: install openvim"
110 echo "################################"
111 mkdir -p ${DIRNAME}/local
112 pushd ${DIRNAME}/local
113 echo "installing openvim at ${DIRNAME}/openvim ... "
114 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
117 openvim="${DIRNAME}/local/openvim/openvim"
118 #force inito-penvim
119 option_init_openvim="-"
120 initopenvim="${DIRNAME}/local/openvim/scripts/initopenvim"
121 popd
122 fi
123
124 if [[ -n "$option_init_openvim" ]]
125 then
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!"
131 fi
132
133 #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
140 for action in $action_list
141 do
142 echo
143 echo "action: $action"
144 echo "################################"
145 #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
153 if [[ $action == "reset" ]]
154 then
155
156 #ask for confirmation if argument is not -f --force
157 force_=y
158 [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
159 [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
160
161 echo "Stopping openmano"
162 $service_openmano mano stop${screen_mano_param}
163 echo "Initializing openmano database"
164 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
165 echo "Starting openmano"
166 $service_openmano mano start${screen_mano_param}
167 echo
168 printf "%-50s" "Creating openmano tenant 'osm': "
169 result=`$openmano tenant-create osm --description="created by basictest.sh"`
170 nfvotenant=`echo $result |gawk '{print $1}'`
171 #check a valid uuid is obtained
172 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
173 export OPENMANO_TENANT=osm
174 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=osm" >> ~/.bashrc
175 echo $nfvotenant
176
177 elif [[ $action == "delete" ]]
178 then
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 instance-scenario-delete -f 3vdu_2vnf_nsd-instance || echo "fail"
191 $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"
197 $openmano scenario-delete -f osm_id=3vdu_2vnf_nsd || echo "fail"
198 $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"
202 $openmano vnf-delete -f dataplaneVNF1 || echo "fail"
203 $openmano vnf-delete -f dataplaneVNF2 || echo "fail"
204 $openmano vnf-delete -f dataplaneVNF3 || echo "fail"
205 $openmano vnf-delete -f dataplaneVNF4 || echo "fail"
206 $openmano vnf-delete -f osm_id=3vdu_vnfd || echo "fail"
207
208 elif [[ $action == "delete-all" ]]
209 then
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
217
218 elif [[ $action == "del-openvim" ]]
219 then
220 $openmano datacenter-detach local-openvim || echo "fail"
221 $openmano datacenter-delete -f local-openvim || echo "fail"
222
223 elif [[ $action == "add-openvim" ]]
224 then
225
226 printf "%-50s" "Creating datacenter 'local-openvim' at openmano:"
227 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
228 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
229 URL_ADMIN_PARAM=""
230 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
231 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}"`
233 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
237 export OPENMANO_DATACENTER=local-openvim
238 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=local-openvim" >> ~/.bashrc
239
240 printf "%-50s" "Attaching openmano tenant to the datacenter:"
241 result=`$openmano datacenter-attach local-openvim --vim-tenant-name=osm --config="{test: no use just for test}"`
242 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
243 echo OK
244
245 printf "%-50s" "Updating external nets in openmano: "
246 result=`$openmano datacenter-netmap-delete -f --all`
247 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
248 result=`$openmano datacenter-netmap-import -f`
249 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
250 echo OK
251 result=`$openmano datacenter-netmap-create --name=default --vim-name=mgmt`
252 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
253 echo OK
254
255 elif [[ $action == "create" ]]
256 then
257 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
258 do
259 printf "%-50s" "Creating VNF '${VNF}': "
260 result=`$openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
261 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
266
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
274 for NS in simple complex complex2 complex3 complex4 complex5 v3_3vdu_2vnf_nsd
275 do
276 printf "%-50s" "Creating scenario '${NS}':"
277 result=`$openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
278 scenario=`echo $result |gawk '{print $1}'`
279 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
280 echo $scenario
281 done
282
283 for IS in simple complex complex2 complex3 complex5 osm_id=3vdu_2vnf_nsd
284 do
285 printf "%-50s" "Creating instance-scenario '${IS}':"
286 result=`$openmano instance-scenario-create --scenario ${IS} --name ${IS#osm_id=}-instance`
287 instance=`echo $result |gawk '{print $1}'`
288 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
289 echo $instance
290 done
291
292 printf "%-50s" "Creating instance-scenario 'complex4':"
293 result=`$openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
294 instance=`echo $result |gawk '{print $1}'`
295 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
296 echo $instance
297
298 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
304 fi
305 done
306
307 echo
308 echo DONE
309
310