openmano first code upload
[osm/RO.git] / test / test_os.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 openstack.
25 #in order to use you need to set the OS_XXXX bash variables with openstack values
26 # OS_USERNAME e.g.: admin
27 # OS_PASSWORD
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
33
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
36
37 function usage(){
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"
43 echo -e " OPTIONS:"
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"
48 }
49
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
52 return 1
53 }
54
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"
57
58 #detect if environment variables are set
59 fail=""
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
68
69 #check correct arguments
70 action_list=""
71 for param in $*
72 do
73 if [[ $param == reset ]] || [[ $param == create ]] || [[ $param == delete ]]
74 then
75 action_list="$action_list $param"
76 elif [[ $param == -h ]] || [[ $param == --help ]]
77 then
78 usage
79 $_exit 0
80 elif [[ $param == -f ]] || [[ $param == --force ]]
81 then
82 force=y
83 elif [[ $param == --insert-bashrc ]]
84 then
85 insert_bashrc=y
86 else
87 echo "invalid argument '$param'?" && usage >&2 && $_exit 1
88 fi
89 done
90
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"
96
97 for action in $action_list
98 do
99 if [[ $action == "reset" ]]
100 then
101
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
105
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
112
113 elif [[ $action == "delete" ]]
114 then
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"
131
132 elif [[ $action == "create" ]]
133 then
134
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
142 echo $nfvotenant
143
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
149 echo $datacenter
150 export OPENMANO_DATACENTER=$datacenter
151 [[ $insert_bashrc == y ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc
152
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
156 echo OK
157
158 printf "%-50s" "Updating external nets in openmano: "
159 result=`openmano datacenter-net-update -f TOS-dc`
160 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
161 echo OK
162
163 printf "%-50s" "Creating VNF 'linux': "
164 #glance image-create --file=./US1404dpdk.qcow2 --name=US1404dpdk --disk-format=qcow2 --min-disk=2 --is-public=True --container-format=bare
165 #nova image-meta US1404dpdk set location=/mnt/powervault/virtualization/vnfs/os/US1404dpdk.qcow2
166 #glance image-create --file=./US1404user.qcow2 --min-disk=2 --is-public=True --container-format=bare --name=US1404user --disk-format=qcow2
167 #nova image-meta US1404user set location=/mnt/powervault/virtualization/vnfs/os/US1404user.qcow2
168 result=`openmano vnf-create $DIRmano/vnfs/examples/linux.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUX"`
169 vnf=`echo $result |gawk '{print $1}'`
170 #check a valid uuid is obtained
171 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
172 echo $vnf
173
174 printf "%-50s" "Creating VNF 1PF,1VF,2GHP,4PThreads: "
175 result=`openmano vnf-create "vnf:
176 name: TOS-VNF1
177 external-connections:
178 - name: eth0
179 type: mgmt
180 VNFC: TOS-VNF1-VM
181 local_iface_name: eth0
182 - name: PF0
183 type: data
184 VNFC: TOS-VNF1-VM
185 local_iface_name: PF0
186 - name: VF0
187 type: data
188 VNFC: TOS-VNF1-VM
189 local_iface_name: VF0
190 VNFC:
191 - name: TOS-VNF1-VM
192 VNFC image: $OS_TEST_IMAGE_PATH_LINUXDATA
193 numas:
194 - paired-threads: 2
195 paired-threads-id: [ [0,2], [1,3] ]
196 memory: 2
197 interfaces:
198 - name: PF0
199 vpci: '0000:00:11.0'
200 dedicated: 'yes'
201 bandwidth: 10 Gbps
202 mac_address: '20:33:45:56:77:44'
203 - name: VF0
204 vpci: '0000:00:12.0'
205 dedicated: 'no'
206 bandwidth: 1 Gbps
207 mac_address: '20:33:45:56:77:45'
208 bridge-ifaces:
209 - name: eth0
210 vpci: '0000:00:09.0'
211 bandwidth: 1 Mbps
212 mac_address: '20:33:45:56:77:46'
213 model: e1000
214 "`
215 vnf=`echo $result |gawk '{print $1}'`
216 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
217 echo $vnf
218
219 printf "%-50s" "Creating VNF 'dataplaneVNF_2VMs': "
220 result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF_2VMs.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUXDATA,$OS_TEST_IMAGE_PATH_LINUXDATA"`
221 vnf=`echo $result |gawk '{print $1}'`
222 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
223 echo $vnf
224
225 printf "%-50s" "Creating VNF 'dataplaneVNF3.yaml': "
226 result=`openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF3.yaml "--image-path=$OS_TEST_IMAGE_PATH_LINUXDATA"`
227 vnf=`echo $result |gawk '{print $1}'`
228 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
229 echo $vnf
230
231 for sce in simple complex2
232 do
233 printf "%-50s" "Creating scenario '$sce':"
234 result=`openmano scenario-create $DIRmano/scenarios/examples/${sce}.yaml`
235 scenario=`echo $result |gawk '{print $1}'`
236 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
237 echo $scenario
238 done
239
240 for sce in simple complex2
241 do
242 printf "%-50s" "Deploying scenario '$sce':"
243 result=`openmano scenario-deploy $sce ${sce}-instance`
244 instance=`echo $result |gawk '{print $1}'`
245 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
246 echo $instance
247 done
248
249 echo
250 echo DONE
251 fi
252 done
253