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 openstack.
25 #in order to use you need to set the OS_XXXX bash variables with openstack values
26 # OS_USERNAME e.g.: admin
28 # OS_AUTH_URL url to access openstack VIM e.g. http:/openstack:35357/v2.0
29 # OS_TENANT_NAME e.g.: admin
30 # OS_CONFIG e.g.: "'network_vlan_ranges: sriov_net'"
31 # OS_TEST_IMAGE_PATH_LINUX image path(location) to use by the VNF linux
32 # OS_TEST_IMAGE_PATH_LINUXDATA image path(location) to use by the VNF dataplaneVNF_2VMs and dataplaneVNF3
34 #it should be used with source. It can modifies /home/$USER/.bashrc appending the variables
35 #you need to delete them manually if desired
38 echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] <action>\n test openmano using a openstack VIM"
39 echo -e " <action> is a list of the following items (by default 'reset create')"
40 echo -e " reset reset the openmano database content"
41 echo -e " create creates items at openstack VIM"
42 echo -e " delete delete created items"
44 echo -e " -f --force does not prompt for confirmation"
45 echo -e " -h --help shows this help"
46 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
47 echo -e " ~/.bashrc to be available by openmano config"
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
55 #detect if is called with a source to use the 'exit'/'return' command for exiting
56 [[ ${BASH_SOURCE[0]} != $0 ]] && _exit
="return" || _exit
="exit"
58 #detect if environment variables are set
60 [[ -z $OS_USERNAME ]] && echo "OS_USERNAME variable not defined" >&2 && fail
=1
61 [[ -z $OS_PASSWORD ]] && echo "OS_PASSWORD variable not defined" >&2 && fail
=1
62 [[ -z $OS_AUTH_URL ]] && echo "OS_AUTH_URL variable not defined" >&2 && fail
=1
63 [[ -z $OS_TENANT_NAME ]] && echo "OS_TENANT_NAME variable not defined" >&2 && fail
=1
64 [[ -z $OS_CONFIG ]] && echo "OS_CONFIG variable not defined" >&2 && fail
=1
65 [[ -z $OS_TEST_IMAGE_PATH_LINUX ]] && echo "OS_TEST_IMAGE_PATH_LINUX variable not defined" >&2 && fail
=1
66 [[ -z $OS_TEST_IMAGE_PATH_LINUXDATA ]] && echo "OS_TEST_IMAGE_PATH_LINUXDATA variable not defined" >&2 && fail
=1
67 [[ -n $fail ]] && $_exit 1
69 #check correct arguments
73 if [[ $param == reset ]] ||
[[ $param == create
]] ||
[[ $param == delete
]]
75 action_list
="$action_list $param"
76 elif [[ $param == -h ]] ||
[[ $param == --help ]]
80 elif [[ $param == -f ]] ||
[[ $param == --force ]]
83 elif [[ $param == --insert-bashrc ]]
87 echo "invalid argument '$param'?" && usage
>&2 && $_exit 1
91 DIRNAME
=$
(dirname $
(readlink
-f ${BASH_SOURCE[0]}))
92 DIRmano
=$
(dirname $DIRNAME)
93 DIRscript
=$
(dirname $DIRmano)/scripts
94 #by default action should be reset create
95 [[ -z $action_list ]] && action_list
="reset create"
97 for action
in $action_list
99 if [[ $action == "reset" ]]
102 #ask for confirmation if argument is not -f --force
103 [[ $force != y
]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N)" force
104 [[ $force != y
]] && [[ $force != yes ]] && echo "aborted!" && $_exit
106 echo "Stopping openmano"
107 $DIRscript/service-openmano.sh mano stop
108 echo "Initializing openmano database"
109 $DIRmano/database_utils
/init_mano_db.sh
-u mano
-p manopw
110 echo "Starting openmano"
111 $DIRscript/service-openmano.sh mano start
113 elif [[ $action == "delete" ]]
115 result
=`openmano tenant-list TOS-tenant`
116 nfvotenant
=`echo $result |gawk '{print $1}'`
117 #check a valid uuid is obtained
118 is_valid_uuid
$nfvotenant ||
! echo "Tenant TOS-tenant not found. Already delete?" >&2 ||
$_exit 1
119 export OPENMANO_TENANT
=$nfvotenant
120 openmano instance-scenario-delete
-f simple-instance ||
echo "fail"
121 openmano instance-scenario-delete
-f complex2-instance ||
echo "fail"
122 openmano scenario-delete
-f simple ||
echo "fail"
123 openmano scenario-delete
-f complex2 ||
echo "fail"
124 openmano vnf-delete
-f linux ||
echo "fail"
125 openmano vnf-delete
-f dataplaneVNF_2VMs ||
echo "fail"
126 openmano vnf-delete
-f dataplaneVNF3 ||
echo "fail"
127 openmano vnf-delete
-f TOS-VNF1 ||
echo "fail"
128 openmano datacenter-detach TOS-dc ||
echo "fail"
129 openmano datacenter-delete
-f TOS-dc ||
echo "fail"
130 openmano tenant-delete
-f TOS-tenant ||
echo "fail"
132 elif [[ $action == "create" ]]
135 printf "%-50s" "Creating openmano tenant 'TOS-tenant': "
136 result
=`openmano tenant-create TOS-tenant --description="created by test_os.sh"`
137 nfvotenant
=`echo $result |gawk '{print $1}'`
138 #check a valid uuid is obtained
139 ! is_valid_uuid
$nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
140 export OPENMANO_TENANT
=$nfvotenant
141 [[ $insert_bashrc == y
]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~
/.bashrc
144 printf "%-50s" "Creating datacenter 'TOS-dc' in openmano:"
145 result
=`openmano datacenter-create TOS-dc "${OS_AUTH_URL}" "--type=openstack" "--config=${OS_CONFIG}"`
146 datacenter
=`echo $result |gawk '{print $1}'`
147 #check a valid uuid is obtained
148 ! is_valid_uuid
$datacenter && echo "FAIL" && echo " $result" && $_exit 1
150 export OPENMANO_DATACENTER
=$datacenter
151 [[ $insert_bashrc == y
]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~
/.bashrc
153 printf "%-50s" "Attaching openmano tenant to the datacenter:"
154 result
=`openmano datacenter-attach TOS-dc "--user=$OS_USERNAME" "--password=$OS_PASSWORD" "--vim-tenant-name=$OS_TENANT_NAME"`
155 [[ $?
!= 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
158 printf "%-50s" "Updating external nets in openmano: "
159 result
=`openmano datacenter-netmap-delete -f --all`
160 [[ $?
!= 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
161 result
=`openmano datacenter-netmap-upload -f`
162 [[ $?
!= 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
165 printf "%-50s" "Creating VNF 'linux': "
166 #glance image-create --file=./US1404dpdk.qcow2 --name=US1404dpdk --disk-format=qcow2 --min-disk=2 --is-public=True --container-format=bare
167 #nova image-meta US1404dpdk set location=/mnt/powervault/virtualization/vnfs/os/US1404dpdk.qcow2
168 #glance image-create --file=./US1404user.qcow2 --min-disk=2 --is-public=True --container-format=bare --name=US1404user --disk-format=qcow2
169 #nova image-meta US1404user set location=/mnt/powervault/virtualization/vnfs/os/US1404user.qcow2
170 result
=`openmano vnf-create $DIRmano/vnfs/examples/linux.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUX"`
171 vnf
=`echo $result |gawk '{print $1}'`
172 #check a valid uuid is obtained
173 ! is_valid_uuid
$vnf && echo FAIL
&& echo " $result" && $_exit 1
176 printf "%-50s" "Creating VNF 1PF,1VF,2GHP,4PThreads: "
177 result
=`openmano vnf-create "vnf:
179 external-connections:
183 local_iface_name: eth0
187 local_iface_name: PF0
191 local_iface_name: VF0
194 VNFC image: $OS_TEST_IMAGE_PATH_LINUXDATA
197 paired-threads-id: [ [0,2], [1,3] ]
204 mac_address: '20:33:45:56:77:44'
209 mac_address: '20:33:45:56:77:45'
214 mac_address: '20:33:45:56:77:46'
217 vnf
=`echo $result |gawk '{print $1}'`
218 ! is_valid_uuid
$vnf && echo FAIL
&& echo " $result" && $_exit 1
221 printf "%-50s" "Creating VNF 'dataplaneVNF_2VMs': "
222 result
=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF_2VMs.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUXDATA,$OS_TEST_IMAGE_PATH_LINUXDATA"`
223 vnf
=`echo $result |gawk '{print $1}'`
224 ! is_valid_uuid
$vnf && echo FAIL
&& echo " $result" && $_exit 1
227 printf "%-50s" "Creating VNF 'dataplaneVNF3.yaml': "
228 result
=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF3.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUXDATA"`
229 vnf
=`echo $result |gawk '{print $1}'`
230 ! is_valid_uuid
$vnf && echo FAIL
&& echo " $result" && $_exit 1
233 for sce
in simple complex2
235 printf "%-50s" "Creating scenario '$sce':"
236 result
=`openmano scenario-create $DIRmano/scenarios/examples/${sce}.yaml`
237 scenario
=`echo $result |gawk '{print $1}'`
238 ! is_valid_uuid
$scenario && echo FAIL
&& echo " $result" && $_exit 1
242 for sce
in simple complex2
244 printf "%-50s" "Deploying scenario '$sce':"
245 result
=`openmano instance-scenario-create --scenario $sce --name ${sce}-instance`
246 instance
=`echo $result |gawk '{print $1}'`
247 ! is_valid_uuid
$instance && echo FAIL
&& echo " $result" && $_exit 1