blob: ad243c63252ec7e36231f8074f689adde6d6ebf9 [file] [log] [blame]
tierno96d9cd42016-07-13 12:28:19 +02001#!/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.
25#WARNING: It destroy the database content
26
27
28function usage(){
29 echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] <action>\n test openmano using openvim as a VIM"
30 echo -e " the OPENVIM_HOST, OPENVIM_PORT shell variables indicate openvim location"
tierno72f35a52016-07-15 13:18:30 +020031 echo -e " by default localhost:9080"
tierno96d9cd42016-07-13 12:28:19 +020032 echo -e " <action> is a list of the following items (by default 'reset create delete')"
33 echo -e " reset reset the openmano database content"
34 echo -e " create creates items"
35 echo -e " delete delete created items"
36 echo -e " OPTIONS:"
37 echo -e " -f --force does not prompt for confirmation"
38 echo -e " -h --help shows this help"
39 echo -e " --insert-bashrc insert the created tenant,datacenter variables at"
40 echo -e " ~/.bashrc to be available by openmano CLI"
tierno72f35a52016-07-15 13:18:30 +020041 echo -e " --init-openvim if openvim runs locally, an init is called to clean openvim"
42 echo -e " database and add fake hosts"
tierno96d9cd42016-07-13 12:28:19 +020043}
44
45function is_valid_uuid(){
46 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
47 return 1
48}
49
50#detect if is called with a source to use the 'exit'/'return' command for exiting
tiernob6884bd2016-07-15 14:09:47 +020051[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
tierno96d9cd42016-07-13 12:28:19 +020052
tierno96d9cd42016-07-13 12:28:19 +020053
54#check correct arguments
55force=""
56action_list=""
57insert_bashrc=""
58init_openvim=""
tierno205d1022016-07-21 11:26:22 +020059
60while [[ $# -gt 0 ]]
tierno96d9cd42016-07-13 12:28:19 +020061do
tierno205d1022016-07-21 11:26:22 +020062 argument="$1"
63 shift
64 if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]]
tierno96d9cd42016-07-13 12:28:19 +020065 then
tierno205d1022016-07-21 11:26:22 +020066 action_list="$action_list $argument"
67 continue
68 #short options
69 elif [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
tierno96d9cd42016-07-13 12:28:19 +020070 then
tierno205d1022016-07-21 11:26:22 +020071 index=0
72 while index=$((index+1)) && [[ $index -lt ${#argument} ]]
73 do
74 [[ ${argument:$index:1} == h ]] && usage && $_exit 0
75 [[ ${argument:$index:1} == f ]] && force="-f" && continue
76 echo "invalid option '${argument:$index:1}'? Type -h for help" >&2 && $_exit 1
77 done
78 continue
tierno96d9cd42016-07-13 12:28:19 +020079 fi
tierno205d1022016-07-21 11:26:22 +020080 #long options
81 [[ $argument == --help ]] && usage && $_exit 0
82 [[ $argument == --force ]] && force="-f" && continue
83 [[ $argument == --insert-bashrc ]] && insert_bashrc="--insert-bashrc" && continue
84 [[ $argument == --init-openvim ]] && init_openvim="y" && continue
85 echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
tierno96d9cd42016-07-13 12:28:19 +020086done
87
88DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
89DIRmano=$(dirname $DIRNAME)
90DIRscript=${DIRmano}/scripts
tiernob6884bd2016-07-15 14:09:47 +020091export OPENMANO_HOST=localhost
92export OPENMANO_PORT=9090
tierno205d1022016-07-21 11:26:22 +020093[[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc
94[[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc
tiernob6884bd2016-07-15 14:09:47 +020095
96
tierno96d9cd42016-07-13 12:28:19 +020097#by default action should be reset and create
98[[ -z $action_list ]] && action_list="reset create delete"
tierno205d1022016-07-21 11:26:22 +020099[[ -z $init_openvim ]] || initopenvim $force $insert_bashrc || echo "WARNING openvim cannot be initialized. The rest of test can fail!"
tierno96d9cd42016-07-13 12:28:19 +0200100
tierno72f35a52016-07-15 13:18:30 +0200101#check openvim client variables are set
102#fail=""
103#[[ -z $OPENVIM_HOST ]] && echo "OPENVIM_HOST variable not defined" >&2 && fail=1
104#[[ -z $OPENVIM_PORT ]] && echo "OPENVIM_PORT variable not defined" >&2 && fail=1
105#[[ -n $fail ]] && $_exit 1
106
107
tierno96d9cd42016-07-13 12:28:19 +0200108for action in $action_list
109do
110#if [[ $action == "install-openvim" ]]
111 #echo "Installing and starting openvim"
112 #mkdir -p temp
113 #pushd temp
114 #wget https://github.com/nfvlabs/openvim/raw/v0.4/scripts/install-openvim.sh
115 #chmod -x install-openvim.sh
116#fi
117
118if [[ $action == "reset" ]]
119then
120
121 #ask for confirmation if argument is not -f --force
tierno72f35a52016-07-15 13:18:30 +0200122 force_=y
tierno96d9cd42016-07-13 12:28:19 +0200123 [[ -z $force ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_
124 [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
125
126 echo "Stopping openmano"
127 $DIRscript/service-openmano.sh mano stop
128 echo "Initializing openmano database"
129 $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
130 echo "Starting openmano"
131 $DIRscript/service-openmano.sh mano start
132 echo
133
134elif [[ $action == "delete" ]]
135then
136 result=`openmano tenant-list TEST-tenant`
137 nfvotenant=`echo $result |gawk '{print $1}'`
138 #check a valid uuid is obtained
139 is_valid_uuid $nfvotenant || ! echo "Tenant TEST-tenant not found. Already delete?" >&2 || $_exit 1
140 export OPENMANO_TENANT=$nfvotenant
141 ${DIRmano}/openmano instance-scenario-delete -f simple-instance || echo "fail"
142 ${DIRmano}/openmano instance-scenario-delete -f complex-instance || echo "fail"
143 ${DIRmano}/openmano instance-scenario-delete -f complex2-instance || echo "fail"
144 ${DIRmano}/openmano scenario-delete -f simple || echo "fail"
145 ${DIRmano}/openmano scenario-delete -f complex || echo "fail"
146 ${DIRmano}/openmano scenario-delete -f complex2 || echo "fail"
147 ${DIRmano}/openmano vnf-delete -f linux || echo "fail"
148 ${DIRmano}/openmano vnf-delete -f dataplaneVNF_2VMs || echo "fail"
149 ${DIRmano}/openmano vnf-delete -f dataplaneVNF2 || echo "fail"
150 ${DIRmano}/openmano vnf-delete -f dataplaneVNF3 || echo "fail"
151 ${DIRmano}/openmano datacenter-detach TEST-dc || echo "fail"
152 ${DIRmano}/openmano datacenter-delete -f TEST-dc || echo "fail"
153 ${DIRmano}/openmano tenant-delete -f TEST-tenant || echo "fail"
154 echo
155
156elif [[ $action == "create" ]]
157then
158 printf "%-50s" "Creating openmano tenant 'TEST-tenant': "
159 result=`${DIRmano}/openmano tenant-create TEST-tenant --description="created by basictest.sh"`
160 nfvotenant=`echo $result |gawk '{print $1}'`
161 #check a valid uuid is obtained
162 ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1
163 export OPENMANO_TENANT=$nfvotenant
tierno205d1022016-07-21 11:26:22 +0200164 [[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200165 echo $nfvotenant
166
167 printf "%-50s" "Creating datacenter 'TEST-dc' in openmano:"
168 [[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
169 [[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
170 URL_ADMIN_PARAM=""
171 [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM="--url_admin=http://${$OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
172 result=`${DIRmano}/openmano datacenter-create TEST-dc "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" --type=openvim $URL_ADMIN_PARAM`
173 datacenter=`echo $result |gawk '{print $1}'`
174 #check a valid uuid is obtained
175 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
176 echo $datacenter
177 export OPENMANO_DATACENTER=$datacenter
tierno205d1022016-07-21 11:26:22 +0200178 [[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc
tierno96d9cd42016-07-13 12:28:19 +0200179
180 printf "%-50s" "Attaching openmano tenant to the datacenter:"
181 result=`${DIRmano}/openmano datacenter-attach TEST-dc`
182 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
183 echo OK
184
185 printf "%-50s" "Updating external nets in openmano: "
186 result=`${DIRmano}/openmano datacenter-netmap-delete -f --all`
187 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
188 result=`${DIRmano}/openmano datacenter-netmap-upload -f`
189 [[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
190 echo OK
191
192 for VNF in linux dataplaneVNF1 dataplaneVNF2 dataplaneVNF_2VMs dataplaneVNF3
193 do
194 printf "%-50s" "Creating VNF '${VNF}': "
195 result=`$DIRmano/openmano vnf-create $DIRmano/vnfs/examples/${VNF}.yaml`
196 vnf=`echo $result |gawk '{print $1}'`
197 #check a valid uuid is obtained
198 ! is_valid_uuid $vnf && echo FAIL && echo " $result" && $_exit 1
199 echo $vnf
200 done
201 for NS in simple complex complex2
202 do
203 printf "%-50s" "Creating scenario '${NS}':"
204 result=`$DIRmano/openmano scenario-create $DIRmano/scenarios/examples/${NS}.yaml`
205 scenario=`echo $result |gawk '{print $1}'`
206 ! is_valid_uuid $scenario && echo FAIL && echo " $result" && $_exit 1
207 echo $scenario
208 done
209
210 for IS in simple complex complex2
211 do
212 printf "%-50s" "Creating instance-scenario '${IS}':"
213 result=`$DIRmano/openmano instance-scenario-create --scenario ${IS} --name ${IS}-instance`
214 instance=`echo $result |gawk '{print $1}'`
215 ! is_valid_uuid $instance && echo FAIL && echo " $result" && $_exit 1
216 echo $instance
217 done
218
219 echo
220 #echo "Check virtual machines are deployed"
221 #vms_error=`openvim vm-list | grep ERROR | wc -l`
222 #vms=`openvim vm-list | wc -l`
223 #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
224 #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
225fi
226done
227
228echo
229echo DONE
230
231