Run stage_3 install in new VM
[osm/devops.git] / jenkins / ci-pipelines / ci_stage_3.groovy
1 /* Copyright 2017 Sandvine
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 properties([
19     parameters([
20         string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH'),
21         string(defaultValue: 'system', description: '', name: 'NODE'),
22         string(defaultValue: '', description: '', name: 'BUILD_FROM_SOURCE'),
23         string(defaultValue: 'unstable', description: '', name: 'REPO_DISTRO'),
24         string(defaultValue: '', description: '', name: 'COMMIT_ID'),
25         string(defaultValue: '-stage_2', description: '', name: 'UPSTREAM_SUFFIX'),
26         string(defaultValue: 'pubkey.asc', description: '', name: 'REPO_KEY_NAME'),
27         string(defaultValue: 'release', description: '', name: 'RELEASE'),
28         string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NAME'),
29         string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NUMBER'),
30         string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NUMBER'),
31         string(defaultValue: 'OSMETSI', description: '', name: 'GPG_KEY_NAME'),
32         string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
33         string(defaultValue: 'osm-stage_4', description: '', name: 'DOWNSTREAM_STAGE_NAME'),
34         string(defaultValue: 'testing-daily', description: '', name: 'DOCKER_TAG'),
35         booleanParam(defaultValue: true, description: '', name: 'SAVE_CONTAINER_ON_FAIL'),
36         booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_PASS'),
37         booleanParam(defaultValue: true, description: '', name: 'SAVE_ARTIFACTS_ON_SMOKE_SUCCESS'),
38         booleanParam(defaultValue: true, description: '', name: 'DO_STAGE_4'),
39         booleanParam(defaultValue: true, description: '',  name: 'DO_BUILD'),
40         booleanParam(defaultValue: true, description: '', name: 'DO_INSTALL'),
41         booleanParam(defaultValue: true, description: '', name: 'DO_SMOKE'),
42         booleanParam(defaultValue: true, description: '', name: 'DO_DOCKERPUSH'),
43         booleanParam(defaultValue: false, description: '', name: 'SAVE_ARTIFACTS_OVERRIDE'),
44         string(defaultValue: '/home/jenkins/hive/openstack-etsi.rc', description: '', name: 'HIVE_VIM_1'),
45         booleanParam(defaultValue: false, description: '', name: 'DO_ROBOT'),
46         string(defaultValue: 'sanity', description: 'sanity/regression are the options', name: 'TEST_NAME'),
47         string(defaultValue: '/home/jenkins/hive/robot-systest.cfg', description: '', name: 'ROBOT_VIM'),
48         string(defaultValue: '/home/jenkins/hive/kubeconfig.yaml', description: '', name: 'KUBECONFIG'),
49         string(defaultValue: '/home/jenkins/hive/clouds.yaml', description: '', name: 'CLOUDS'),
50         string(defaultValue: 'Charmed', description: '', name: 'INSTALLER'),
51     ])
52 ])
53
54 def uninstall_osm(stackName) {
55     sh """
56          export OSM_USE_LOCAL_DEVOPS=true
57          export PATH=$PATH:/snap/bin
58          installers/full_install_osm.sh -y -w /tmp/osm -t ${stackName} -s ${stackName} --test --nolxd --nodocker --nojuju --nohostports --nohostclient --uninstall
59        """
60 }
61
62 def run_systest(stackName,tagName,testName,envfile=null) {
63     tempdir = sh(returnStdout: true, script: "mktemp -d").trim()
64     if ( !envfile )
65     {
66         sh(script: "touch ${tempdir}/env")
67         envfile="${tempdir}/env"
68     }
69     sh "docker run --network net${stackName} --env-file ${envfile} -v ${tempdir}:/usr/share/osm-devops/systest/reports opensourcemano/osmclient:${tagName} make -C /usr/share/osm-devops/systest ${testName}"
70     sh "cp ${tempdir}/* ."
71     junit  '*.xml'
72 }
73
74 def run_robot_systest(tagName,testName,osmHostname,prometheusHostname,prometheus_port=null,envfile=null,kubeconfig=null,clouds=null,hostfile=null) {
75     tempdir = sh(returnStdout: true, script: "mktemp -d").trim()
76     if ( !envfile )
77     {
78         sh(script: "touch ${tempdir}/env")
79         envfile="${tempdir}/env"
80     }
81     PROMETHEUS_PORT_VAR = ""
82     if ( prometheusPort != null) {
83         PROMETHEUS_PORT_VAR = "--env PROMETHEUS_PORT="+prometheusPort
84     }
85     hostfilemount=""
86     if ( hostfile ) {
87         hostfilemount="-v "+hostfile+":/etc/hosts"
88     }
89
90     try {
91         sh "docker run --env OSM_HOSTNAME=${osmHostname} --env PROMETHEUS_HOSTNAME=${prometheusHostname} ${PROMETHEUS_PORT_VAR} --env-file ${envfile} -v ${clouds}:/etc/openstack/clouds.yaml -v ${kubeconfig}:/root/.kube/config -v ${tempdir}:/robot-systest/reports ${hostfilemount} opensourcemano/tests:${tagName} -c -t ${testName}"
92     } finally {
93         sh "cp ${tempdir}/* ."
94         outputDirectory = sh(returnStdout: true, script: "pwd").trim()
95         println ("Present Directory is : ${outputDirectory}")
96         step([
97             $class : 'RobotPublisher',
98             outputPath : "${outputDirectory}",
99             outputFileName : "*.xml",
100             disableArchiveOutput : false,
101             reportFileName : "report.html",
102             logFileName : "log.html",
103             passThreshold : 0,
104             unstableThreshold: 0,
105             otherFiles : "*.png",
106         ])
107     }
108 }
109
110 def archive_logs(remote) {
111
112     sshCommand remote: remote, command: '''mkdir -p logs'''
113     if (useCharmedInstaller) {
114         sshCommand remote: remote, command: '''
115             for container in `kubectl get pods -n osm | grep -v operator | grep -v NAME| awk '{print $1}'`; do
116                 logfile=`echo $container | cut -d- -f1`
117                 echo "Extracting log for $logfile"
118                 kubectl logs -n osm $container 2>&1 > logs/$logfile.log
119             done
120         '''
121     } else {
122         // collect logs from k8s based installer...
123     }
124
125     sh "rm -rf logs"
126     sshCommand remote: remote, command: '''ls -al logs'''
127     sshGet remote: remote, from: 'logs', into: '.', override: true
128     sh "cp logs/* ."
129     archiveArtifacts artifacts: '*.log'
130 }
131
132 def get_value(key, output) {
133     for (String line : output.split( '\n' )) {
134         data = line.split( '\\|' )
135         if (data.length > 1) {
136             if ( data[1].trim() == key ) {
137                 return data[2].trim()
138             }
139         }
140     }
141 }
142
143 node("${params.NODE}") {
144
145     INTERNAL_DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/'
146     SSH_KEY = '~/hive/cicd_rsa'
147     sh 'env'
148
149     tag_or_branch = params.GERRIT_BRANCH.replaceAll(/\./,"")
150
151     stage("Checkout") {
152         checkout scm
153     }
154
155     ci_helper = load "jenkins/ci-pipelines/ci_helper.groovy"
156
157     def upstream_main_job = params.UPSTREAM_SUFFIX
158
159     // upstream jobs always use merged artifacts
160     upstream_main_job += '-merge'
161     container_name_prefix = "osm-${tag_or_branch}"
162     container_name = "${container_name_prefix}"
163
164     keep_artifacts = false
165     if ( JOB_NAME.contains('merge') ) {
166         container_name += "-merge"
167
168         // On a merge job, we keep artifacts on smoke success
169         keep_artifacts = params.SAVE_ARTIFACTS_ON_SMOKE_SUCCESS
170     }
171     container_name += "-${BUILD_NUMBER}"
172
173     // Copy the artifacts from the upstream jobs
174     stage("Copy Artifacts") {
175         // cleanup any previous repo
176         sh 'rm -rf repo'
177         dir("repo") {
178             // grab all stable upstream builds based on the
179
180             dir("${RELEASE}") {
181                 def list = ["RO", "openvim", "osmclient", "IM", "devops", "MON", "N2VC", "NBI", "common", "LCM", "POL", "LW-UI", "NG-UI", "PLA", "tests"]
182                 for (component in list) {
183                     step ([$class: 'CopyArtifact',
184                            projectName: "${component}${upstream_main_job}/${GERRIT_BRANCH}"])
185
186                     // grab the build name/number
187                     build_num = ci_helper.get_env_value('build.env','BUILD_NUMBER')
188
189                     // grab the archives from the stage_2 builds (ie. this will be the artifacts stored based on a merge)
190                     ci_helper.get_archive(params.ARTIFACTORY_SERVER,component,GERRIT_BRANCH, "${component}${upstream_main_job} :: ${GERRIT_BRANCH}", build_num)
191
192                     // cleanup any prevously defined dists
193                     sh "rm -rf dists"
194                 }
195
196                 // check if an upstream artifact based on specific build number has been requested
197                 // This is the case of a merge build and the upstream merge build is not yet complete (it is not deemed
198                 // a successful build yet). The upstream job is calling this downstream job (with the its build artifiact)
199                 if ( params.UPSTREAM_JOB_NAME ) {
200                     step ([$class: 'CopyArtifact',
201                            projectName: "${params.UPSTREAM_JOB_NAME}",
202                            selector: [$class: 'SpecificBuildSelector', buildNumber: "${params.UPSTREAM_JOB_NUMBER}"]
203                           ])
204
205                     build_num = ci_helper.get_env_value('build.env','BUILD_NUMBER')
206                     component = ci_helper.get_mdg_from_project(ci_helper.get_env_value('build.env','GERRIT_PROJECT'))
207
208                     // the upstream job name contains suffix with the project. Need this stripped off
209                     def project_without_branch = params.UPSTREAM_JOB_NAME.split('/')[0]
210
211                     // Remove the previous artifact for this component. Use the new upstream artifact
212                     sh "rm -rf pool/${component}"
213
214                     ci_helper.get_archive(params.ARTIFACTORY_SERVER,component,GERRIT_BRANCH, "${project_without_branch} :: ${GERRIT_BRANCH}", build_num)
215
216                     sh "rm -rf dists"
217                 }
218
219                 // sign all the components
220                 for (component in list) {
221                     sh "dpkg-sig --sign builder -k ${GPG_KEY_NAME} pool/${component}/*"
222                 }
223
224                 // now create the distro
225                 for (component in list) {
226                     sh "mkdir -p dists/${params.REPO_DISTRO}/${component}/binary-amd64/"
227                     sh "apt-ftparchive packages pool/${component} > dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
228                     sh "gzip -9fk dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
229                 }
230
231                 // create and sign the release file
232                 sh "apt-ftparchive release dists/${params.REPO_DISTRO} > dists/${params.REPO_DISTRO}/Release"
233                 sh "gpg --yes -abs -u ${GPG_KEY_NAME} -o dists/${params.REPO_DISTRO}/Release.gpg dists/${params.REPO_DISTRO}/Release"
234
235                 // copy the public key into the release folder
236                 // this pulls the key from the home dir of the current user (jenkins)
237                 sh "cp ~/${REPO_KEY_NAME} 'OSM ETSI Release Key.gpg'"
238                 sh "cp ~/${REPO_KEY_NAME} ."
239
240                 // merge the change logs
241                 sh """
242                    rm -f changelog/changelog-osm.html
243                    [ ! -d changelog ] || for mdgchange in \$(ls changelog); do cat changelog/\$mdgchange >> changelog/changelog-osm.html; done
244                    """
245                 RELEASE_DIR = sh(returnStdout:true,  script: 'pwd').trim()
246             }
247             // start an apache server to serve up the images
248             http_server_name = "${container_name}-apache"
249
250             pwd = sh(returnStdout:true,  script: 'pwd').trim()
251             repo_port = sh(script: 'echo $(python -c \'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()\');', returnStdout: true).trim()
252             repo_base_url = ci_helper.start_http_server(pwd,http_server_name,repo_port)
253             NODE_IP_ADDRESS=sh(returnStdout: true, script:
254                 "echo ${SSH_CONNECTION} | awk '{print \$3}'").trim()
255         }
256
257         // now pull the devops package and install in temporary location
258         tempdir = sh(returnStdout: true, script: "mktemp -d").trim()
259         osm_devops_dpkg = sh(returnStdout: true, script: "find . -name osm-devops*.deb").trim()
260         sh "dpkg -x ${osm_devops_dpkg} ${tempdir}"
261         OSM_DEVOPS="${tempdir}/usr/share/osm-devops"
262         println("Repo base URL=${repo_base_url}")
263     }
264
265     dir(OSM_DEVOPS) {
266         def remote = [:]
267         error = null
268
269         if ( params.DO_BUILD ) {
270             stage("Build") {
271                 sh "make -C docker clean"
272                 sh "make -C docker -j `nproc` Q= CMD_DOCKER_ARGS= TAG=${container_name} RELEASE=${params.RELEASE} REPOSITORY_BASE=${repo_base_url} REPOSITORY_KEY=${params.REPO_KEY_NAME} REPOSITORY=${params.REPO_DISTRO}"
273             }
274
275             stage("Push to internal registry") {
276                 withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'gitlab-registry',
277                                 usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
278                     sh "docker login ${INTERNAL_DOCKER_REGISTRY} -u ${USERNAME} -p ${PASSWORD}"
279                 }
280                 sh "make -C docker push INPUT_TAG=${container_name} TAG=${container_name} DOCKER_REGISTRY=${INTERNAL_DOCKER_REGISTRY}"
281             }
282
283         }
284
285         try {
286             useCharmedInstaller = params.INSTALLER.equalsIgnoreCase("charmed")
287
288             if ( params.DO_INSTALL ) {
289
290                 stage("Spawn Remote VM") {
291                     println("Launching new VM")
292                     output=sh(returnStdout: true, script: """#!/bin/sh -e
293                         for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
294                         openstack server create --flavor m1.xlarge \
295                                                 --image ubuntu18.04 \
296                                                 --key-name CICD \
297                                                 --nic net-id=osm-ext \
298                                                 ${container_name}
299                     """).trim()
300
301                     server_id = get_value('id', output)
302
303                     if (server_id == null) {
304                         println("VM launch output: ")
305                         println(output)
306                         throw new Exception("VM Launch failed")
307                     }
308                     println("Target VM is ${server_id}, waiting for IP address to be assigned")
309
310                     IP_ADDRESS = ""
311
312                     while (IP_ADDRESS == "") {
313                         output=sh(returnStdout: true, script: """#!/bin/sh -e
314                             for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
315                             openstack server show ${server_id}
316                         """).trim()
317                         IP_ADDRESS = get_value('addresses', output)
318                     }
319                     IP_ADDRESS = IP_ADDRESS.split('=')[1]
320                     println("Waiting for VM at ${IP_ADDRESS} to be reachable")
321
322                     alive = false
323                     while (! alive) {
324                         output=sh(returnStdout: true, script: "sleep 1 ; nc -zv ${IP_ADDRESS} 22 2>&1 || true").trim()
325                         println("output is [$output]")
326                         alive = output.contains("succeeded")
327                     }
328                     println("VM is ready and accepting ssh connections")
329                 }
330
331                 stage("Install") {
332                     commit_id = ''
333                     repo_distro = ''
334                     repo_key_name = ''
335                     release = ''
336
337                     if ( params.COMMIT_ID )
338                     {
339                         commit_id = "-b ${params.COMMIT_ID}"
340                     }
341
342                     if ( params.REPO_DISTRO )
343                     {
344                         repo_distro = "-r ${params.REPO_DISTRO}"
345                     }
346
347                     if ( params.REPO_KEY_NAME )
348                     {
349                         repo_key_name = "-k ${params.REPO_KEY_NAME}"
350                     }
351
352                     if ( params.RELEASE )
353                     {
354                         release = "-R ${params.RELEASE}"
355                     }
356
357                     if ( params.REPOSITORY_BASE )
358                     {
359                         repo_base_url = "-u ${params.REPOSITORY_BASE}"
360                     }
361                     else
362                     {
363                         repo_base_url = "-u http://${NODE_IP_ADDRESS}:${repo_port}"
364                     }
365
366                     remote.name = container_name
367                     remote.host = IP_ADDRESS
368                     remote.user = 'ubuntu'
369                     remote.identityFile = SSH_KEY
370                     remote.allowAnyHosts = true
371                     remote.logLevel = 'INFO'
372
373                     sshCommand remote: remote, command: """
374                         wget https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh
375                         chmod +x ./install_osm.sh
376                     """
377
378                     if ( useCharmedInstaller ) {
379
380                         // Use local proxy for docker hub
381                         sshCommand remote: remote, command: '''
382                             sudo snap install microk8s --classic
383                             sudo sed -i "s|https://registry-1.docker.io|http://172.21.1.1:5000|" /var/snap/microk8s/current/args/containerd-template.toml
384                             sudo systemctl restart snap.microk8s.daemon-containerd.service
385                             sudo snap alias microk8s.kubectl kubectl
386                             echo export PATH=/snap/bin:\${PATH} > ~/.bashrc
387                         '''
388
389                         withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'gitlab-registry',
390                                         usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
391                             sshCommand remote: remote, command: """
392                                 ./install_osm.sh -y \
393                                     ${repo_base_url} \
394                                     ${repo_key_name} \
395                                     ${release} -r unstable \
396                                     --charmed  \
397                                     --registry ${USERNAME}:${PASSWORD}@${INTERNAL_DOCKER_REGISTRY} \
398                                     --tag ${container_name}
399                             """
400                         }
401                         prometheusHostname = "prometheus."+IP_ADDRESS+".xip.io"
402                         prometheusPort = 80
403                         osmHostname = "nbi."+IP_ADDRESS+".xip.io:443"
404                     } else {
405                         // Run -k8s installer here
406                         // Update to use 172.21.1.1 as the dockerhub proxy
407                         // Specify registry to use for installer
408                         // set osmHostname, prometheusHostname, prometheusPort as needed
409                     }
410                 }
411             }
412
413             stage_archive = false
414             if ( params.DO_SMOKE ) {
415                 stage("OSM Health") {
416                     if ( useCharmedInstaller ) {
417                         stackName = "osm"
418                     } else {
419                         stackName = container_name
420                     }
421                     sshCommand remote: remote, command: """
422                         /usr/share/osm-devops/installers/osm_health.sh -k -s ${stackName}
423                     """
424                 }
425             }
426
427             if ( params.DO_STAGE_4 ) {
428                 // override stage_archive to only archive on stable
429                 stage_archive = false
430                 try {
431                     stage("System Integration Test") {
432                         if ( params.DO_ROBOT ) {
433                             if( useCharmedInstaller ) {
434                                 tempdir = sh(returnStdout: true, script: "mktemp -d").trim()
435                                 sh(script: "touch ${tempdir}/hosts")
436                                 hostfile="${tempdir}/hosts"
437                                 sh """cat << EOF > ${hostfile}
438 127.0.0.1           localhost
439 ${remote.host}      prometheus.${remote.host}.xip.io nbi.${remote.host}.xip.io
440 EOF"""
441                             } else {
442                                 hostfile=null
443                             }
444
445                             run_robot_systest(
446                                 container_name,
447                                 params.TEST_NAME,
448                                 osmHostname,
449                                 prometheusHostname,
450                                 prometheusPort,
451                                 params.ROBOT_VIM,
452                                 params.KUBECONFIG,
453                                 params.CLOUDS,
454                                 hostfile)
455                         }
456                     }
457                 } finally {
458                     stage("Archive Contailer Logs") {
459                         // Archive logs to containers_logs.txt
460                         archive_logs(remote)
461                         if ( ! currentBuild.result.equals('UNSTABLE') && ! currentBuild.result.equals('FAILURE')) {
462                             stage_archive = keep_artifacts
463                         } else {
464                             println ("Systest test failed, throwing error")
465                             error = new Exception("Systest test failed")
466                             currentBuild.result = 'FAILURE'
467                             throw error
468                         }
469                     }
470                 }
471             }
472
473             // override to save the artifacts
474             if ( params.SAVE_ARTIFACTS_OVERRIDE || stage_archive ) {
475                 stage("Archive") {
476                     sh "echo ${container_name} > build_version.txt"
477                     archiveArtifacts artifacts: "build_version.txt", fingerprint: true
478
479                     // Archive the tested repo
480                     dir("${RELEASE_DIR}") {
481                         ci_helper.archive(params.ARTIFACTORY_SERVER,RELEASE,GERRIT_BRANCH,'tested')
482                     }
483                     if ( params.DO_DOCKERPUSH ) {
484                         stage("Docker Push") {
485                             sh "make -C docker push INPUT_TAG=${container_name} TAG=${params.DOCKER_TAG}"
486                         }
487
488                         stage("Snap promotion") {
489                             def snaps = ["osmclient"]
490                             for (snap in snaps) {
491                                 channel=""
492                                 if (BRANCH_NAME.startsWith("v")) {
493                                     channel=BRANCH_NAME.substring(1)+"/"
494                                 } else if (BRANCH_NAME!="master") {
495                                     channel+="/"+BRANCH_NAME.replaceAll('/','-')
496                                 }
497                                 track=channel+"edge\\*"
498                                 edge_rev=sh(returnStdout: true,
499                                     script: "sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " +
500                                     "-w /build snapcore/snapcraft:stable /bin/bash -c " +
501                                     "\"snapcraft login --with /snapcraft/config &>/dev/null && " +
502                                     "snapcraft revisions $snap\" | " +
503                                     "grep \" $track\" | tail -1 | awk '{print \$1}'").trim()
504                                 track=channel+"beta\\*"
505                                 beta_rev=sh(returnStdout: true,
506                                     script: "sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " +
507                                     "-w /build snapcore/snapcraft:stable /bin/bash -c " +
508                                     "\"snapcraft login --with /snapcraft/config &>/dev/null && " +
509                                     "snapcraft revisions $snap\" | " +
510                                     "grep \" $track\" | tail -1 | awk '{print \$1}'").trim()
511
512                                 if ( edge_rev != beta_rev ) {
513                                     print "Promoting $edge_rev to beta in place of $beta_rev"
514                                     beta_track=channel+"beta"
515                                     sh("sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " +
516                                         "-w /build snapcore/snapcraft:stable /bin/bash -c " +
517                                         "\"snapcraft login --with /snapcraft/config &>/dev/null && " +
518                                         "snapcraft release $snap $edge_rev $beta_track\"")
519                                 }
520                             }
521                         }
522                     }
523                 }
524             }
525         }
526         catch(Exception ex) {
527             error = ex
528             currentBuild.result = 'FAILURE'
529             println("Caught error: "+ex)
530         }
531         finally {
532             println("Entered finally block")
533             if ( params.DO_INSTALL && server_id != null) {
534                 delete_vm = true
535                 if (error && params.SAVE_CONTAINER_ON_FAIL ) {
536                     delete_vm = false
537                 }
538                 if (!error && params.SAVE_CONTAINER_ON_PASS ) {
539                     delete_vm = false
540                 }
541
542                 if ( delete_vm ) {
543                     if (server_id != null) {
544                         println("Deleting VM: $server_id")
545                         sh """#!/bin/sh -e
546                             for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
547                             openstack server delete ${server_id}
548                         """
549                     } else {
550                         println("Saved VM $server_id in ETSI VIM")
551                     }
552                 }
553             }
554             sh "docker stop ${http_server_name} || true"
555             sh "docker rm ${http_server_name} || true"
556         }
557     }
558 }