blob: 6505091fc05c75e34b8a512c3961b366be68567d [file] [log] [blame]
tierno7edb6752016-03-21 17:37:52 +01001#!/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 is a basic test for openmano, that deals with two openvim
25#stopping on an error
26#WARNING: It destroy the database content
27
28
29function usage(){
30 echo -e "usage: ${BASH_SOURCE[0]} [-f]\n Deletes openvim/openmano content and make automatically the wiki steps"
31 echo -e " at 'https://github.com/nfvlabs/openmano/wiki/Getting-started#how-to-use-it'"
32 echo -e " OPTIONS:"
33 echo -e " -f --force : does not prompt for confirmation"
34 echo -e " -h --help : shows this help"
35}
36
37function is_valid_uuid(){
38 echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
39 return 1
40}
41
42
43#detect if is called with a source to use the 'exit'/'return' command for exiting
44[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
45
46#check correct arguments
47[[ -n $1 ]] && [[ $1 != -h ]] && [[ $1 != --help ]] && [[ $1 != -f ]] && [[ $1 != --force ]] && \
48 echo "invalid argument '$1'?" && usage >&2 && $_exit 1
49[[ $1 == -h ]] || [[ $1 == --help ]] && usage && $_exit 0
50
51#ask for confirmation if argument is not -f --force
52force=""
53[[ $1 == -f ]] || [[ $1 == --force ]] && force=y
54[[ $force != y ]] && read -e -p "WARNING: openmano and openvim database content will be lost!!! Continue(y/N)" force
55[[ $force != y ]] && [[ $force != yes ]] && echo "aborted!" && $_exit
56
57DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
58DIR_BASE=$(dirname $DIRNAME)
59DIR_BASE=$(dirname $DIR_BASE)
60DIRvim=$DIR_BASE/openvim
61DIRmano=$DIR_BASE/openmano
62DIRscripts=$DIR_BASE/scripts
63
64echo "deleting deployed vm"
65openvim vm-delete -f | grep -q deleted && sleep 10 #give some time to get virtual machines deleted
66
67echo "Stopping openmano"
garciadeblasde590c02017-04-24 13:17:01 +020068$DIRscripts/service-openmano stop
tierno7edb6752016-03-21 17:37:52 +010069
70echo "Initializing databases"
71$DIRvim/database_utils/init_vim_db.sh -u vim -p vimpw
72$DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
73
74echo "Starting openmano"
garciadeblasde590c02017-04-24 13:17:01 +020075$DIRscripts/service-openmano start
tierno7edb6752016-03-21 17:37:52 +010076
77echo "Creating openmano tenant 'mytenant'"
78nfvotenant=`openmano tenant-create mytenant --description=mytenant |gawk '{print $1}'`
79#check a valid uuid is obtained
80is_valid_uuid $nfvotenant || ! echo "fail" >&2 || $_exit 1
81export OPENMANO_TENANT=$nfvotenant
82echo " $nfvotenant"
83
84echo "Adding example hosts"
85openvim host-add $DIRvim/test/hosts/host-example0.json || ! echo "fail" >&2 || $_exit 1
86openvim host-add $DIRvim/test/hosts/host-example1.json || ! echo "fail" >&2 || $_exit 1
87openvim host-add $DIRvim/test/hosts/host-example2.json || ! echo "fail" >&2 || $_exit 1
88openvim host-add $DIRvim/test/hosts/host-example3.json || ! echo "fail" >&2 || $_exit 1
89echo "Adding example nets"
90openvim net-create $DIRvim/test/networks/net-example0.yaml || ! echo "fail" >&2 || $_exit 1
91openvim net-create $DIRvim/test/networks/net-example1.yaml || ! echo "fail" >&2 || $_exit 1
92openvim net-create $DIRvim/test/networks/net-example2.yaml || ! echo "fail" >&2 || $_exit 1
93openvim net-create $DIRvim/test/networks/net-example3.yaml || ! echo "fail" >&2 || $_exit 1
94
95echo "Creating openvim tenant 'admin'"
96vimtenant=`openvim tenant-create '{"tenant": {"name":"admin", "description":"admin"}}' |gawk '{print $1}'`
97#check a valid uuid is obtained
98is_valid_uuid $vimtenant || ! echo "fail" >&2 || $_exit 1
99echo " $vimtenant"
100OPENVIM_TENANT_1=$vimtenant && export OPENVIM_TENANT=$vimtenant
101
102echo "Creating datacenter 'mydc1' in openmano"
103datacenter=`openmano datacenter-create mydc1 http://localhost:9080/openvim |gawk '{print $1}'`
104#check a valid uuid is obtained
105is_valid_uuid $datacenter || ! echo "fail" >&2 || $_exit 1
106echo " $datacenter"
107OPENMANO_DATACENTER_1=$datacenter && export OPENMANO_DATACENTER=$datacenter
108
109echo "Attaching openmano tenant to the datacenter and the openvim tenant"
110openmano datacenter-attach mydc1 --vim-tenant-id $vimtenant || ! echo "fail" >&2 || $_exit 1
111
112echo "Updating external nets in openmano"
113openmano datacenter-net-update -f mydc1 || ! echo "fail" >&2 || $_exit 1
114
115echo "Creating a second fake datacenter 'mydc2' in openmano"
116datacenter2=`openmano datacenter-create mydc2 http://localhost:9082/openvim |gawk '{print $1}'`
117#check a valid uuid is obtained
118is_valid_uuid $datacenter || ! echo "fail" >&2 || $_exit 1
119echo " $datacenter2"
120OPENMANO_DATACENTER_2=$datacenter2
121echo "Attaching a second fake openvim 'mydc2'"
122openmano datacenter-attach mydc2 --vim-tenant-id $vimtenant || ! echo "fail" >&2 || $_exit 1
123
124echo "Creating VNFs, must fail in second openvim"
125openmano vnf-create $DIRmano/vnfs/examples/linux.yaml || ! echo "fail" >&2 || $_exit 1
126openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF1.yaml || ! echo "fail" >&2 || $_exit 1
127openmano vnf-create $DIRmano/vnfs/examples/dataplaneVNF2.yaml || ! echo "fail" >&2 || $_exit 1
128
129echo "Checking images and flavors created at openvim"
130nb=`openvim image-list | wc -l`
131echo -n " $nb images "
132[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
133echo " $nb flavors "
134[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
135
136echo "Creating Scenarios"
137openmano scenario-create $DIRmano/scenarios/examples/simple.yaml || ! echo "fail" >&2 || $_exit 1
138openmano scenario-create $DIRmano/scenarios/examples/complex.yaml || ! echo "fail" >&2 || $_exit 1
139
140echo "Deleting openvim images and flavors to force reload again"
141openvim image-delete -f
142openvim flavor-delete -f
143
144echo "Launching scenarios"
145openmano scenario-deploy simple simple-instance || ! echo "fail" >&2 || $_exit 1
146openmano scenario-deploy complex complex-instance || ! echo "fail" >&2 || $_exit 1
147
148echo "Checking that openvim has 5 VM running"
149nb=`openvim vm-list | wc -l`
150[[ $nb -eq 5 ]] || ! echo "fail" >&2 || $_exit 1
151while openvim vm-list | grep -q CREATING ; do sleep 1; done
152openvim vm-list | grep -v -q ERROR || ! echo "fail: VM with error" >&2 || $_exit 1
153
154echo "Removing scenarios"
155for scenario in `openmano instance-scenario-list | awk '{print $2}'`
156do
157 openmano instance-scenario-delete -f $scenario
158done
159
160echo "Editing datacenters so that Changing openvim Working with the second openvim"
161openmano datacenter-edit -f mydc1 'vim_url: http://localhost:9083/openvim'
162openmano datacenter-edit -f mydc2 'vim_url: http://localhost:9080/openvim'
163export OPENMANO_DATACENTER=$OPENMANO_DATACENTER_2
164
165echo "Updating external nets in openmano for second datacenter"
166openmano datacenter-net-update -f mydc2 || ! echo "fail" >&2 || $_exit 1
167
168echo "Launching Scenario instances"
169openmano scenario-deploy simple simple-instance || ! echo "fail" >&2 || $_exit 1
170openmano scenario-deploy complex complex-instance || ! echo "fail" >&2 || $_exit 1
171
172echo "Checking images and flavors created at openvim"
173nb=`openvim image-list | wc -l`
174echo -n " $nb images "
175[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
176echo " $nb flavors "
177[[ $nb -eq 3 ]] || ! echo "fail" >&2 || $_exit 1
178
179echo "Checking that openvim has 5 VM running"
180nb=`openvim vm-list | wc -l`
181[[ $nb -eq 5 ]] || ! echo "fail" >&2 || $_exit 1
182while openvim vm-list | grep -q CREATING ; do sleep 1; done
183openvim vm-list | grep -v -q ERROR || ! echo "fail: VM with error" >&2 || $_exit 1
184
185
186echo
187echo DONE
188#echo "Listing VNFs"
189#openmano vnf-list
190#echo "Listing scenarios"
191#openmano scenario-list
192#echo "Listing scenario instances"
193#openmano instance-scenario-list
194
195