4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
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
25 #author Alfonso Tierno
27 #script to test openvim with the creation of flavors and interfaces, openflow rules
28 #using images already inserted
32 echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] \n test openvim "
34 echo -e " -f --force does not prompt for confirmation"
35 echo -e " -v --same-vlan use this if the parameter 'of_controller_nets_with_same_vlan'"
36 echo -e " is not false at openvimd.cfg to avoid test unrealizable openflow nets"
37 echo -e " -h --help shows this help"
38 echo -e " -c --create create management network and two images (valid for test mode)"
40 echo "This script test openvim, creating flavors, images, vms, de-attaching dataplane port"
41 echo "from one network to other and testing openflow generated rules."
42 echo "By default (unless -c option) uses and already created management network and two valid images."
43 echo "If -c option is set, it creates the network and images with fake content (only usefull for"
44 echo "openvim in 'test' mode) This is speccified in this shell variables:"
45 echo " VIM_TEST_NETWORK_INTERNET name of the mamagement network to use"
46 echo " VIM_TEST_IMAGE_PATH path of a vm image to use, the image is created if not exist"
47 echo " VIM_TEST_IMAGE_PATH_EXTRA path of another vm image to use, the image is created if not exist"
50 #detect if is called with a source to use the 'exit'/'return' command for exiting
51 [[ ${BASH_SOURCE[0]} != $0 ]] && echo "Do not execute this script as SOURCE" >&2 && return 1
53 #check correct arguments
59 if [[ $param == -h ]] ||
[[ $param == --help ]]
63 elif [[ $param == -v ]] ||
[[ $param == --same-vlan ]]
66 elif [[ $param == -f ]] ||
[[ $param == --force ]]
69 elif [[ $param == -c ]] ||
[[ $param == --create ]]
73 echo "invalid argument '$param'?" && usage
>&2 && exit 1
77 #detect if environment variables are set
79 [[ $create == n
]] && [[ -z $VIM_TEST_NETWORK_INTERNET ]] && echo "VIM_TEST_NETWORK_INTERNET not defined" >&2 && fail
=1
80 [[ $create == n
]] && [[ -z $VIM_TEST_IMAGE_PATH ]] && echo "VIM_TEST_IMAGE_PATH not defined" >&2 && fail
=1
81 [[ $create == n
]] && [[ -z $VIM_TEST_IMAGE_PATH_EXTRA ]] && echo "VIM_TEST_IMAGE_PATH_EXTRA not defined" >&2 && fail
=1
82 [[ -n $fail ]] && exit 1
84 [[ $create == y
]] && [[ -z $VIM_TEST_IMAGE_PATH ]] && VIM_TEST_IMAGE_PATH
="/test/path/of/image1"
85 [[ $create == y
]] && [[ -z $VIM_TEST_IMAGE_PATH_EXTRA ]] && VIM_TEST_IMAGE_PATH_EXTRA
="/test/path2/of/image2"
87 export _exit
=delete_and_exit
89 function delete_and_exit
(){
91 [[ $force != y
]] && read -e -p " Press enter to delete the deployed things " kk
95 openvim
${f%%:*}-delete ${f##*:} -f
101 function is_valid_uuid
(){
102 echo "$1" |
grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
106 function process_cmd
(){
107 # test the result of the previos command, if fails execute the $_exit command
109 # uuid <variable> <result...> : test that the first word of <result> is a valid uuid, stored it at <variable>. Print uuid
110 # fail <reason> <result...> : test that the previous command has failed. If not print the <reason> why it needs to fail
111 # ok <result...> : test that the previos command has not failed. Print OK
115 [[ $cmd_result == 0 ]] ||
! shift 2 ||
! echo "FAIL: $*" >&2 ||
$_exit 1
116 is_valid_uuid
$3 ||
! shift 2 ||
! echo "FAIL: $*" >&2 ||
$_exit 1
119 elif [[ $1 == fail
]]
121 [[ $cmd_result != "0" ]] ||
! echo "NOT FAIL: $2" >&2 ||
$_exit 1
125 [[ $cmd_result == 0 ]] ||
! shift 1 ||
! echo "FAIL: $*" >&2 ||
$_exit 1
131 function test_of_rules
(){
132 #test the number of rules of a network, wait until 10 seconds
135 do #it can take some seconds to get it ready
136 result
=`openvim openflow-net-list $1`
137 nb_rules
=`echo $result | grep actions -o | wc -l`
138 [[ $nb_rules == $2 ]] && echo "OK" && break
139 [[ $timeout_ == 0 ]] && echo "FAIL $result" >&2 && $_exit 1
141 timeout_
=$
((timeout_
- 1))
145 echo " Test VIM with 3 VM deployments. It delete the created items at the end"
147 [[ $force != y
]] && read -e -p "Press enter to continue, CTRL+C to abort " kk
150 printf "%-50s" "1 get ${VIM_TEST_IMAGE_PATH##*/} image: "
151 image1
=`openvim image-list -F"path=${VIM_TEST_IMAGE_PATH}" | gawk '{print $1}'`
152 if is_valid_uuid
$image1
158 printf "%-50s" " b create ${VIM_TEST_IMAGE_PATH##*/} image: "
159 result
=`openvim image-create --name=test-image1 --path=${VIM_TEST_IMAGE_PATH} --description=for-test`
160 process_cmd uuid image1
$result
161 TODELETE
="image:$image1 $TODELETE"
164 printf "%-50s" "2 get ${VIM_TEST_IMAGE_PATH_EXTRA##*/} image: "
165 image2
=`openvim image-list -F"path=${VIM_TEST_IMAGE_PATH_EXTRA}" | gawk '{print $1}'`
166 if is_valid_uuid
$image2
172 printf "%-50s" " b create ${VIM_TEST_IMAGE_PATH_EXTRA##*/} image: "
173 result
=`openvim image-create --name=test-image1 --path=${VIM_TEST_IMAGE_PATH_EXTRA} --description=for-test`
174 process_cmd uuid image2
$result
175 TODELETE
="image:$image2 $TODELETE"
178 if [[ $create == y
]]
180 printf "%-50s" "3 create management network: "
181 result
=`openvim net-create "name: test_mgmt_net
183 process_cmd uuid network_eth0
$result
184 TODELETE
="net:$network_eth0 $TODELETE"
186 printf "%-50s" "3 get ${VIM_TEST_NETWORK_INTERNET} network: "
187 result
=`openvim net-list -F"name=$VIM_TEST_NETWORK_INTERNET"`
188 process_cmd uuid network_eth0
$result
191 printf "%-50s" "4 insert flavor1: "
192 result
=`openvim flavor-create '
196 description: flavor to test openvim
198 processor_ranking: 205
207 #mac_address: "10:10:10:10:10:12"
212 mac_address: "10:10:10:10:10:13"
214 process_cmd uuid flavor1
$result
215 TODELETE
="flavor:$flavor1 $TODELETE"
217 printf "%-50s" "5 insert net_ptp: "
218 result
=`openvim net-create '
224 process_cmd uuid net_ptp
$result
225 TODELETE
="net:$net_ptp $TODELETE"
227 printf "%-50s" " b insert net_data: "
228 result
=`openvim net-create '
234 process_cmd uuid net_data
$result
235 TODELETE
="net:$net_data $TODELETE"
237 printf "%-50s" "6 insert net_bind network bound to net_data: "
238 result
=`openvim net-create 'name: test_net_binded
240 bind_net: test_net_data'`
241 process_cmd uuid net_bind
$result
242 TODELETE
="net:$net_bind $TODELETE"
244 printf "%-50s" "7 insert bridge network net2: "
245 result
=`openvim net-create '
248 name: test_bridge_net2
250 process_cmd uuid network2
$result
251 TODELETE
="net:$network2 $TODELETE"
253 printf "%-50s" "8 add VM1 dataplane not connected: "
254 result
=`openvim vm-create "
258 descrition: US or server with 1 SRIOV 1 PASSTHROUGH
260 flavorRef: '$flavor1'
264 uuid: ${network_eth0}
265 mac_address: '10:10:10:10:10:10'
269 mac_address: '10:10:10:10:10:11'
271 process_cmd uuid server1
$result
272 TODELETE
="vm:$server1 $TODELETE"
274 printf "%-50s" "9 add VM2 oversubscribe flavor: "
275 result
=`openvim vm-create "
279 descrition: US or server with direct network attach
281 flavorRef: '$flavor1'
285 uuid: ${network_eth0}
286 mac_address: '10:10:10:10:11:10'
290 mac_address: '10:10:10:10:11:11'
292 processor_ranking: 205
298 dedicated: 'yes:sriov'
301 mac_address: '10:10:10:10:11:12'
307 process_cmd uuid server2
$result
308 TODELETE
="vm:$server2 $TODELETE"
310 printf "%-50s" "10 test VM with repeated vpci: "
311 result
=`openvim vm-create "
315 descrition: repeated mac address
317 flavorRef: '$flavor1'
321 uuid: ${network_eth0}
323 process_cmd fail
"Duplicate vpci 0000:00:10.0" $result
325 printf "%-50s" " b test VM with repeated mac address: "
326 result
=`openvim vm-create "
330 descrition: repeated mac address
332 flavorRef: '$flavor1'
336 uuid: ${network_eth0}
337 mac_address: '10:10:10:10:10:10'
339 process_cmd fail
"Duplicate mac 10:10:10:10:10:10" $result
342 printf "%-50s" " c test VM with wrong iface name at networks: "
343 result
=`openvim vm-create "
347 descrition: repeated mac address
349 flavorRef: '$flavor1'
355 process_cmd fail
"wrong iface name at networks" $result
358 printf "%-50s" " d test VM with wrong iface type at networks: "
359 result
=`openvim vm-create "
363 descrition: repeated mac address
365 flavorRef: '$flavor1'
371 process_cmd fail
"wrong iface type at networks" $result
374 printf "%-50s" "11 add VM3 dataplane connected: "
375 result
=`openvim vm-create "
379 descrition: US or server with 2 dataplane connected
381 flavorRef: '$flavor1'
385 uuid: ${network_eth0}
386 mac_address: '10:10:10:10:12:10'
391 mac_address: '10:10:10:10:12:11'
398 mac_address: '10:10:10:10:12:13'
400 process_cmd uuid server3
$result
401 TODELETE
="vm:$server3 $TODELETE"
403 printf "%-50s" "12 check 2 openflow rules for net_ptp: "
404 test_of_rules
$net_ptp 2
406 printf "%-50s" "13 check net-down net_ptp: "
407 result
=`openvim net-down -f ${net_ptp}`
408 process_cmd ok
$result
410 printf "%-50s" " b check 0 openflow rules for net_ptp: "
411 test_of_rules
$net_ptp 0
413 printf "%-50s" " c check net-up net_ptp: "
414 result
=`openvim net-up -f ${net_ptp}`
415 process_cmd ok
$result
417 printf "%-50s" " d check 2 openflow rules for net_ptp: "
418 test_of_rules
$net_ptp 2
420 printf "%-50s" "14 check 0 openflow rules for net_data: "
421 test_of_rules
$net_data 0
423 [[ $force != y
]] && read -e -p " Test control plane, and server2:xe0 to server3:xe1 connectivity. Press enter to continue " kk
425 printf "%-50s" "15 get xe0 iface uuid from server1: "
426 result
=`openvim port-list -F"device_id=${server1}&name=xe0"`
427 process_cmd uuid server1_xe0
$result
429 printf "%-50s" " b get xe1 iface uuid from server1: "
430 result
=`openvim port-list -F"device_id=${server1}&name=xe1"`
431 process_cmd uuid server1_xe1
$result
433 printf "%-50s" " c get xe0 iface uuid from server3: "
434 result
=`openvim port-list -F"device_id=${server3}&name=xe0"`
435 process_cmd uuid server3_xe0
$result
437 printf "%-50s" " d get xe1 iface uuid from server3: "
438 result
=`openvim port-list -F"device_id=${server3}&name=xe1"`
439 process_cmd uuid server3_xe1
$result
441 printf "%-50s" " e get xe0 iface uuid from server3: "
442 result
=`openvim port-list -F"device_id=${server2}&name=xe0"`
443 process_cmd uuid server2_xe0
$result
445 printf "%-50s" "16 test ptp 3connex server1:xe0 -> net_ptp: "
446 result
=`openvim port-edit $server1_xe0 "network_id: $net_ptp" -f`
447 process_cmd fail
"Can not connect 3 interfaces to ptp network"
449 printf "%-50s" "17 attach server1:xe0 to net_data: "
450 result
=`openvim port-edit $server1_xe0 "network_id: $net_data" -f`
451 process_cmd ok
$result
453 printf "%-50s" "18 check 2 openflow rules for net_data: "
454 test_of_rules
$net_data 2
456 [[ $force != y
]] && read -e -p " Test server1:xe0 to server3:xe0 connectivity. Press enter to continue " kk
458 if [[ $same_vlan == n
]]
461 printf "%-50s" "19 attach server1:xe1 to net-data: "
462 result
=`openvim port-edit $server1_xe1 "network_id: $net_data" -f`
463 process_cmd ok
$result
465 printf "%-50s" " b check 9 openflow rules for net_data: "
466 test_of_rules
$net_data 9
468 [[ $force != y
]] && read -e -p " Test server1:xe0,server1:xe1,server3:xe0 connectivity. Press enter to continue " kk
470 printf "%-50s" " c re-attach server3:xe1 to net-data: "
471 result
=`openvim port-edit $server3_xe1 "network_id: $net_data" -f`
472 process_cmd ok
$result
474 printf "%-50s" " d check 16 openflow rules for net_data: "
475 test_of_rules
$net_data 16
477 printf "%-50s" " e check 0 openflow rules for net_ptp: "
478 test_of_rules
$net_ptp 0
480 [[ $force != y
]] && read -e -p " Test server1:xe0,server1:xe1,server3:xe0,server3:xe1 connectivity. Press enter to continue " kk
482 printf "%-50s" " f detach server1:xe1 from net-data: "
483 result
=`openvim port-edit $server1_xe1 "network_id: null" -f `
484 process_cmd ok
$result
486 printf "%-50s" " g detach server3:xe1 to net-data: "
487 result
=`openvim port-edit $server3_xe1 "network_id: null" -f`
488 process_cmd ok
$result
490 printf "%-50s" " h check 2 openflow rules for net_data: "
491 test_of_rules
$net_data 2
494 echo "19 skipping unrealizable test because --same_vlan option "
497 printf "%-50s" "20 check 2 openflow rules for net_data: "
498 test_of_rules
$net_data 2
500 printf "%-50s" " a attach server2:xe0 to net_bind: "
501 result
=`openvim port-edit $server2_xe0 "network_id: $net_bind" -f`
502 process_cmd ok
$result
504 printf "%-50s" " b check 6 openflow rules for net_data: "
505 #type src_net src_port => dst_port dst_net
506 #unicast net_data server1:xe0 => server3:xe0 net_data
507 #unicast net_data server3:xe0 => server1:xe0 net_data
508 #unicast net_data server1:xe0 => server2:xe0 net_bind
509 #unicast net_data server3:xe0 => server2:xe0 net_bind
510 #broadcast net_data server1:xe0 => server3:xe0,server2:xe0 net_data,net_bind
511 #broadcast net_data server3:xe0 => server1:xe0,server2:xe0 net_data,net_bind
512 test_of_rules
$net_data 6
515 printf "%-50s" " c check 3 openflow rules for net_bind: "
516 #type src_net src_port => dst_port dst_net
517 #unicast net_bind server2:xe0 => server1:xe0 net_data
518 #unicast net_bind server2:xe0 => server3:xe0 net_data
519 #broadcast net_bind server2:xe0 => server1:xe0,server3:xe0 net_data,net_data
520 test_of_rules
$net_bind 3
522 printf "%-50s" " d attach server1:xe1 to net_bind: "
523 result
=`openvim port-edit $server1_xe1 "network_id: $net_bind" -f`
524 process_cmd ok
$result
526 printf "%-50s" " e check 8 openflow rules for net_data: "
527 #type src_net src_port => dst_port dst_net
528 #unicast net_data server1:xe0 => server3:xe0 net_data
529 #unicast net_data server3:xe0 => server1:xe0 net_data
530 #unicast net_data server1:xe0 => server2:xe0 net_bind
531 #unicast net_data server1:xe0 => server1:xe1 net_bind
532 #unicast net_data server3:xe0 => server2:xe0 net_bind
533 #unicast net_data server3:xe0 => server1:xe1 net_bind
534 #broadcast net_data server1:xe0 => server3:xe0,server2:xe0,server1:xe1 net_data,net_bind,net_bind
535 #broadcast net_data server3:xe0 => server1:xe0,server2:xe0,server1:xe1 net_data,net_bind,net_bind
536 test_of_rules
$net_data 8
539 printf "%-50s" " f check 8 openflow rules for net_bind: "
540 test_of_rules
$net_bind 8
542 printf "%-50s" " d put net_data down: "
543 result
=`openvim net-down $net_data -f`
544 process_cmd ok
$result
546 printf "%-50s" " e check 0 openflow rules for net_data: "
547 test_of_rules
$net_data 0
549 printf "%-50s" " e check 2 openflow rules for net_bind: "
550 test_of_rules
$net_bind 2