4 # Copyright 2017 Telefonica Investigacion y Desarrollo, S.A.U.
5 # This file is part of OSM
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
22 # Author: Alfonso Tierno (alfonso.tiernosepulveda@telefonica.com)
24 description
="It creates a new lxc container, installs RO from a concrete commit and executes validation tests.\
25 An openvim in test mode is installed and used to validate"
28 echo -e "usage: ${BASH_SOURCE[0]} CONTAINER\n ${description}"
29 echo -e " CONTAINER is the name of the container to be created. By default test1"\
30 "Warning! if a container with the same name exists, it will be deleted"
31 echo -e " You must also supply at TEST_RO_COMMIT envioronmental variable with the git command"\
32 "to clone the version under test. It can be copy paste from gerrit. Examples:\n"\
33 " TEST_RO_COMMIT='git fetch https://osm.etsi.org/gerrit/osm/RO refs/changes/40/5540/1 && git checkout FETCH_HEAD'\n"\
34 " TEST_RO_COMMIT='git checkout v3.0.1'"
35 echo -e " You can provide TEST_RO_GIT_URL, by default https://osm.etsi.org/gerrit/osm/RO is used"
36 echo -e " You can provide TEST_RO_CONTAINER instead of by parameter, by default test1"
37 echo -e " You can provide TEST_RO_CUSTOM, with a command for container customization, by default nothing."
40 [ "$1" = "--help" ] ||
[ "$1" = "-h" ] && usage
&& exit 0
42 [[ -z "$TEST_RO_COMMIT" ]] && echo 'provide a TEST_RO_COMMIT variable. Type --help for more info' >&2 && exit 1
43 [[ -z "$TEST_RO_GIT_URL" ]] && TEST_RO_GIT_URL
="https://osm.etsi.org/gerrit/osm/RO"
45 [ -n "$1" ] && TEST_RO_CONTAINER
="$1"
46 [[ -z "$TEST_RO_CONTAINER" ]] && TEST_RO_CONTAINER
=test1
48 instance_name
=3vdu_2vnf
50 function echo_RO_log
(){
51 # echo "LOG DUMP:" >&2 && lxc exec "$TEST_RO_CONTAINER" -- tail -n 150 /var/log/osm/openmano.log >&2
52 echo -e "\nFAILED" >&2
56 if ! lxc
exec "$TEST_RO_CONTAINER" --env OPENMANO_TENANT
=osm
--env OPENMANO_DATACENTER
=local-openvim \
57 --env OPENVIM_TENANT
="$OPENVIM_TENANT" -- bash
-c "$*"
59 echo "ERROR on command '$*'" >&2
65 function wait_until_deleted
(){
67 while lxc_exec RO
/test
/local
/openvim
/openvim vm-list |
grep -q -e ${instance_name} ||
68 lxc_exec RO
/test
/local
/openvim
/openvim net-list |
grep -q -e ${instance_name}
71 [ $wait_active -gt 90 ] && echo "timeout waiting VM and nets deleted at VIM" >&2 && echo_RO_log
&& exit 1
72 wait_active
=$
((wait_active
+ 1))
78 lxc delete
"$TEST_RO_CONTAINER" --force 2>/dev
/null
&& echo "container '$TEST_RO_CONTAINER' deleted"
79 lxc launch ubuntu
:16.04 "$TEST_RO_CONTAINER"
81 [[ -n "$TEST_RO_CUSTOM" ]] && ${TEST_RO_CUSTOM}
82 lxc_exec ifconfig eth0 mtu
1446 # Avoid problems when inside an openstack VM that normally limit MTU do this value
83 lxc_exec git clone
"$TEST_RO_GIT_URL"
84 lxc_exec git
-C RO status
85 lxc_exec
"cd RO && $TEST_RO_COMMIT"
88 lxc_exec RO
/scripts
/install-openmano.sh
--noclone --force -q --updatedb -b master
90 lxc_exec openmano tenant-create osm
91 lxc_exec openmano tenant-list
93 # TEST database migration
94 lxc_exec .
/RO
/database_utils
/migrate_mano_db.sh
20
95 lxc_exec .
/RO
/database_utils
/migrate_mano_db.sh
96 lxc_exec .
/RO
/database_utils
/migrate_mano_db.sh
20
97 lxc_exec .
/RO
/database_utils
/migrate_mano_db.sh
99 # TEST instantiate with a fake local openvim
100 lxc_exec .
/RO
/test
/basictest.sh
-f --insert-bashrc --install-openvim reset add-openvim create delete
103 # TEST instantiate with a fake local openvim 2
104 lxc_exec .
/RO
/test
/test_RO.py deploy
-n mgmt
-t osm
-i cirros034
-d local-openvim
--timeout=30 --failfast
105 lxc_exec .
/RO
/test
/test_RO.py vim
-t osm
-d local-openvim
--timeout=30 --failfast
108 echo "TEST service restart in the middle of a instantiation/deletion"
109 OPENVIM_TENANT
=`lxc_exec RO/test/local/openvim/openvim tenant-list`
110 OPENVIM_TENANT
=${OPENVIM_TENANT%% *}
112 lxc_exec openmano vnf-create RO
/vnfs
/examples
/v3_3vdu_vnfd.yaml
--image-name=cirros034
113 lxc_exec openmano scenario-create RO
/scenarios
/examples
/v3_3vdu_2vnf_nsd.yaml
116 while [ $test_number -lt 5 ] ; do
117 echo test ${test_number}.0 test instantiation recovering
118 lxc_exec openmano instance-scenario-create
--name ${instance_name} --scenario osm_id
=3vdu_2vnf_nsd
";"service osm-ro stop
120 lxc_exec service osm-ro start
122 # wait until all VM are active
124 while [ `lxc_exec openmano instance-scenario-list ${instance_name} | grep ACTIVE | wc -l` -lt 7 ] ; do
126 [ $wait_active -gt 90 ] && echo "timeout waiting VM active" >&2 && echo_RO_log
&& exit 1
127 wait_active
=$
((wait_active
+ 1))
132 # Due to race condition the VIM request can be processed without getting the response by RO
133 # resulting in having some VM or net at VIM not registered by RO. If this is the case need to be deleted manually
134 vim_vms
=`lxc_exec RO/test/local/openvim/openvim vm-list | grep ${instance_name} | awk '{print $1}'`
135 for vim_vm
in $vim_vms ; do
136 if ! lxc_exec openmano instance-scenario-list
${instance_name} |
grep -q $vim_vm ; then
137 echo deleting VIM vm
$vim_vm
138 lxc_exec RO
/test
/local
/openvim
/openvim vm-delete
-f $vim_vm
141 vim_nets
=`lxc_exec RO/test/local/openvim/openvim net-list | grep ${instance_name} | awk '{print $1}'`
142 for vim_net
in $vim_nets ; do
143 if ! lxc_exec openmano instance-scenario-list
${instance_name} |
grep -q $vim_net ; then
144 echo deleting VIM net
$vim_net
145 lxc_exec RO
/test
/local
/openvim
/openvim net-delete
-f $vim_net
149 # delete first VIM VM and wait until RO detects it
150 echo test ${test_number}.1 test refresh VM VIM status deleted
151 OPENVIM_VM
=`lxc_exec RO/test/local/openvim/openvim vm-list`
152 OPENVIM_VM
=${OPENVIM_VM%% *}
153 lxc_exec RO
/test
/local
/openvim
/openvim vm-delete
-f $OPENVIM_VM
155 while ! lxc_exec openmano instance-scenario-list
${instance_name} |
grep -q DELETED
; do
157 [ $wait_active -gt 90 ] && echo "timeout waiting RO get VM status as DELETED" >&2 && echo_RO_log
&& exit 1
158 wait_active
=$
((wait_active
+ 1))
160 ACTIVE
=`lxc_exec openmano instance-scenario-list ${instance_name} | grep ACTIVE | wc -l`
164 # TEST service restart in the middle of a instantiation deletion
165 echo test ${test_number}.2 test isntantiation deletion recovering
166 lxc_exec openmano instance-scenario-delete
${instance_name} -f";"service osm-ro stop
168 lxc_exec service osm-ro start
170 # wait until all VM are deteled at VIM
173 test_number
=$
((test_number
+ 1))