blob: 9708b1c8a0ac6a2018188837a9407aebaffbe36f [file] [log] [blame]
Mike Marchetti8343e3f2017-06-30 15:12:26 -04001/* 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
Wesley Hirsch92da2062017-09-08 17:42:29 -040018def get_archive(artifactory_server, mdg, branch, build_name, build_number, pattern='*') {
19 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -040020
21 println("retrieve archive for ${mdg}/${branch}/${build_name}/${build_number}/${pattern}")
22
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -050023 // if the build name does not contain merge, then this is a patchset/staging job
24 if (!build_name.contains('merge')) {
25 branch += '-staging'
26 }
Mike Marchetti8343e3f2017-06-30 15:12:26 -040027 def repo_prefix = 'osm-'
28 def downloadSpec = """{
29 "files": [
30 {
31 "target": "./",
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -050032 "pattern": "${repo_prefix}${mdg}/${branch}/${build_number}/${pattern}",
Mike Marchetti8343e3f2017-06-30 15:12:26 -040033 "build": "${build_name}/${build_number}"
34 }
35 ]
36 }"""
37
38 server.download(downloadSpec)
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -050039 // workaround. flatten repo to remove specific build num from the directory
Mike Marchettiea319bf2017-09-20 15:58:32 -040040 sh "cp -R ${branch}/${build_num}/* ."
41 sh "rm -rf ${branch}/${build_num}"
Mike Marchetti8343e3f2017-06-30 15:12:26 -040042}
43
44def get_env_value(build_env_file,key) {
45 return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim()
46}
47
48def lxc_run(container_name,cmd) {
49 return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim()
50}
51
Mike Marchettif94dd8a2017-11-06 11:04:38 -050052def lxc_file_push(container_name,file,destination) {
53 return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim()
54}
55
Mike Marchetti8343e3f2017-06-30 15:12:26 -040056// start a http server
57// return the http server URL
58def start_http_server(repo_dir,server_name) {
59 sh "docker run -dit --name ${server_name} -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4"
60 def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
61 return "-u http://${http_server_ip}/"
62}
63
64def lxc_get_file(container_name,file,destination) {
65 sh "lxc file pull ${container_name}/${file} ${destination}"
66}
67
Mike Marchettif94dd8a2017-11-06 11:04:38 -050068def systest_run(container_name, test, source_rc = null) {
Mike Marchetti8343e3f2017-06-30 15:12:26 -040069 // need to get the SO IP inside the running container
70 so_ip = lxc_run(container_name,"lxc list SO-ub -c 4|grep eth0 |awk '{print \$2}'")
Mike Marchettif94dd8a2017-11-06 11:04:38 -050071 ro_ip = lxc_run(container_name,"lxc list RO -c 4|grep eth0 |awk '{print \$2}'")
Mike Marchetti8343e3f2017-06-30 15:12:26 -040072 //container_ip = get_ip_from_container(container_name)
Mike Marchettif94dd8a2017-11-06 11:04:38 -050073
74 if ( source_rc ) {
75 pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1)
76
77 lxc_file_push(container_name,source_rc,pre_source)
78 lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'")
79 }
80 else
81 {
82 lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}")
83 }
Mike Marchetti8343e3f2017-06-30 15:12:26 -040084 lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.')
85}
86
87def get_ip_from_container( container_name ) {
88 return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim()
89}
90
Wesley Hirsch92da2062017-09-08 17:42:29 -040091def archive(artifactory_server,mdg,branch,status) {
92 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -040093
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -050094 def properties = ""
95 //def properties = "branch=${branch};status=${status}"
Mike Marchetti8343e3f2017-06-30 15:12:26 -040096 def repo_prefix = 'osm-'
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -050097
98 // if the build name does not contain merge, then this is a patchset/staging job
99 if ( !JOB_NAME.contains('merge') ) {
100 branch += '-staging'
101 }
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400102 def uploadSpec = """{
103 "files": [
104 {
105 "pattern": "dists/*.gz",
Mike Marchettib8e44732017-09-12 10:36:02 -0400106 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400107 "props": "${properties}",
108 "flat": false
109 },
110 {
111 "pattern": "dists/*Packages",
Mike Marchettib8e44732017-09-12 10:36:02 -0400112 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400113 "props": "${properties}",
114 "flat": false
115 },
116 {
117 "pattern": "pool/*/*.deb",
Mike Marchettib8e44732017-09-12 10:36:02 -0400118 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400119 "props": "${properties}",
120 "flat": false
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -0500121 },
122 {
123 "pattern": "changelog/*",
124 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
125 "props": "${properties}",
126 "flat": false
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400127 }]
128 }"""
129
130 buildInfo = server.upload(uploadSpec)
131 //buildInfo.retention maxBuilds: 4
132 //buildInfo.retention deleteBuildArtifacts: false
133
134 server.publishBuildInfo(buildInfo)
135
136 // store the build environment into the jenkins artifact storage
137 sh 'env > build.env'
138 archiveArtifacts artifacts: "build.env", fingerprint: true
139}
140
141
142//CANNOT use build promotion with OSS version of artifactory
143// For now, will publish downloaded artifacts into a new repo.
Wesley Hirsch92da2062017-09-08 17:42:29 -0400144def promote_build(artifactory_server,mdg,branch,buildInfo) {
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400145 println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}")
146
Wesley Hirsch92da2062017-09-08 17:42:29 -0400147 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400148
149 //def properties = "branch=${branch};status=${status}"
150 def repo_prefix = 'osm-'
151 def build_name = "${mdg}-stage_2 :: ${branch}"
152
153 def promotionConfig = [
154 // Mandatory parameters
155 "buildName" : buildInfo.name,
156 "buildNumber" : buildInfo.number,
157 'targetRepo' : 'osm-release',
158
159 // Optional parameters
160 'comment' : 'this is the promotion comment',
161 'sourceRepo' : "${repo_prefix}${mdg}",
162 'status' : 'Testing',
163 'includeDependencies': true,
164 'copy' : true,
165 // 'failFast' is true by default.
166 // Set it to false, if you don't want the promotion to abort upon receiving the first error.
167 'failFast' : true
168 ]
169
170 server.promote promotionConfig
171}
172
173def get_mdg_from_project(project) {
174 // split the project.
175 def values = project.split('/')
176 if ( values.size() > 1 ) {
177 return values[1]
178 }
179 // no prefix, likely just the project name then
180 return project
181}
182
183
184return this