| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ## |
| 4 | # Copyright 2020 ATOS |
| 5 | # |
| 6 | # All Rights Reserved. |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain 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, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | ## |
| 20 | |
| 21 | cat /dev/zero | ssh-keygen -q -N "" > /dev/null |
| 22 | |
| 23 | install_osmclient(){ |
| 24 | echo -e "\nInstalling osmclient ${OSMCLIENT}" |
| 25 | python3 -m pip install git+https://osm.etsi.org/gerrit/osm/osmclient@${OSMCLIENT} |
| 26 | } |
| 27 | |
| 28 | download_packages(){ |
| 29 | echo -e "\nDownloading packages ${PACKAGES}" |
| 30 | rm -rf ${PACKAGES_FOLDER} |
| 31 | git clone https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages.git ${PACKAGES_FOLDER} && (cd ${PACKAGES_FOLDER} && \ |
| garciaale | 82f05de | 2020-12-01 12:29:31 -0300 | [diff] [blame] | 32 | git checkout sol006) |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 35 | download_tst010(){ |
| 36 | # Fetch conformance tests |
| 37 | git clone --single-branch --branch ${NFV_TESTS_BRANCH} https://forge.etsi.org/rep/nfv/api-tests.git /robot-systest/conformance-tests/repo |
| 38 | python3 -m pip install -r /robot-systest/conformance-tests/repo/requirements.txt |
| 39 | } |
| 40 | |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 41 | create_vim(){ |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 42 | |
| 43 | attempts=3 |
| 44 | while [ $attempts -ge 0 ] ; do |
| 45 | echo -e "\n$( date '+%F_%H:%M:%S' ) Creating VIM ${VIM_TARGET}" |
| 46 | osm vim-create --name ${VIM_TARGET} --user ${OS_USERNAME} --password ${OS_PASSWORD} --tenant ${OS_PROJECT_NAME} \ |
| 47 | --auth_url ${OS_AUTH_URL} --account_type openstack --description vim \ |
| 48 | --config "{management_network_name: ${VIM_MGMT_NET}, dataplane_physical_net: ${DATAPLANE:-physnet2}}" || true |
| beierlm | 6cc2bd1 | 2020-12-03 11:44:47 -0500 | [diff] [blame] | 49 | STATUS="" |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 50 | i=0 |
| 51 | while [[ ${STATUS} != "ENABLED" ]] |
| 52 | do |
| 53 | ((i++)) |
| 54 | if [[ $i -eq 5 ]]; then |
| beierlm | 6cc2bd1 | 2020-12-03 11:44:47 -0500 | [diff] [blame] | 55 | echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}" |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 56 | osm vim-delete --force ${VIM_TARGET} |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 57 | sleep 5 |
| 58 | break |
| 59 | fi |
| 60 | sleep 10 |
| beierlm | 1d535af | 2020-12-03 09:28:28 -0500 | [diff] [blame] | 61 | VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}` |
| 62 | echo VIM status: ${VIM_LIST} |
| beierlm | 6cc2bd1 | 2020-12-03 11:44:47 -0500 | [diff] [blame] | 63 | STATUS=`echo ${VIM_LIST} | grep -io ENABLED` |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 64 | done |
| 65 | if [[ ${STATUS} = "ENABLED" ]] ; then |
| 66 | break |
| Felipe Vicens | 02300c0 | 2020-07-02 12:19:28 +0200 | [diff] [blame] | 67 | fi |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 68 | ((attempts--)) |
| Felipe Vicens | 02300c0 | 2020-07-02 12:19:28 +0200 | [diff] [blame] | 69 | done |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 70 | if [ $attempts -lt 0 ] ; then |
| 71 | echo "VIM failed to enter ENABLED state" |
| 72 | exit 1 |
| 73 | fi |
| garciadeblas | 4bcd715 | 2021-04-14 16:45:24 +0200 | [diff] [blame] | 74 | if [ -n "${SDNC_URL}" ]; then |
| 75 | osm sdnc-create --name sdnc-osm --type ${SDNC_TYPE} --user ${SDNC_USER} --password ${SDNC_PASSWORD} --url ${SDNC_URL} |
| 76 | COUNTER=0 |
| 77 | STATUS="" |
| 78 | while [ ${COUNTER} -lt 5 ] ; do |
| 79 | echo "Checking status of SDNC sdnc-osm to see if it is enabled" |
| 80 | STATUS=$(osm sdnc-show sdnc-osm |grep -io ENABLED) |
| 81 | if [ "${STATUS}" == "ENABLED" ]; then |
| 82 | break |
| 83 | fi |
| 84 | ((COUNTER++)) |
| 85 | sleep 10 |
| 86 | done |
| 87 | if [ "${STATUS}" == "ENABLED" ]; then |
| 88 | echo "SDNC enabled" |
| 89 | else |
| 90 | echo "SDNC failed to enter ENABLED state" |
| 91 | osm sdnc-show sdnc-osm |
| 92 | exit 1 |
| 93 | fi |
| 94 | if [ -f /root/port-mapping.yaml ]; then |
| 95 | osm vim-update ${VIM_TARGET} --sdn_controller sdnc-osm --sdn_port_mapping /root/port-mapping.yaml |
| 96 | COUNTER2=0 |
| 97 | RESULT="" |
| 98 | while [ ${COUNTER2} -lt 5 ] ; do |
| 99 | echo "Checking status of VIM $VIM_TARGET to see if there is port-mapping" |
| 100 | osm vim-show $VIM_TARGET |grep sdn-port-mapping |
| 101 | if [ $? -eq 0 ]; then |
| 102 | RESULT="OK" |
| 103 | break |
| 104 | fi |
| 105 | ((COUNTER2++)) |
| 106 | sleep 10 |
| 107 | done |
| 108 | if [ "${RESULT}" == "OK" ]; then |
| 109 | echo "Port-mapping correctly added" |
| 110 | else |
| 111 | echo "Port-mapping failed to be added" |
| 112 | osm vim-show ${VIM_TARGET} |
| 113 | exit 1 |
| 114 | fi |
| 115 | fi |
| 116 | fi |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 119 | |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 120 | PARAMS="" |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 121 | RUN_CONFORMANCE_TESTS=false |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 122 | |
| 123 | while (( "$#" )); do |
| 124 | case "$1" in |
| 125 | -t|--testingtags) |
| 126 | TEST=$2 |
| 127 | shift 2 |
| 128 | ;; |
| 129 | -p|--packagesbranch) |
| 130 | PACKAGES=$2 && download_packages |
| 131 | shift 2 |
| 132 | ;; |
| 133 | -o|--osmclientversion) |
| Felipe Vicens | 24e3d15 | 2020-06-25 21:52:06 +0200 | [diff] [blame] | 134 | OSMCLIENT=$2 && install_osmclient |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 135 | shift 2 |
| 136 | ;; |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 137 | -c|--createvim) |
| 138 | create_vim |
| 139 | shift 1 |
| 140 | ;; |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 141 | -T) |
| 142 | NFV_TESTS_BRANCH=$2 && download_tst010 |
| 143 | RUN_CONFORMANCE_TESTS=true |
| 144 | shift 1 |
| 145 | ;; |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 146 | -h|--help) |
| 147 | echo "OSM TESTS TOOL |
| 148 | |
| 149 | Usage: |
| 150 | docker run --rm=true -t osmtests --env-file <env_file> \\ |
| Felipe Vicens | 5c54d27 | 2020-06-23 15:55:08 +0200 | [diff] [blame] | 151 | -v <path_to_reports>:/reports osmtests \\ |
| 152 | -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\ |
| 153 | -v <path_to_kubeconfig>:/root/.kube/config \\ |
| 154 | -o <osmclient_version> \\ |
| 155 | -p <package_branch> \\ |
| 156 | -t <testing_tags> |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 157 | |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 158 | Options: |
| 159 | --env-file: It is the environmental file where is described the OSM target and VIM |
| 160 | -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest |
| 161 | -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master |
| 162 | -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, regression, particular_test]. Default: sanity |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 163 | -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 164 | -c To create a VIM for the tests |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 165 | |
| 166 | Volumes: |
| 167 | <path_to_reports> [OPTIONAL]: It is the absolute path to reports location in the host |
| Felipe Vicens | 5c54d27 | 2020-06-23 15:55:08 +0200 | [diff] [blame] | 168 | <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host |
| 169 | <path_to_kubeconfig> [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters" |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 170 | |
| 171 | exit 0 |
| 172 | ;; |
| 173 | -*|--*=) |
| 174 | echo "Error: Unsupported flag $1" >&2 |
| 175 | exit 1 |
| 176 | ;; |
| 177 | *) |
| 178 | PARAMS="$PARAMS $1" |
| 179 | shift |
| 180 | ;; |
| 181 | esac |
| 182 | done |
| 183 | |
| 184 | eval set -- "$PARAMS" |
| 185 | |
| Felipe Vicens | 24e3d15 | 2020-06-25 21:52:06 +0200 | [diff] [blame] | 186 | if [[ -n "$BRANCH_NAME" ]]; then |
| 187 | PACKAGES=$BRANCH_NAME && download_packages |
| 188 | OSMCLIENT=$BRANCH_NAME && install_osmclient |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 189 | fi |
| 190 | |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 191 | |
| 192 | if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then |
| 193 | python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py |
| 194 | fi |
| 195 | |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 196 | if [[ -z "${TEST}" ]]; then |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 197 | printf "Test not provided. \nRunning default test: sanity\n" |
| 198 | TEST="sanity" |
| 199 | fi |
| 200 | |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 201 | if [[ -n "${TEST}" ]]; then |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 202 | robot -d ${ROBOT_DEVOPS_FOLDER}/reports -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/ |
| 203 | exit 0 |
| 204 | else |
| 205 | echo "Wrong test provided" |
| 206 | exit 1 |
| 207 | fi |
| 208 | |
| 209 | exit 1 |