blob: 04904671fb1f4711684bc1feee5f2da70fca6a1b [file] [log] [blame]
tierno574b09f2017-07-11 13:51:57 +02001#!/bin/bash
2
3##
tierno92021022018-09-12 16:29:23 +02004# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
tierno574b09f2017-07-11 13:51:57 +02005# 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 with fake tenant, datancenters, etc."\
30 "It assumes that you have configured openmano cli with HOST,PORT,TENANT with environment variables"
31 "If not, it will use by default localhost:9080 and creates a new TENANT"
32 echo -e " -h --help shows this help"
33}
34
35function is_valid_uuid(){
36 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
37 return 1
38}
39
40DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
41DIRmano=$(dirname $DIRNAME)
42DIRscript=${DIRmano}/scripts
43
44#detect paths of executables, preceding the relative paths
45openmano=openmano && [[ -x "${DIRmano}/openmano" ]] && openmano="${DIRmano}/openmano"
46service_openmano=service-openmano && [[ -x "$DIRscript/service-openmano" ]] &&
47 service_openmano="$DIRscript/service-openmano"
48initopenvim="initopenvim"
49openvim="openvim"
50
51function _exit()
52{
53 EXIT_STATUS=$1
54 for item in $ToDelete
55 do
56 command=${item%%:*}
57 uuid=${item#*:}
58 [[ $command == "datacenter-detach" ]] && force="" || force=-f
59 printf "%-50s" "$command $uuid:"
60 ! $openmano $command $uuid $force >> /dev/null && echo FAIL && EXIT_STATUS=1 || echo OK
61 done
62 [[ ${BASH_SOURCE[0]} != $0 ]] && return $1 || exit $EXIT_STATUS
63}
64
65
66# process options
67source ${DIRscript}/get-options.sh "force:-f help:h insert-bashrc init-openvim:initopenvim install-openvim screen" \
68 $* || _exit 1
69
70# help
71[ -n "$option_help" ] && usage && _exit 0
72
73
74ToDelete=""
75DCs="dc-fake1-openstack dc-fake2-openvim" #dc-fake3-vmware
76Ts="fake-tenant1 fake-tenand2"
77SDNs="sdn-fake1-opendaylight sdn-fake2-floodlight sdn-fake3-onos"
78
79for T in $Ts
80do
81 printf "%-50s" "Creating fake tenant '$T':"
82 ! result=`$openmano tenant-create "$T"` && echo FAIL && echo " $result" && _exit 1
83 tenant=`echo $result |gawk '{print $1}'`
84 ! is_valid_uuid $tenant && echo "FAIL" && echo " $result" && _exit 1
85 echo $tenant
86 ToDelete="tenant-delete:$tenant $ToDelete"
87 [[ -z "$OPENMANO_TENANT" ]] && export OPENMANO_TENANT=$tenant
88done
89
90index=0
91for DC in $DCs
92do
93 index=$((index+1))
94 printf "%-50s" "Creating datacenter '$DC':"
95 ! result=`$openmano datacenter-create "$DC" "http://$DC/v2.0" --type=${DC##*-} --config='{insecure: True}'` &&
96 echo FAIL && echo " $result" && _exit 1
97 datacenter=`echo $result |gawk '{print $1}'`
98 ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && _exit 1
99 echo $datacenter
100 eval DC${index}=$datacenter
101 ToDelete="datacenter-delete:$datacenter $ToDelete"
102 [[ -z "$datacenter_empty" ]] && datacenter_empty=datacenter
103
104 printf "%-50s" "Attaching openmano tenant to the datacenter:"
105 ! result=`$openmano datacenter-attach "$DC" --vim-tenant-name=osm --config='{insecure: False}'` &&
106 echo FAIL && echo " $result" && _exit 1
107 ToDelete="datacenter-detach:$datacenter $ToDelete"
108 echo OK
109done
110
111printf "%-50s" "Datacenter list:"
112! result=`$openmano datacenter-list` &&
113 echo "FAIL" && echo " $result" && _exit 1
114for verbose in "" -v -vv -vvv
115do
116 ! result=`$openmano datacenter-list "$DC" $verbose` &&
117 echo "FAIL" && echo " $result" && _exit 1
118done
119echo OK
120
121dpid_prefix=55:56:57:58:59:60:61:0
122dpid_sufix=0
123for SDN in $SDNs
124do
125 printf "%-50s" "Creating SDN controller '$SDN':"
126 ! result=`$openmano sdn-controller-create "$SDN" --ip 4.5.6.7 --port 80 --type=${SDN##*-} \
127 --user user --passwd p --dpid=${dpid_prefix}${dpid_sufix}` && echo "FAIL" && echo " $result" && _exit 1
128 sdn=`echo $result |gawk '{print $1}'`
129 #check a valid uuid is obtained
130 ! is_valid_uuid $sdn && echo "FAIL" && echo " $result" && _exit 1
131 echo $sdn
132 ToDelete="sdn-controller-delete:$sdn $ToDelete"
133 dpid_sufix=$((dpid_sufix+1))
134
135done
136printf "%-50s" "Edit SDN-controller:"
137for edit in user=u password=p ip=5.6.6.7 port=81 name=name dpid=45:55:54:45:44:44:55:67
138do
139 ! result=`$openmano sdn-controller-edit $sdn -f --"${edit}"` &&
140 echo "FAIL" && echo " $result" && _exit 1
141done
142echo OK
143
144printf "%-50s" "SDN-controller list:"
145! result=`$openmano sdn-controller-list` &&
146 echo "FAIL" && echo " $result" && _exit 1
147for verbose in "" -v -vv -vvv
148do
149 ! result=`$openmano sdn-controller-list "$sdn" $verbose` &&
150 echo "FAIL" && echo " $result" && _exit 1
151done
152echo OK
153
154printf "%-50s" "Add sdn to datacenter:"
155! result=`$openmano datacenter-edit -f $DC --sdn-controller $SDN` &&
156 echo "FAIL" && echo " $result" && _exit 1 || echo OK
157
158printf "%-50s" "Clear Port mapping:"
159! result=`$openmano datacenter-sdn-port-mapping-clear -f $DC` &&
160 echo "FAIL" && echo " $result" && _exit 1 || echo OK
161
162printf "%-50s" "Set Port mapping:"
163! result=`$openmano datacenter-sdn-port-mapping-set -f $DC ${DIRmano}/sdn/sdn_port_mapping.yaml` &&
164 echo "FAIL" && echo " $result" && _exit 1 || echo OK
165
166printf "%-50s" "List Port mapping:"
167for verbose in "" -v -vv -vvv
168do
169 ! result=`$openmano datacenter-sdn-port-mapping-list "$DC" $verbose` &&
170 echo "FAIL" && echo " $result" && _exit 1
171done
172echo OK
173
174printf "%-50s" "Set again Port mapping:"
175! result=`$openmano datacenter-sdn-port-mapping-set -f $DC ${DIRmano}/sdn/sdn_port_mapping.yaml` &&
176 echo "FAIL" && echo " $result" && _exit 1 || echo OK
177
178printf "%-50s" "Clear again Port mapping:"
179! result=`$openmano datacenter-sdn-port-mapping-clear -f $DC` &&
180 echo "FAIL" && echo " $result" && _exit 1 || echo OK
181
182printf "%-50s" "Set again Port mapping:"
183! result=`$openmano datacenter-sdn-port-mapping-set -f $DC ${DIRmano}/sdn/sdn_port_mapping.yaml` &&
184 echo "FAIL" && echo " $result" && _exit 1 || echo OK
185
186printf "%-50s" "Remove datacenter sdn:"
187! result=`$openmano datacenter-edit -f $DC --sdn-controller null` &&
188 echo "FAIL" && echo " $result" && _exit 1 || echo OK
189
190printf "%-50s" "Negative list port mapping:"
191result=`$openmano datacenter-sdn-port-mapping-list $DC` &&
192 echo "FAIL" && echo " $result" && _exit 1 || echo OK
193
194printf "%-50s" "Add again datacenter sdn:"
195! result=`$openmano datacenter-edit -f $DC --sdn-controller $SDN` &&
196 echo "FAIL" && echo " $result" && _exit 1 || echo OK
197
198printf "%-50s" "Empty list port mapping:"
199! [[ `$openmano datacenter-sdn-port-mapping-list $DC | wc -l` -eq 6 ]] &&
200 echo "FAIL" && _exit 1 || echo OK
201
202printf "%-50s" "Set again Port mapping:"
203! result=`$openmano datacenter-sdn-port-mapping-set -f $DC ${DIRmano}/sdn/sdn_port_mapping.yaml` &&
204 echo "FAIL" && echo " $result" && _exit 1 || echo OK
205
206_exit 0
207