blob: d058099c093612bd1d9299eba209bfca8f16916e [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
23 def repo_prefix = 'osm-'
24 def downloadSpec = """{
25 "files": [
26 {
27 "target": "./",
Mike Marchettib8e44732017-09-12 10:36:02 -040028 "pattern": "${repo_prefix}${mdg}/${branch}/${pattern}",
Mike Marchetti8343e3f2017-06-30 15:12:26 -040029 "build": "${build_name}/${build_number}"
30 }
31 ]
32 }"""
33
34 server.download(downloadSpec)
35 // workaround. flatten and repo the specific build num from the directory
Mike Marchettiea319bf2017-09-20 15:58:32 -040036 sh "cp -R ${branch}/${build_num}/* ."
37 sh "rm -rf ${branch}/${build_num}"
Mike Marchetti8343e3f2017-06-30 15:12:26 -040038}
39
40def get_env_value(build_env_file,key) {
41 return sh(returnStdout:true, script: "cat ${build_env_file} | awk -F= '/${key}/{print \$2}'").trim()
42}
43
44def lxc_run(container_name,cmd) {
45 return sh(returnStdout: true, script: "lxc exec ${container_name} -- ${cmd}").trim()
46}
47
Mike Marchettif94dd8a2017-11-06 11:04:38 -050048def lxc_file_push(container_name,file,destination) {
49 return sh(returnStdout: true, script: "lxc file push ${file} ${container_name}/${destination}").trim()
50}
51
Mike Marchetti8343e3f2017-06-30 15:12:26 -040052// start a http server
53// return the http server URL
54def start_http_server(repo_dir,server_name) {
55 sh "docker run -dit --name ${server_name} -v ${repo_dir}:/usr/local/apache2/htdocs/ httpd:2.4"
56 def http_server_ip = sh(returnStdout:true, script: "docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${server_name}").trim()
57 return "-u http://${http_server_ip}/"
58}
59
60def lxc_get_file(container_name,file,destination) {
61 sh "lxc file pull ${container_name}/${file} ${destination}"
62}
63
Mike Marchettif94dd8a2017-11-06 11:04:38 -050064def systest_run(container_name, test, source_rc = null) {
Mike Marchetti8343e3f2017-06-30 15:12:26 -040065 // need to get the SO IP inside the running container
66 so_ip = lxc_run(container_name,"lxc list SO-ub -c 4|grep eth0 |awk '{print \$2}'")
Mike Marchettif94dd8a2017-11-06 11:04:38 -050067 ro_ip = lxc_run(container_name,"lxc list RO -c 4|grep eth0 |awk '{print \$2}'")
Mike Marchetti8343e3f2017-06-30 15:12:26 -040068 //container_ip = get_ip_from_container(container_name)
Mike Marchettif94dd8a2017-11-06 11:04:38 -050069
70 if ( source_rc ) {
71 pre_source = "/tmp/" + source_rc.substring(source_rc.lastIndexOf('/')+1)
72
73 lxc_file_push(container_name,source_rc,pre_source)
74 lxc_run(container_name, "sh -c '. ${pre_source}; make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}'")
75 }
76 else
77 {
78 lxc_run(container_name, "make -C devops/systest OSM_HOSTNAME=${so_ip} OSM_RO_HOSTNAME=${ro_ip} ${test}")
79 }
Mike Marchetti8343e3f2017-06-30 15:12:26 -040080 lxc_get_file(container_name, "/root/devops/systest/reports/pytest-${test}.xml",'.')
81}
82
83def get_ip_from_container( container_name ) {
84 return sh(returnStdout: true, script: "lxc list ${container_name} -c 4|grep eth0 |awk '{print \$2}'").trim()
85}
86
Wesley Hirsch92da2062017-09-08 17:42:29 -040087def archive(artifactory_server,mdg,branch,status) {
88 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -040089
90 def properties = "branch=${branch};status=${status}"
91 def repo_prefix = 'osm-'
92 def uploadSpec = """{
93 "files": [
94 {
Mike Marchetti3a0fc422017-11-17 13:38:47 -050095 "pattern": "changelog/*",
96 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
97 "props": "${properties}",
98 "flat": false
99 },
100 {
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400101 "pattern": "dists/*.gz",
Mike Marchettib8e44732017-09-12 10:36:02 -0400102 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400103 "props": "${properties}",
104 "flat": false
105 },
106 {
107 "pattern": "dists/*Packages",
Mike Marchettib8e44732017-09-12 10:36:02 -0400108 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400109 "props": "${properties}",
110 "flat": false
111 },
112 {
113 "pattern": "pool/*/*.deb",
Mike Marchettib8e44732017-09-12 10:36:02 -0400114 "target": "${repo_prefix}${mdg}/${branch}/${BUILD_NUMBER}/",
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400115 "props": "${properties}",
116 "flat": false
117 }]
118 }"""
119
120 buildInfo = server.upload(uploadSpec)
121 //buildInfo.retention maxBuilds: 4
122 //buildInfo.retention deleteBuildArtifacts: false
123
124 server.publishBuildInfo(buildInfo)
125
126 // store the build environment into the jenkins artifact storage
127 sh 'env > build.env'
128 archiveArtifacts artifacts: "build.env", fingerprint: true
129}
130
131
132//CANNOT use build promotion with OSS version of artifactory
133// For now, will publish downloaded artifacts into a new repo.
Wesley Hirsch92da2062017-09-08 17:42:29 -0400134def promote_build(artifactory_server,mdg,branch,buildInfo) {
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400135 println("Promoting build: mdg: ${mdg} branch: ${branch} build: ${buildInfo.name}/${buildInfo.number}")
136
Wesley Hirsch92da2062017-09-08 17:42:29 -0400137 server = Artifactory.server artifactory_server
Mike Marchetti8343e3f2017-06-30 15:12:26 -0400138
139 //def properties = "branch=${branch};status=${status}"
140 def repo_prefix = 'osm-'
141 def build_name = "${mdg}-stage_2 :: ${branch}"
142
143 def promotionConfig = [
144 // Mandatory parameters
145 "buildName" : buildInfo.name,
146 "buildNumber" : buildInfo.number,
147 'targetRepo' : 'osm-release',
148
149 // Optional parameters
150 'comment' : 'this is the promotion comment',
151 'sourceRepo' : "${repo_prefix}${mdg}",
152 'status' : 'Testing',
153 'includeDependencies': true,
154 'copy' : true,
155 // 'failFast' is true by default.
156 // Set it to false, if you don't want the promotion to abort upon receiving the first error.
157 'failFast' : true
158 ]
159
160 server.promote promotionConfig
161}
162
163def get_mdg_from_project(project) {
164 // split the project.
165 def values = project.split('/')
166 if ( values.size() > 1 ) {
167 return values[1]
168 }
169 // no prefix, likely just the project name then
170 return project
171}
172
173
174return this