| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 1 | /* Copyright ETSI Contributors and Others |
| 2 | * |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | * not use this file except in compliance with the License. You may obtain |
| 7 | * a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations |
| 15 | * under the License. |
| 16 | */ |
| 17 | |
| 18 | pipeline { |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 19 | parameters { |
| 20 | // string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER') |
| 21 | |
| 22 | // Parameters to define the specific OSM version to test |
| 23 | // --> Defaults to latest stable version of Release FOURTEEN |
| garciadeblas | e400dfd | 2023-12-12 21:53:43 +0100 | [diff] [blame^] | 24 | string(defaultValue: 'https://osm-download.etsi.org/ftp/osm-15.0-fifteen/install_osm.sh', description: 'URL to OSM installer', name: 'INSTALLER_URL') |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 25 | string(defaultValue: 'testing-daily', description: 'Release for OSM binaries (REPO_BASE)', name: 'REPO_BASE') |
| 26 | string(defaultValue: 'testing-daily', description: 'OSM docker tag (DOCKER_TAG)', name: 'DOCKER_TAG') |
| 27 | string(defaultValue: 'testing', description: 'Repository name for OSM packages (REPO_NAME)', name: 'REPO_NAME') |
| 28 | |
| 29 | // Parameters for docker run |
| 30 | string(defaultValue: 'opensourcemano/tests', description: 'Name of docker image for client-side of Robot tests', name: 'TEST_IMAGE') |
| 31 | string(defaultValue: 'testing-daily', description: 'Tag of docker image for client-side', name: 'TEST_TAG') |
| 32 | |
| 33 | // Parameters to define SSH keys (Jenkins secret) used when creating VMs |
| 34 | string(defaultValue: '', description: 'Jenkins credential containing SSH private key used in VMs', name: 'SSH_PRIVATE_KEY') |
| 35 | string(defaultValue: '', description: 'Jenkins credential containing SSH public key used in VMs', name: 'SSH_PUBLIC_KEY') |
| 36 | |
| 37 | // Parameter to set the target environment |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 38 | // Parameter to set the name of secret in Jenkins for Azure JSON credentials |
| 39 | string(defaultValue: 'azure-credentials', description: 'Jenkins secret that contains Azure JSON credentials', name: 'AZURE_CREDENTIALS') |
| 40 | // File format (take care of brackets in clientId): |
| 41 | // { |
| 42 | // "clientId": "{<client-id>}", |
| 43 | // "clientSecret": "<secret>", |
| 44 | // "subscriptionId": "<subscription-id>", |
| 45 | // "tenantId": "<tenant-id>", |
| 46 | // "activeDirectoryEndpointUrl": "https://login.microsoftonline.com", |
| 47 | // "resourceManagerEndpointUrl": "https://management.azure.com/", |
| 48 | // "activeDirectoryGraphResourceId": "https://graph.windows.net/", |
| 49 | // "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/", |
| 50 | // "galleryEndpointUrl": "https://gallery.azure.com/", |
| 51 | // "managementEndpointUrl": "https://management.core.windows.net/" |
| 52 | // } |
| 53 | |
| 54 | // Parameter to set the tag for selecting Robot test to be run |
| 55 | string(defaultValue: 'azure', description: 'Tag for selecting Robot test to be run', name: 'ROBOT_RUN_TAG') |
| 56 | |
| 57 | // Configuration of thresholds for Robot tests |
| 58 | string(defaultValue: '99.0', description: '% passed Robot tests to mark the build as passed', name: 'ROBOT_PASS_THRESHOLD') |
| 59 | string(defaultValue: '80.0', description: '% passed Robot tests to mark the build as unstable (if lower, it will be failed)', name: 'ROBOT_UNSTABLE_THRESHOLD') |
| 60 | } |
| 61 | environment { |
| 62 | // Azure environment |
| 63 | CLOUD_TYPE = 'azure' |
| 64 | SOURCE_IMAGE_NAME = 'Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest' |
| 65 | FLAVOR_NAME = 'Standard_D4as_v4' |
| 66 | K8S_FLAVOR_NAME = 'Standard_A2_v2' |
| 67 | USE_PAAS_K8S = 'FALSE' |
| 68 | PRIORITY = 'Regular' |
| 69 | RESOURCE_GROUP = 'OSM_CICD_GROUP' |
| 70 | VNET_NAME = 'OSM-CICD-net' |
| 71 | VIM_MGMT_NET = 'OSM-CICD-subnet' |
| 72 | VIM_TARGET = 'azure-etsi' |
| 73 | AZURE_FLAVORS_PATTERN = '^Standard' |
| 74 | AZURE_REGION = 'westeurope' |
| 75 | OSM_VIM_MULTIPLIER_TIMEOUT = '4.0' |
| 76 | |
| 77 | /* |
| 78 | // Openstack environment |
| 79 | CLOUD_TYPE = 'openstack' |
| 80 | OS_CLOUD = 'etsi-vim-telefonica' |
| 81 | OS_DOMAIN_NAME = 'Default' |
| 82 | VIM_TARGET = 'etsi-vim-telefonica' |
| 83 | VIM_MGMT_NET = 'osm-ext' |
| 84 | VIM_EXT_NET = 'osm-ext' |
| 85 | OVERRIDES = '--override-epa' |
| 86 | FLAVOR_NAME = 'osm.sanity' |
| 87 | SOURCE_IMAGE_NAME = 'ubuntu22.04' |
| 88 | SSH_KEY_NAME = 'niv2020' |
| 89 | SDNC_USER = 'karaf' |
| 90 | SDNC_PASSWORD = 'karaf' |
| 91 | SDNC_URL = 'http://172.21.248.11:8181' |
| 92 | SDNC_TYPE = 'onos_vpls' |
| 93 | |
| 94 | // Google Cloud environment |
| 95 | CLOUD_TYPE = 'gcp' |
| 96 | GCP_PROJECT = 'telcocloudpocs' |
| 97 | GCP_ZONE = 'europe-west1-b' |
| 98 | GCP_MACHINE_TYPE = 'e2-standard-4' |
| 99 | GCP_DISK_SIZE = '40' |
| 100 | GCP_IMAGE_PROJECT = 'ubuntu-os-cloud' |
| 101 | GCP_IMAGE_FAMILY = 'ubuntu-2204-lts' |
| 102 | VIM_TARGET = 'gcp' |
| 103 | VIM_MGMT_NET = 'default' |
| 104 | OSM_VIM_MULTIPLIER_TIMEOUT = '4.0' |
| 105 | */ |
| 106 | } |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 107 | agent { |
| 108 | docker { |
| 109 | label 'osm4' |
| 110 | image "${params.TEST_IMAGE}:${params.TEST_TAG}" |
| 111 | args "-u root:root --entrypoint=''" |
| 112 | } |
| 113 | } |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 114 | stages { |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 115 | stage('Set environment') { |
| 116 | steps { |
| 117 | script { |
| 118 | if (params.SSH_PUBLIC_KEY == '') { |
| 119 | // Gererate SSH private and public keys |
| 120 | sh "mkdir -m 700 ~/.ssh" |
| 121 | sh "ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''" |
| 122 | } |
| 123 | else { |
| 124 | // SSH private and public keys from Jenkins credentials |
| 125 | sh "mkdir -m 700 ~/.ssh" |
| 126 | withCredentials([file(credentialsId: "${params.SSH_PRIVATE_KEY}", variable: 'SSHPATH')]) { |
| 127 | sh "cp ${SSHPATH} ~/.ssh/id_rsa" |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 128 | } |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 129 | withCredentials([file(credentialsId: "${params.SSH_PUBLIC_KEY}", variable: 'SSHPATH')]) { |
| 130 | sh "cp ${SSHPATH} ~/.ssh/id_rsa.pub" |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 131 | } |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 132 | sh "chmod 400 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub" |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 133 | } |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 134 | // This file is used by some Robot test (BASIC12) |
| 135 | sh "cp ~/.ssh/id_rsa ~/osm_id_rsa" |
| 136 | sh "echo Reading credential ${params.AZURE_CREDENTIALS}" |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 137 | } |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 138 | // Azure credentials |
| 139 | withCredentials([file(credentialsId: "${params.AZURE_CREDENTIALS}", variable: 'FILE')]) { |
| 140 | sh "cp ${FILE} ~/azure-creds.json" |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 141 | sh """ |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 142 | set +x; \ |
| 143 | AZURE_CLIENT_ID=\$(cat ~/azure-creds.json | jq -r .clientId | sed s/[{}]//g) ; \ |
| 144 | AZURE_SECRET=\$(cat ~/azure-creds.json | jq -r .clientSecret) ; \ |
| 145 | AZURE_TENANT=\$(cat ~/azure-creds.json | jq -r .tenantId) ; \ |
| 146 | az login --service-principal --username \$AZURE_CLIENT_ID --password \$AZURE_SECRET --tenant \$AZURE_TENANT |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 147 | """ |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 148 | sh "az vm list -o table" |
| 149 | } |
| 150 | } |
| 151 | } |
| aguilard | bff5fd0 | 2023-11-17 07:53:43 +0000 | [diff] [blame] | 152 | stage('Create k8s cluster') { |
| 153 | steps { |
| 154 | sh "/robot-systest/cloud-scripts/create-k8s.sh" |
| 155 | sh "cat /robot-systest/results/k8s_environment.rc" |
| 156 | } |
| 157 | } |
| 158 | stage('Install OSM') { |
| 159 | steps { |
| 160 | sh "/robot-systest/cloud-scripts/create-osm-vm.sh" |
| 161 | sh "cat /robot-systest/results/osm_environment.rc" |
| 162 | sh ". /robot-systest/results/osm_environment.rc ; /robot-systest/cloud-scripts/remote-install-osm.sh" |
| 163 | } |
| 164 | } |
| 165 | stage('Add VIM and K8s cluster to OSM') { |
| 166 | steps { |
| 167 | sh """ |
| 168 | . /robot-systest/results/osm_environment.rc ; \ |
| 169 | . /robot-systest/results/k8s_environment.rc ; \ |
| 170 | osm version ; \ |
| 171 | set +x; \ |
| 172 | export AZURE_CLIENT_ID=\$(cat ~/azure-creds.json | jq -r .clientId | sed s/[{}]//g) ; \ |
| 173 | export AZURE_SECRET=\$(cat ~/azure-creds.json | jq -r .clientSecret) ; \ |
| 174 | export AZURE_TENANT=\$(cat ~/azure-creds.json | jq -r .tenantId) ; \ |
| 175 | export AZURE_SUBSCRIPTION_ID=\$(cat ~/azure-creds.json | jq -r .subscriptionId) ; \ |
| 176 | /robot-systest/cloud-scripts/add-vim-and-k8scluster.sh |
| 177 | """ |
| 178 | } |
| 179 | |
| 180 | } |
| 181 | stage('Run Robot tests') { |
| 182 | steps { |
| 183 | sh """ |
| 184 | . /robot-systest/results/osm_environment.rc ; \ |
| 185 | . /robot-systest/results/k8s_environment.rc ; \ |
| 186 | /robot-systest/run_test.sh -t ${params.ROBOT_RUN_TAG} |
| 187 | """ |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | post { |
| 192 | always { |
| 193 | echo "Retrieve container logs" |
| 194 | sh """ |
| 195 | . /robot-systest/results/osm_environment.rc ; \ |
| 196 | /robot-systest/cloud-scripts/remote-extract-logs.sh |
| 197 | """ |
| 198 | |
| 199 | echo "Save results" |
| 200 | sh "rm -rf results" |
| 201 | sh "cp -var /robot-systest/results /robot-systest/reports/* ." |
| 202 | archiveArtifacts artifacts: 'results/**/*', fingerprint: true |
| 203 | |
| 204 | echo "Updates the Robot dashboard in Jenkins" |
| 205 | robot outputPath: '.', passThreshold: "${params.ROBOT_PASS_THRESHOLD}", unstableThreshold: "${params.ROBOT_UNSTABLE_THRESHOLD}" |
| 206 | |
| 207 | echo "Destroy the K8s cluster" |
| 208 | sh '. /robot-systest/results/k8s_environment.rc ; /robot-systest/cloud-scripts/delete-k8s.sh' |
| 209 | |
| 210 | echo "Destroy the OSM host" |
| 211 | sh '. /robot-systest/results/osm_environment.rc ; /robot-systest/cloud-scripts/delete-osm-vm.sh' |
| 212 | sh "az vm list -o table" |
| 213 | } |
| aguilard | 22efe2b | 2023-11-13 13:11:05 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |