| tierno | 5fd09ae | 2017-10-24 07:20:44 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## |
| tierno | 9202102 | 2018-09-12 16:29:23 +0200 | [diff] [blame] | 4 | # Copyright 2017 Telefonica Investigacion y Desarrollo, S.A.U. |
| tierno | 5fd09ae | 2017-10-24 07:20:44 +0200 | [diff] [blame] | 5 | # This file is part of OSM |
| 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 | ## |
| 21 | |
| 22 | # Author: Alfonso Tierno (alfonso.tiernosepulveda@telefonica.com) |
| 23 | |
| 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" |
| 26 | |
| 27 | usage(){ |
| 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." |
| 38 | } |
| 39 | |
| 40 | [ "$1" = "--help" ] || [ "$1" = "-h" ] && usage && exit 0 |
| 41 | |
| 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" |
| 44 | |
| 45 | [ -n "$1" ] && TEST_RO_CONTAINER="$1" |
| 46 | [[ -z "$TEST_RO_CONTAINER" ]] && TEST_RO_CONTAINER=test1 |
| 47 | |
| 48 | instance_name=3vdu_2vnf |
| 49 | |
| 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 |
| 53 | } |
| 54 | |
| 55 | function lxc_exec(){ |
| 56 | if ! lxc exec "$TEST_RO_CONTAINER" --env OPENMANO_TENANT=osm --env OPENMANO_DATACENTER=local-openvim \ |
| 57 | --env OPENVIM_TENANT="$OPENVIM_TENANT" -- bash -c "$*" |
| 58 | then |
| 59 | echo "ERROR on command '$*'" >&2 |
| 60 | echo_RO_log |
| 61 | exit 1 |
| 62 | fi |
| 63 | } |
| 64 | |
| 65 | function wait_until_deleted(){ |
| 66 | wait_active=0 |
| 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} |
| 69 | do |
| 70 | echo -n "." |
| 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)) |
| 73 | sleep 1 |
| 74 | done |
| 75 | echo |
| 76 | } |
| 77 | |
| 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" |
| 80 | sleep 10 |
| 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" |
| 86 | |
| 87 | # TEST INSTALL |
| tierno | 16e3dd4 | 2018-04-24 12:52:40 +0200 | [diff] [blame] | 88 | lxc_exec RO/scripts/install-openmano.sh --noclone --force -q --updatedb -b master |
| tierno | 5fd09ae | 2017-10-24 07:20:44 +0200 | [diff] [blame] | 89 | sleep 10 |
| 90 | lxc_exec openmano tenant-create osm |
| 91 | lxc_exec openmano tenant-list |
| 92 | |
| 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 |
| 98 | |
| 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 |
| 101 | |
| 102 | |
| 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 |
| 106 | |
| 107 | sleep 10 |
| 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%% *} |
| 111 | |
| 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 |
| 114 | wait_until_deleted |
| 115 | test_number=0 |
| 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 |
| 119 | sleep 5 |
| 120 | lxc_exec service osm-ro start |
| 121 | sleep 10 |
| 122 | # wait until all VM are active |
| 123 | wait_active=0 |
| 124 | while [ `lxc_exec openmano instance-scenario-list ${instance_name} | grep ACTIVE | wc -l` -lt 7 ] ; do |
| 125 | echo -n "." |
| 126 | [ $wait_active -gt 90 ] && echo "timeout waiting VM active" >&2 && echo_RO_log && exit 1 |
| 127 | wait_active=$((wait_active + 1)) |
| 128 | sleep 1 |
| 129 | done |
| 130 | echo |
| 131 | |
| 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 |
| 139 | fi |
| 140 | done |
| 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 |
| 146 | fi |
| 147 | done |
| 148 | |
| 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 |
| 154 | wait_active=0 |
| 155 | while ! lxc_exec openmano instance-scenario-list ${instance_name} | grep -q DELETED ; do |
| 156 | echo -n "." |
| 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)) |
| 159 | sleep 1 |
| 160 | ACTIVE=`lxc_exec openmano instance-scenario-list ${instance_name} | grep ACTIVE | wc -l` |
| 161 | done |
| 162 | echo |
| 163 | |
| 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 |
| 167 | sleep 5 |
| 168 | lxc_exec service osm-ro start |
| 169 | sleep 10 |
| 170 | # wait until all VM are deteled at VIM |
| 171 | wait_until_deleted |
| 172 | |
| 173 | test_number=$((test_number + 1)) |
| 174 | done |
| 175 | echo "DONE" |
| 176 | |
| 177 | |