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