| 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 | |
| garciadeblas | 730b2f7 | 2026-01-29 18:00:41 +0100 | [diff] [blame] | 21 | cat /dev/zero | ssh-keygen -t rsa -q -N "" > /dev/null |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 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} |
| garciadeblas | 28ce11e | 2021-03-02 16:15:17 +0000 | [diff] [blame] | 31 | git clone https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages.git ${PACKAGES_FOLDER} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 32 | } |
| 33 | |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 34 | download_tst010(){ |
| 35 | # Fetch conformance tests |
| 36 | git clone --single-branch --branch ${NFV_TESTS_BRANCH} https://forge.etsi.org/rep/nfv/api-tests.git /robot-systest/conformance-tests/repo |
| veleza | 12ed0f5 | 2021-12-07 08:29:34 +0000 | [diff] [blame] | 37 | #python3 -m pip install -r /robot-systest/conformance-tests/repo/requirements.txt |
| 38 | python3 -m pip install -r /robot-systest/conformance-tests/requirements.txt |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 41 | |
| Mark Beierl | 9e36736 | 2022-12-09 10:20:45 -0500 | [diff] [blame] | 42 | create_k8scluster(){ |
| 43 | attempts=3 |
| 44 | while [ $attempts -ge 0 ] ; do |
| 45 | echo -e "\n$( date '+%F_%H:%M:%S' ) Creating K8s Cluster" |
| 46 | |
| garciadeblas | 4791774 | 2023-11-27 16:50:01 +0100 | [diff] [blame] | 47 | osm k8scluster-add --creds ${K8S_CREDENTIALS} --version "v1" --vim ${VIM_TARGET} --k8s-nets "{\"net1\": \"${VIM_MGMT_NET}\"}" ${VIM_TARGET} --description "Robot cluster" --skip-jujubundle |
| Mark Beierl | 9e36736 | 2022-12-09 10:20:45 -0500 | [diff] [blame] | 48 | |
| 49 | STATUS="" |
| 50 | i=0 |
| 51 | while [[ ${STATUS} != "ENABLED" ]] |
| 52 | do |
| 53 | ((i++)) |
| 54 | if [[ $i -eq 5 ]]; then |
| 55 | echo "K8s cluster stuck for more than 50 seconds:" |
| 56 | osm k8scluster-show ${VIM_TARGET} |
| 57 | osm k8scluster-delete ${VIM_TARGET} |
| 58 | sleep 5 |
| 59 | break |
| 60 | fi |
| 61 | sleep 10 |
| 62 | STATUS=`osm k8scluster-list | grep ${VIM_TARGET} | awk '{print $8}'` |
| 63 | done |
| 64 | if [[ ${STATUS} = "ENABLED" ]] ; then |
| 65 | break |
| 66 | fi |
| 67 | ((attempts--)) |
| 68 | done |
| 69 | if [ $attempts -lt 0 ] ; then |
| garciadeblas | c753f67 | 2023-05-18 15:06:49 +0200 | [diff] [blame] | 70 | echo "K8s cluster failed to enter ENABLED state" |
| Mark Beierl | 9e36736 | 2022-12-09 10:20:45 -0500 | [diff] [blame] | 71 | exit 1 |
| 72 | fi |
| 73 | } |
| 74 | |
| 75 | create_vim(){ |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 76 | attempts=3 |
| 77 | while [ $attempts -ge 0 ] ; do |
| 78 | echo -e "\n$( date '+%F_%H:%M:%S' ) Creating VIM ${VIM_TARGET}" |
| 79 | osm vim-create --name ${VIM_TARGET} --user ${OS_USERNAME} --password ${OS_PASSWORD} --tenant ${OS_PROJECT_NAME} \ |
| 80 | --auth_url ${OS_AUTH_URL} --account_type openstack --description vim \ |
| 81 | --config "{management_network_name: ${VIM_MGMT_NET}, dataplane_physical_net: ${DATAPLANE:-physnet2}}" || true |
| beierlm | 6cc2bd1 | 2020-12-03 11:44:47 -0500 | [diff] [blame] | 82 | STATUS="" |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 83 | i=0 |
| 84 | while [[ ${STATUS} != "ENABLED" ]] |
| 85 | do |
| 86 | ((i++)) |
| 87 | if [[ $i -eq 5 ]]; then |
| beierlm | 6cc2bd1 | 2020-12-03 11:44:47 -0500 | [diff] [blame] | 88 | echo "VIM stuck for more than 50 seconds as: ${VIM_LIST}" |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 89 | osm vim-delete --force ${VIM_TARGET} |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 90 | sleep 5 |
| 91 | break |
| 92 | fi |
| 93 | sleep 10 |
| beierlm | 1d535af | 2020-12-03 09:28:28 -0500 | [diff] [blame] | 94 | VIM_LIST=`osm vim-list --long | grep ${VIM_TARGET}` |
| 95 | echo VIM status: ${VIM_LIST} |
| beierlm | 6cc2bd1 | 2020-12-03 11:44:47 -0500 | [diff] [blame] | 96 | STATUS=`echo ${VIM_LIST} | grep -io ENABLED` |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 97 | done |
| 98 | if [[ ${STATUS} = "ENABLED" ]] ; then |
| 99 | break |
| Felipe Vicens | 02300c0 | 2020-07-02 12:19:28 +0200 | [diff] [blame] | 100 | fi |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 101 | ((attempts--)) |
| Felipe Vicens | 02300c0 | 2020-07-02 12:19:28 +0200 | [diff] [blame] | 102 | done |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 103 | if [ $attempts -lt 0 ] ; then |
| 104 | echo "VIM failed to enter ENABLED state" |
| 105 | exit 1 |
| 106 | fi |
| garciadeblas | 9f608b1 | 2024-01-23 14:27:30 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
| 110 | create_sdnc(){ |
| garciadeblas | 419af64 | 2021-04-14 16:45:24 +0200 | [diff] [blame] | 111 | if [ -n "${SDNC_URL}" ]; then |
| 112 | osm sdnc-create --name sdnc-osm --type ${SDNC_TYPE} --user ${SDNC_USER} --password ${SDNC_PASSWORD} --url ${SDNC_URL} |
| 113 | COUNTER=0 |
| 114 | STATUS="" |
| 115 | while [ ${COUNTER} -lt 5 ] ; do |
| 116 | echo "Checking status of SDNC sdnc-osm to see if it is enabled" |
| 117 | STATUS=$(osm sdnc-show sdnc-osm |grep -io ENABLED) |
| 118 | if [ "${STATUS}" == "ENABLED" ]; then |
| 119 | break |
| 120 | fi |
| 121 | ((COUNTER++)) |
| 122 | sleep 10 |
| 123 | done |
| 124 | if [ "${STATUS}" == "ENABLED" ]; then |
| 125 | echo "SDNC enabled" |
| 126 | else |
| 127 | echo "SDNC failed to enter ENABLED state" |
| 128 | osm sdnc-show sdnc-osm |
| 129 | exit 1 |
| 130 | fi |
| 131 | if [ -f /root/port-mapping.yaml ]; then |
| 132 | osm vim-update ${VIM_TARGET} --sdn_controller sdnc-osm --sdn_port_mapping /root/port-mapping.yaml |
| 133 | COUNTER2=0 |
| 134 | RESULT="" |
| 135 | while [ ${COUNTER2} -lt 5 ] ; do |
| 136 | echo "Checking status of VIM $VIM_TARGET to see if there is port-mapping" |
| 137 | osm vim-show $VIM_TARGET |grep sdn-port-mapping |
| 138 | if [ $? -eq 0 ]; then |
| 139 | RESULT="OK" |
| 140 | break |
| 141 | fi |
| 142 | ((COUNTER2++)) |
| 143 | sleep 10 |
| 144 | done |
| 145 | if [ "${RESULT}" == "OK" ]; then |
| 146 | echo "Port-mapping correctly added" |
| 147 | else |
| 148 | echo "Port-mapping failed to be added" |
| 149 | osm vim-show ${VIM_TARGET} |
| 150 | exit 1 |
| 151 | fi |
| 152 | fi |
| 153 | fi |
| garciadeblas | 9f608b1 | 2024-01-23 14:27:30 +0100 | [diff] [blame] | 154 | |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| beierlm | 9fc2b84 | 2020-06-26 14:57:09 -0400 | [diff] [blame] | 157 | |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 158 | PARAMS="" |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 159 | RUN_CONFORMANCE_TESTS=false |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 160 | |
| 161 | while (( "$#" )); do |
| 162 | case "$1" in |
| 163 | -t|--testingtags) |
| 164 | TEST=$2 |
| 165 | shift 2 |
| 166 | ;; |
| 167 | -p|--packagesbranch) |
| 168 | PACKAGES=$2 && download_packages |
| 169 | shift 2 |
| 170 | ;; |
| 171 | -o|--osmclientversion) |
| Felipe Vicens | 24e3d15 | 2020-06-25 21:52:06 +0200 | [diff] [blame] | 172 | OSMCLIENT=$2 && install_osmclient |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 173 | shift 2 |
| 174 | ;; |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 175 | -c|--createvim) |
| 176 | create_vim |
| garciadeblas | d770607 | 2024-01-23 14:30:54 +0100 | [diff] [blame] | 177 | # create_sdnc |
| Mark Beierl | 9e36736 | 2022-12-09 10:20:45 -0500 | [diff] [blame] | 178 | create_k8scluster |
| Felipe Vicens | 55b6158 | 2020-06-24 21:23:44 +0200 | [diff] [blame] | 179 | shift 1 |
| 180 | ;; |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 181 | -T) |
| 182 | NFV_TESTS_BRANCH=$2 && download_tst010 |
| 183 | RUN_CONFORMANCE_TESTS=true |
| 184 | shift 1 |
| 185 | ;; |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 186 | -h|--help) |
| 187 | echo "OSM TESTS TOOL |
| 188 | |
| 189 | Usage: |
| 190 | docker run --rm=true -t osmtests --env-file <env_file> \\ |
| Felipe Vicens | 5c54d27 | 2020-06-23 15:55:08 +0200 | [diff] [blame] | 191 | -v <path_to_reports>:/reports osmtests \\ |
| 192 | -v <path_to_clouds.yaml>:/robot-systest/clouds.yaml \\ |
| 193 | -v <path_to_kubeconfig>:/root/.kube/config \\ |
| 194 | -o <osmclient_version> \\ |
| 195 | -p <package_branch> \\ |
| 196 | -t <testing_tags> |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 197 | |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 198 | Options: |
| 199 | --env-file: It is the environmental file where is described the OSM target and VIM |
| 200 | -o <osmclient_version> [OPTIONAL]: It is used to specify a particular osmclient version. Default: latest |
| 201 | -p <package_branch> [OPTIONAL]: OSM packages repository branch. Default: master |
| garciadeblas | 4cf45d7 | 2021-04-08 13:52:22 +0200 | [diff] [blame] | 202 | -t <testing_tags> [OPTIONAL]: Robot tests tags. [sanity, daily, regression, particular_test]. Default: sanity |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 203 | -T <testing_branch> [OPTIONAL]: Run SOL005 Robot conformance tests |
| Mark Beierl | 9e36736 | 2022-12-09 10:20:45 -0500 | [diff] [blame] | 204 | -c To create a VIM and K8s cluster for the tests |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 205 | |
| 206 | Volumes: |
| 207 | <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] | 208 | <path_to_clouds.yaml> [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host |
| aktas | 8e0504f | 2021-09-06 13:23:35 +0300 | [diff] [blame] | 209 | <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] | 210 | |
| 211 | exit 0 |
| 212 | ;; |
| 213 | -*|--*=) |
| 214 | echo "Error: Unsupported flag $1" >&2 |
| 215 | exit 1 |
| 216 | ;; |
| 217 | *) |
| 218 | PARAMS="$PARAMS $1" |
| 219 | shift |
| 220 | ;; |
| 221 | esac |
| 222 | done |
| 223 | |
| 224 | eval set -- "$PARAMS" |
| 225 | |
| Felipe Vicens | 24e3d15 | 2020-06-25 21:52:06 +0200 | [diff] [blame] | 226 | if [[ -n "$BRANCH_NAME" ]]; then |
| 227 | PACKAGES=$BRANCH_NAME && download_packages |
| 228 | OSMCLIENT=$BRANCH_NAME && install_osmclient |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 229 | fi |
| 230 | |
| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 231 | |
| 232 | if [ "$RUN_CONFORMANCE_TESTS" = true ] ; then |
| 233 | python3 ${ROBOT_DEVOPS_FOLDER}/conformance-tests/run_conformance_tests.py |
| 234 | fi |
| 235 | |
| Felipe Vicens | 6366c68 | 2020-06-25 20:12:16 +0200 | [diff] [blame] | 236 | if [[ -n "${TEST}" ]]; then |
| garciadeblas | abf7cad | 2025-06-26 08:51:14 +0200 | [diff] [blame] | 237 | robot --legacy-output -d ${ROBOT_DEVOPS_FOLDER}/reports --tagstatinclude "cluster_*" -i ${TEST} ${ROBOT_DEVOPS_FOLDER}/testsuite/ |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 238 | else |
| garciadeblas | 6373cc9 | 2023-05-23 11:17:09 +0200 | [diff] [blame] | 239 | echo "No test was provided. Exiting..." |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 240 | fi |
| 241 | |
| garciadeblas | 6373cc9 | 2023-05-23 11:17:09 +0200 | [diff] [blame] | 242 | exit 0 |