blob: c920f46be4bd87127a03f4f7a12cd304da3c1138 [file] [log] [blame]
Mike Marchetti8343e3f2017-06-30 15:12:26 -04001/* Copyright 2017 Sandvine
2 *
3 * All Rights Reserved.
David Garciaa60ec732021-03-17 15:28:47 +01004 *
Mike Marchetti8343e3f2017-06-30 15:12:26 -04005 * 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": "./",
beierlm499b4422022-02-04 11:14:33 -050032 "pattern": "${repo_prefix}${mdg}/${branch}/${build_number}/${pattern}"
Mike Marchetti8343e3f2017-06-30 15:12:26 -040033 }
34 ]
35 }"""
36
beierlm499b4422022-02-04 11:14:33 -050037 println("Searching Artifactory with ${downloadSpec}")
38
David Garciaa60ec732021-03-17 15:28:47 +010039 def results = server.download(downloadSpec)
40 // Save the list of URLs that we need to pass to the dockerfiles for build
41 def debian_packages = []
42 for ( result in results.getDependencies()) {
43 if (result.remotePath.contains(".deb")) {
44 debian_packages.add(result.remotePath)
45 }
46 }
47
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -050048 // workaround. flatten repo to remove specific build num from the directory
David Garciaa60ec732021-03-17 15:28:47 +010049 sh "cp -R ${branch}/${build_number}/* ."
50 sh "rm -rf ${branch}/${build_number}"
51
52 return debian_packages
Mike Marchetti8343e3f2017-06-30 15:12:26 -040053}
54
55def get_env_value(build_env_file,key) {
56 return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim()
57}
58
59def lxc_run(container_name,cmd) {
60 return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim()
61}
62
Mike Marchettif94dd8a2017-11-06 11:04:38 -050063def lxc_file_push(container_name,file,destination) {
64 return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim()
65}
66
Mike Marchetti8343e3f2017-06-30 15:12:26 -040067// start a http server
68// return the http server URL
beierlm7b0acc02020-11-19 11:39:36 -050069def start_http_server(repo_dir,server_name,port) {
70 sh "docker run -dit --name ${server_name} -p ${port}:80 -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4"
Mike Marchetti8343e3f2017-06-30 15:12:26 -040071 def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
Mike Marchetti7f186032018-09-19 17:09:05 -040072 return "http://${http_server_ip}/"
Mike Marchetti8343e3f2017-06-30 15:12:26 -040073}
74
75def lxc_get_file(container_name,file,destination) {
76 sh "lxc file pull ${container_name}/${file} ${destination}"
77}
78
Mike Marchettif94dd8a2017-11-06 11:04:38 -050079def systest_run(container_name, test, source_rc = null) {
Mike Marchetti8343e3f2017-06-30 15:12:26 -040080 // need to get the SO IP inside the running container
81 so_ip = lxc_run(container_name,"lxc list SO-ub -c 4|grep eth0 |awk '{print \$2}'")
Mike Marchettif94dd8a2017-11-06 11:04:38 -050082 ro_ip = lxc_run(container_name,"lxc list RO -c 4|grep eth0 |awk '{print \$2}'")
Mike Marchetti8343e3f2017-06-30 15:12:26 -040083 //container_ip = get_ip_from_container(container_name)
David Garciaa60ec732021-03-17 15:28:47 +010084
Mike Marchettif94dd8a2017-11-06 11:04:38 -050085 if ( source_rc ) {
86 pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1)
David Garciaa60ec732021-03-17 15:28:47 +010087
Mike Marchettif94dd8a2017-11-06 11:04:38 -050088 lxc_file_push(container_name,source_rc,pre_source)
Mike Marchetti34334652018-05-04 10:26:42 -040089 result = lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'")
90 echo result
Mike Marchettif94dd8a2017-11-06 11:04:38 -050091 }
92 else
93 {
Mike Marchetti34b892a2018-04-16 13:57:12 -040094 result = lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}")
95 echo result
Mike Marchettif94dd8a2017-11-06 11:04:38 -050096 }
Mike Marchetti8343e3f2017-06-30 15:12:26 -040097 lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.')
98}
99
100def get_ip_from_container( container_name ) {
101 return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim()
102}
103
Wesley Hirsch92da2062017-09-08 17:42:29 -0400104def archive(artifactory_server,mdg,branch,status) {
105 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400106
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -0500107 def properties = ""
108 //def properties = "branch=${branch};status=${status}"
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400109 def repo_prefix = 'osm-'
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -0500110
111 // if the build name does not contain merge, then this is a patchset/staging job
112 if ( !JOB_NAME.contains('merge') ) {
113 branch += '-staging'
114 }
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400115 def uploadSpec = """{
116 "files": [
117 {
118 "pattern": "dists/*.gz",
Mike Marchettib8e44732017-09-12 10:36:02 -0400119 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400120 "props": "${properties}",
121 "flat": false
122 },
123 {
124 "pattern": "dists/*Packages",
Mike Marchettib8e44732017-09-12 10:36:02 -0400125 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400126 "props": "${properties}",
127 "flat": false
128 },
129 {
130 "pattern": "pool/*/*.deb",
Mike Marchettib8e44732017-09-12 10:36:02 -0400131 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400132 "props": "${properties}",
133 "flat": false
Mike Marchetti4ffe5fe2017-11-21 15:07:59 -0500134 },
135 {
136 "pattern": "changelog/*",
137 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
138 "props": "${properties}",
139 "flat": false
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400140 }]
141 }"""
142
143 buildInfo = server.upload(uploadSpec)
144 //buildInfo.retention maxBuilds: 4
145 //buildInfo.retention deleteBuildArtifacts: false
146
147 server.publishBuildInfo(buildInfo)
148
149 // store the build environment into the jenkins artifact storage
150 sh 'env > build.env'
151 archiveArtifacts artifacts: "build.env", fingerprint: true
152}
153
154
155//CANNOT use build promotion with OSS version of artifactory
156// For now, will publish downloaded artifacts into a new repo.
Wesley Hirsch92da2062017-09-08 17:42:29 -0400157def promote_build(artifactory_server,mdg,branch,buildInfo) {
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400158 println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}")
159
Wesley Hirsch92da2062017-09-08 17:42:29 -0400160 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400161
162 //def properties = "branch=${branch};status=${status}"
163 def repo_prefix = 'osm-'
164 def build_name = "${mdg}-stage_2 :: ${branch}"
165
166 def promotionConfig = [
167 // Mandatory parameters
168 "buildName" : buildInfo.name,
169 "buildNumber" : buildInfo.number,
170 'targetRepo' : 'osm-release',
David Garciaa60ec732021-03-17 15:28:47 +0100171
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400172 // Optional parameters
173 'comment' : 'this is the promotion comment',
174 'sourceRepo' : "${repo_prefix}${mdg}",
175 'status' : 'Testing',
176 'includeDependencies': true,
177 'copy' : true,
178 // 'failFast' is true by default.
179 // Set it to false, if you don't want the promotion to abort upon receiving the first error.
180 'failFast' : true
181 ]
182
183 server.promote promotionConfig
184}
185
186def get_mdg_from_project(project) {
187 // split the project.
188 def values = project.split('/')
189 if ( values.size() > 1 ) {
190 return values[1]
191 }
192 // no prefix, likely just the project name then
193 return project
194}
195
196
197return this