basictest changed to remove nsd complex5. It requires a pre-provisioned image at...
[osm/RO.git] / test / basictest.sh
1 #!/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
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 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"
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 " --init-openvim if openvim runs locally, an init is called to clean openvim"
43 echo -e " database and add fake hosts"
44 }
45
46 function is_valid_uuid(){
47 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
48 return 1
49 }
50
51 #detect if is called with a source to use the 'exit'/'return' command for exiting
52 DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
53 DIRmano=$(dirname $DIRNAME)
54 DIRscript=${DIRmano}/scripts
55
56 [[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
57
58
59 #process options
60 source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim screen" $* || $_exit 1
61
62 #help
63 [ -n "$option_help" ] && usage && $_exit 0
64
65 #check correct arguments
66 force_param="" && [[ -n "$option_force" ]] && force_param=" -f"
67 insert_bashrc_param="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param=" --insert-bashrc"
68 screen_mano_param="" && [[ -n "$option_screen" ]] && screen_mano_param=" --screen-name=mano"
69 screen_vim_param="" && [[ -n "$option_screen" ]] && screen_vim_param=" --screen-name=vim"
70
71 action_list=""
72
73 for argument in $params
74 do
75 if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]]
76 then
77 action_list="$action_list $argument"
78 continue
79 fi
80 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
81 done
82
83 export OPENMANO_HOST=localhost
84 export OPENMANO_PORT=9090
85 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc
86 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc
87
88
89 #by default action should be reset and create
90 [[ -z $action_list ]] && action_list="reset create delete"
91 [[ -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!"
92
93 #check openvim client variables are set
94 #fail=""
95 #[[ -z $OPENVIM_HOST ]] && echo "OPENVIM_HOST variable not defined" >&2 && fail=1
96 #[[ -z $OPENVIM_PORT ]] && echo "OPENVIM_PORT variable not defined" >&2 && fail=1
97 #[[ -n $fail ]] && $_exit 1
98
99
100 for action in $action_list
101 do
102 #if [[ $action == "install-openvim" ]]
103 #echo "Installing and starting openvim"
104 #mkdir -p temp
105 #pushd temp
106 #wget https://github.com/nfvlabs/openvim/raw/v0.4/scripts/install-openvim.sh
107 #chmod -x install-openvim.sh
108 #fi
109
110 if [[ $action == "reset" ]]
111 then
112
113 #ask for confirmation if argument is not -f --force
114 force_=y
115 [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
116 [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
117
118 echo "Stopping openmano"
119 $DIRscript/service-openmano.sh mano stop${screen_mano_param}
120 echo "Initializing openmano database"
121 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw --createdb
122 echo "Starting openmano"
123 $DIRscript/service-openmano.sh mano start${screen_mano_param}
124 echo
125
126 elif [[ $action == "delete" ]]
127 then
128 result=`openmano tenant-list TEST-tenant`
129 nfvotenant=`echo $result |gawk '{print $1}'`
130 #check a valid uuid is obtained
131 is_valid_uuid $nfvotenant || ! echo "Tenant TEST-tenant not found. Already delete?" >&2 || $_exit 1
132 export OPENMANO_TENANT=$nfvotenant
133 ${DIRmano}/openmano instance-scenario-delete -f simple-instance || echo "fail"
134 ${DIRmano}/openmano instance-scenario-delete -f complex-instance || echo "fail"
135 ${DIRmano}/openmano instance-scenario-delete -f complex2-instance || echo "fail"
136 ${DIRmano}/openmano instance-scenario-delete -f complex3-instance || echo "fail"
137 ${DIRmano}/openmano instance-scenario-delete -f complex4-instance || echo "fail"
138 ${DIRmano}/openmano scenario-delete -f simple || echo "fail"
139 ${DIRmano}/openmano scenario-delete -f complex || echo "fail"
140 ${DIRmano}/openmano scenario-delete -f complex2 || echo "fail"
141 ${DIRmano}/openmano scenario-delete -f complex3 || echo "fail"
142 ${DIRmano}/openmano scenario-delete -f complex4 || echo "fail"
143 ${DIRmano}/openmano vnf-delete -f linux || echo "fail"
144 ${DIRmano}/openmano vnf-delete -f linux_2VMs_v02 || echo "fail"
145 ${DIRmano}/openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
146 ${DIRmano}/openmano vnf-delete -f dataplaneVNF_2VMs_v02 || echo "fail"
147 ${DIRmano}/openmano vnf-delete -f dataplaneVNF4 || echo "fail"
148 ${DIRmano}/openmano vnf-delete -f dataplaneVNF2 || echo "fail"
149 ${DIRmano}/openmano vnf-delete -f dataplaneVNF3 || echo "fail"
150 ${DIRmano}/openmano datacenter-detach TEST-dc || echo "fail"
151 ${DIRmano}/openmano datacenter-delete -f TEST-dc || echo "fail"
152 ${DIRmano}/openmano tenant-delete -f TEST-tenant || echo "fail"
153 echo
154
155 elif [[ $action == "create" ]]
156 then
157 printf "%-50s" "Creating openmano tenant 'TEST-tenant': "
158 result=`${DIRmano}/openmano tenant-create TEST-tenant --description="created by basictest.sh"`
159 nfvotenant=`echo $result |gawk '{print $1}'`
160 #check a valid uuid is obtained
161 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
162 export OPENMANO_TENANT=$nfvotenant
163 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~/.bashrc
164 echo $nfvotenant
165
166 printf "%-50s" "Creating datacenter 'TEST-dc' in openmano:"
167 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
168 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
169 URL_ADMIN_PARAM=""
170 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM="--url_admin=http://${$OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
171 result=`${DIRmano}/openmano datacenter-create TEST-dc "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" --type=openvim $URL_ADMIN_PARAM`
172 datacenter=`echo $result |gawk '{print $1}'`
173 #check a valid uuid is obtained
174 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
175 echo $datacenter
176 export OPENMANO_DATACENTER=$datacenter
177 [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc
178
179 printf "%-50s" "Attaching openmano tenant to the datacenter:"
180 result=`${DIRmano}/openmano datacenter-attach TEST-dc`
181 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
182 echo OK
183
184 printf "%-50s" "Updating external nets in openmano: "
185 result=`${DIRmano}/openmano datacenter-netmap-delete -f --all`
186 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
187 result=`${DIRmano}/openmano datacenter-netmap-import -f`
188 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
189 echo OK
190
191 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF_2VMs_v02 dataplaneVNF3 linux_2VMs_v02 dataplaneVNF4
192 do
193 printf "%-50s" "Creating VNF '${VNF}': "
194 result=`$DIRmano/openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
195 vnf=`echo $result |gawk '{print $1}'`
196 #check a valid uuid is obtained
197 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
198 echo $vnf
199 done
200 for NS in simple complex complex2 complex3 complex4
201 do
202 printf "%-50s" "Creating scenario '${NS}':"
203 result=`$DIRmano/openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
204 scenario=`echo $result |gawk '{print $1}'`
205 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
206 echo $scenario
207 done
208
209 for IS in simple complex complex2 complex3
210 do
211 printf "%-50s" "Creating instance-scenario '${IS}':"
212 result=`$DIRmano/openmano instance-scenario-create --scenario ${IS} --name ${IS}-instance`
213 instance=`echo $result |gawk '{print $1}'`
214 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
215 echo $instance
216 done
217
218 printf "%-50s" "Creating instance-scenario 'complex4':"
219 result=`$DIRmano/openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml`
220 instance=`echo $result |gawk '{print $1}'`
221 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
222 echo $instance
223
224 echo
225 #echo "Check virtual machines are deployed"
226 #vms_error=`openvim vm-list | grep ERROR | wc -l`
227 #vms=`openvim vm-list | wc -l`
228 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
229 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
230 fi
231 done
232
233 echo
234 echo DONE
235
236