Changes in vimconn_vmware.py :
[osm/RO.git] / test / test_vimconn.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 deployment over a vim
25 #in order to use you need to set the VIM_XXXX bash variables with a vim values
26 # VIM_TYPE openstack or openvim
27 # VIM_USERNAME e.g.: admin
28 # VIM_PASSWORD
29 # VIM_AUTH_URL url to access VIM e.g. http:/openstack:35357/v2.0
30 # VIM_AUTH_URL_ADMIN admin url
31 # VIM_TENANT_NAME e.g.: admin
32 # VIM_CONFIG e.g.: "'network_vlan_ranges: sriov_net'"
33 # VIM_TEST_IMAGE_PATH_LINUX image path(location) to use by the VNF linux
34 # VIM_TEST_IMAGE_PATH_NFV image path(location) to use by the VNF dataplaneVNF_2VMs and dataplaneVNF3
35
36 #it should be used with source. It can modifies /home/$USER/.bashrc appending the variables
37 #you need to delete them manually if desired
38
39 function usage(){
40 echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] <action>\n test VIM managing from openmano"
41 echo -e " <action> is a list of the following items (by default 'reset create')"
42 echo -e " reset reset the openmano database content"
43 echo -e " create creates items at VIM"
44 echo -e " delete delete created items"
45 echo -e " OPTIONS:"
46 echo -e " -f --force does not prompt for confirmation"
47 echo -e " -h --help shows this help"
48 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
49 echo -e " ~/.bashrc to be available by openmano config"
50 }
51
52 function is_valid_uuid(){
53 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
54 echo "$1" | grep -q -E '^[0-9a-f]{32}$' && return 0
55 return 1
56 }
57
58 #detect if is called with a source to use the 'exit'/'return' command for exiting
59 [[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
60
61 #detect if environment variables are set
62 fail=""
63 [[ -z $VIM_TYPE ]] && echo "VIM_TYPE variable not defined" >&2 && fail=1
64 [[ -z $VIM_USERNAME ]] && echo "VIM_USERNAME variable not defined" >&2 && fail=1
65 [[ -z $VIM_PASSWORD ]] && echo "VIM_PASSWORD variable not defined" >&2 && fail=1
66 [[ -z $VIM_AUTH_URL ]] && echo "VIM_AUTH_URL variable not defined" >&2 && fail=1
67 [[ -z $VIM_TENANT_NAME ]] && [[ -z $VIM_TENANT_NAME ]] && echo "neither VIM_TENANT_NAME not VIM_TENANT_ID variables are not defined" >&2 && fail=1
68 [[ -z $VIM_CONFIG ]] && echo "VIM_CONFIG variable not defined" >&2 && fail=1
69 [[ -z $VIM_TEST_IMAGE_PATH_LINUX ]] && echo "VIM_TEST_IMAGE_PATH_LINUX variable not defined" >&2 && fail=1
70 [[ -z $VIM_TEST_IMAGE_PATH_NFV ]] && echo "VIM_TEST_IMAGE_PATH_NFV variable not defined" >&2 && fail=1
71 [[ -n $fail ]] && $_exit 1
72
73 #check correct arguments
74 action_list=""
75 for param in $*
76 do
77 if [[ $param == reset ]] || [[ $param == create ]] || [[ $param == delete ]]
78 then
79 action_list="$action_list $param"
80 elif [[ $param == -h ]] || [[ $param == --help ]]
81 then
82 usage
83 $_exit 0
84 elif [[ $param == -f ]] || [[ $param == --force ]]
85 then
86 force=y
87 elif [[ $param == --insert-bashrc ]]
88 then
89 insert_bashrc=y
90 else
91 echo "invalid argument '$param'?" && usage >&2 && $_exit 1
92 fi
93 done
94
95 DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
96 DIRmano=$(dirname $DIRNAME)
97 DIRscript=${DIRmano}/scripts
98 #by default action should be reset and create
99 [[ -z $action_list ]] && action_list="reset create"
100
101 for action in $action_list
102 do
103 if [[ $action == "reset" ]]
104 then
105
106 #ask for confirmation if argument is not -f --force
107 [[ $force != y ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N)" force
108 [[ $force != y ]] && [[ $force != yes ]] && echo "aborted!" && $_exit
109
110 echo "Stopping openmano"
111 $DIRscript/service-openmano.sh mano stop
112 echo "Initializing openmano database"
113 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw --createdb
114 echo "Starting openmano"
115 $DIRscript/service-openmano.sh mano start
116
117 elif [[ $action == "delete" ]]
118 then
119 result=`openmano tenant-list TESTVIM-tenant`
120 nfvotenant=`echo $result |gawk '{print $1}'`
121 #check a valid uuid is obtained
122 is_valid_uuid $nfvotenant || ! echo "Tenant TESTVIM-tenant not found. Already delete?" >&2 || $_exit 1
123 export OPENMANO_TENANT=$nfvotenant
124 openmano instance-scenario-delete -f simple-instance || echo "fail"
125 openmano instance-scenario-delete -f complex2-instance || echo "fail"
126 openmano instance-scenario-delete -f complex4-instance || echo "fail"
127 openmano scenario-delete -f simple || echo "fail"
128 openmano scenario-delete -f complex2 || echo "fail"
129 openmano scenario-delete -f complex3 || echo "fail"
130 openmano scenario-delete -f complex4 || echo "fail"
131 openmano vnf-delete -f linux || echo "fail"
132 openmano vnf-delete -f linux_2VMs_v02 || echo "fail"
133 openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
134 openmano vnf-delete -f dataplaneVNF3 || echo "fail"
135 openmano vnf-delete -f TESTVIM-VNF1 || echo "fail"
136 openmano datacenter-detach TESTVIM-dc || echo "fail"
137 openmano datacenter-delete -f TESTVIM-dc || echo "fail"
138 openmano tenant-delete -f TESTVIM-tenant || echo "fail"
139
140 elif [[ $action == "create" ]]
141 then
142
143 printf "%-50s" "Creating openmano tenant 'TESTVIM-tenant': "
144 result=`openmano tenant-create TESTVIM-tenant --description="created by test_vimconn.sh"`
145 nfvotenant=`echo $result |gawk '{print $1}'`
146 #check a valid uuid is obtained
147 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
148 export OPENMANO_TENANT=$nfvotenant
149 [[ $insert_bashrc == y ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~/.bashrc
150 echo $nfvotenant
151
152 printf "%-50s" "Creating datacenter 'TESTVIM-dc' in openmano:"
153 URL_ADMIN_PARAM=""
154 [[ -n $VIM_AUTH_URL_ADMIN ]] && URL_ADMIN_PARAM="--url_admin=$VIM_AUTH_URL_ADMIN"
155 result=`openmano datacenter-create TESTVIM-dc "${VIM_AUTH_URL}" "--type=$VIM_TYPE" $URL_ADMIN_PARAM "--config=${VIM_CONFIG}"`
156 datacenter=`echo $result |gawk '{print $1}'`
157 #check a valid uuid is obtained
158 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
159 echo $datacenter
160 export OPENMANO_DATACENTER=$datacenter
161 [[ $insert_bashrc == y ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc
162
163 printf "%-50s" "Attaching openmano tenant to the datacenter:"
164 [[ -n $VIM_PASSWORD ]] && passwd_param="--password=$VIM_PASSWORD" || passwd_param=""
165 [[ -n $VIM_TENANT_NAME ]] && vim_tenant_name_param="--vim-tenant-name=$VIM_TENANT_NAME" || vim_tenant_name_param=""
166 [[ -n $VIM_TENANT_ID ]] && vim_tenant_id_param="--vim-tenant-id=$VIM_TENANT_ID" || vim_tenant_id_param=""
167 [[ -n $VIM_PASSWORD ]] && passwd_param="--password=$VIM_PASSWORD" || passwd_param=""
168 result=`openmano datacenter-attach TESTVIM-dc "--user=$VIM_USERNAME" "$passwd_param" "$vim_tenant_name_param"`
169 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
170 echo OK
171
172 printf "%-50s" "Updating external nets in openmano: "
173 result=`openmano datacenter-netmap-delete -f --all`
174 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
175 result=`openmano datacenter-netmap-import -f`
176 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
177 echo OK
178
179 printf "%-50s" "Creating VNF 'linux': "
180 #glance image-create --file=./US1404dpdk.qcow2 --name=US1404dpdk --disk-format=qcow2 --min-disk=2 --is-public=True --container-format=bare
181 #nova image-meta US1404dpdk set location=/mnt/powervault/virtualization/vnfs/os/US1404dpdk.qcow2
182 #glance image-create --file=./US1404user.qcow2 --min-disk=2 --is-public=True --container-format=bare --name=US1404user --disk-format=qcow2
183 #nova image-meta US1404user set location=/mnt/powervault/virtualization/vnfs/os/US1404user.qcow2
184 result=`openmano vnf-create $DIRmano/vnfs/examples/linux.yaml "--image-path=$VIM_TEST_IMAGE_PATH_LINUX"`
185 vnf=`echo $result |gawk '{print $1}'`
186 #check a valid uuid is obtained
187 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
188 echo $vnf
189
190 printf "%-50s" "Creating VNF 1PF,1VF,2GB,4PThreads: "
191 result=`openmano vnf-create "vnf:
192 name: TESTVIM-VNF1
193 external-connections:
194 - name: eth0
195 type: mgmt
196 VNFC: TESTVIM-VNF1-VM
197 local_iface_name: eth0
198 - name: PF0
199 type: data
200 VNFC: TESTVIM-VNF1-VM
201 local_iface_name: PF0
202 - name: VF0
203 type: data
204 VNFC: TESTVIM-VNF1-VM
205 local_iface_name: VF0
206 VNFC:
207 - name: TESTVIM-VNF1-VM
208 VNFC image: $VIM_TEST_IMAGE_PATH_NFV
209 numas:
210 - paired-threads: 2
211 paired-threads-id: [ [0,2], [1,3] ]
212 memory: 2
213 interfaces:
214 - name: PF0
215 vpci: '0000:00:11.0'
216 dedicated: 'yes'
217 bandwidth: 10 Gbps
218 mac_address: '20:33:45:56:77:44'
219 - name: VF0
220 vpci: '0000:00:12.0'
221 dedicated: 'no'
222 bandwidth: 1 Gbps
223 mac_address: '20:33:45:56:77:45'
224 bridge-ifaces:
225 - name: eth0
226 vpci: '0000:00:09.0'
227 bandwidth: 1 Mbps
228 mac_address: '20:33:45:56:77:46'
229 model: e1000
230 "`
231 vnf=`echo $result |gawk '{print $1}'`
232 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
233 echo $vnf
234
235 printf "%-50s" "Creating VNF 'dataplaneVNF_2VMs': "
236 result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF_2VMs.yaml "--image-path=$VIM_TEST_IMAGE_PATH_NFV,$VIM_TEST_IMAGE_PATH_NFV"`
237 vnf=`echo $result |gawk '{print $1}'`
238 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
239 echo $vnf
240
241 printf "%-50s" "Creating VNF 'dataplaneVNF3.yaml': "
242 result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF3.yaml "--image-path=$VIM_TEST_IMAGE_PATH_NFV"`
243 vnf=`echo $result |gawk '{print $1}'`
244 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
245 echo $vnf
246
247 printf "%-50s" "Creating VNF 'dataplaneVNF_2VMs_v02': "
248 result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF_2VMs_v02.yaml "--image-path=$VIM_TEST_IMAGE_PATH_NFV,$VIM_TEST_IMAGE_PATH_NFV"`
249 vnf=`echo $result |gawk '{print $1}'`
250 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
251 echo $vnf
252
253 printf "%-50s" "Creating VNF 'linux_2VMs_v02': "
254 result=`openmano vnf-create $DIRmano/vnfs/examples/linux_2VMs_v02.yaml "--image-path=$VIM_TEST_IMAGE_PATH_NFV,$VIM_TEST_IMAGE_PATH_NFV"`
255 vnf=`echo $result |gawk '{print $1}'`
256 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
257 echo $vnf
258
259 for sce in simple complex2 complex3 complex4
260 do
261 printf "%-50s" "Creating scenario '$sce':"
262 result=`openmano scenario-create $DIRmano/scenarios/examples/${sce}.yaml`
263 scenario=`echo $result |gawk '{print $1}'`
264 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
265 echo $scenario
266 done
267
268 #USER_KEY=""
269 key_param1=""
270 key_param2=""
271 #add user keys if present at .ssh
272 ls ${HOME}/.ssh/*.pub > /dev/null 2>&1 && key_param1=--keypair-auto
273
274 for sce in simple complex2
275 do
276 printf "%-50s" "Deploying scenario '$sce':"
277 result=`openmano instance-scenario-create --scenario $sce --name ${sce}-instance "$key_param1" "$key_param2"`
278 instance=`echo $result |gawk '{print $1}'`
279 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
280 echo $instance
281 done
282
283 #Testing IP parameters in networks
284 printf "%-50s" "Deploying scenario 'complex4' with IP parameters in networks:"
285 result=`openmano instance-scenario-create $DIRmano/instance-scenarios/examples/instance-creation-complex4.yaml "$key_param1" "$key_param2"`
286 instance=`echo $result |gawk '{print $1}'`
287 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
288 echo $instance
289
290 echo
291 echo DONE
292 fi
293 done
294