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 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
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
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
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"
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"
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
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"
61 #detect if environment variables are set
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
73 #check correct arguments
77 if [[ $param == reset ]] ||
[[ $param == create
]] ||
[[ $param == delete
]]
79 action_list
="$action_list $param"
80 elif [[ $param == -h ]] ||
[[ $param == --help ]]
84 elif [[ $param == -f ]] ||
[[ $param == --force ]]
87 elif [[ $param == --insert-bashrc ]]
91 echo "invalid argument '$param'?" && usage
>&2 && $_exit 1
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"
101 for action
in $action_list
103 if [[ $action == "reset" ]]
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
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
117 elif [[ $action == "delete" ]]
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"
140 elif [[ $action == "create" ]]
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
152 printf "%-50s" "Creating datacenter 'TESTVIM-dc' in openmano:"
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
160 export OPENMANO_DATACENTER
=$datacenter
161 [[ $insert_bashrc == y
]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~
/.bashrc
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
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
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
190 printf "%-50s" "Creating VNF 1PF,1VF,2GB,4PThreads: "
191 result
=`openmano vnf-create "vnf:
193 external-connections:
196 VNFC: TESTVIM-VNF1-VM
197 local_iface_name: eth0
200 VNFC: TESTVIM-VNF1-VM
201 local_iface_name: PF0
204 VNFC: TESTVIM-VNF1-VM
205 local_iface_name: VF0
207 - name: TESTVIM-VNF1-VM
208 VNFC image: $VIM_TEST_IMAGE_PATH_NFV
211 paired-threads-id: [ [0,2], [1,3] ]
218 mac_address: '20:33:45:56:77:44'
223 mac_address: '20:33:45:56:77:45'
228 mac_address: '20:33:45:56:77:46'
231 vnf
=`echo $result |gawk '{print $1}'`
232 ! is_valid_uuid
$vnf && echo FAIL
&& echo " $result" && $_exit 1
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
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
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
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
259 for sce
in simple complex2 complex3 complex4
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
271 #add user keys if present at .ssh
272 ls ${HOME}/.ssh
/*.pub
> /dev
/null
2>&1 && key_param1
=--keypair-auto
274 for sce
in simple complex2
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
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