Repository navigation
Expand file tree
/
Copy pathJenkinsfile-Tutorial-Check-eBPF
More file actions
356 lines (338 loc) · 14.4 KB
/
Copy pathJenkinsfile-Tutorial-Check-eBPF
File metadata and controls
356 lines (338 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/bin/groovy
/*
* SPDX-License-Identifier: MIT
*/
// Location of the CN executor node
def cn_ci_host = params.Host_CN_CI_Server
def cn_ci_resource = params.DockerContainers
def upstreamEvent = false
def upstreamIsFED = false
// Variables that can used in main pipeline and in functions
NRF=0
AMF=1
SMF=2
UPF=3
AUSF=4
UDM=5
UDR=6
NSSF=7
PCF=8
// Default tags / branches --> could be passed on by upstream job
imageNames = ["oai-nrf", "oai-amf", "oai-smf", "oai-upf", "oai-ausf", "oai-udm", "oai-udr", "oai-nssf", "oai-pcf"]
repoNames = ["oai-cn5g-nrf", "oai-cn5g-amf", "oai-cn5g-smf", "oai-cn5g-upf", "oai-cn5g-ausf", "oai-cn5g-udm", "oai-cn5g-udr", "oai-cn5g-nssf", "oai-cn5g-pcf"]
branchNames = ["", "", "", "", "", "", "", "", ""]
imageTags = ["", "", "", "", "", "", "", "", ""]
upstreamJobs = [false, false, false, false, false, false, false, false, false]
pulledImages = [false, false, false, false, false, false, false, false, false]
// Which RAN TAG to use
ranTag = params.ranTag
upstreamTagToUse = params.upstreamTagToUse?.trim() ?: 'develop'
// means to shorten the pipeline
run_ebpf_upf = true
//-------------------------------------------------------------------------------
// Pipeline start
pipeline {
agent {
label cn_ci_host
}
options {
disableConcurrentBuilds()
timestamps()
ansiColor('xterm')
lock(cn_ci_resource)
}
stages {
stage ('Verify Parameters') {
steps {
script {
echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
JOB_TIMESTAMP = sh returnStdout: true, script: 'date --utc --rfc-3339=seconds | sed -e "s#+00:00##"'
JOB_TIMESTAMP = JOB_TIMESTAMP.trim()
echo "Node is ${NODE_NAME}"
// Find out the cause of the trigger
for (cause in currentBuild.getBuildCauses()) {
if (cause.toString().contains('UpstreamCause')) {
upstreamEvent = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-NRF')) {
upstreamJobs[NRF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-AMF')) {
upstreamJobs[AMF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-SMF')) {
upstreamJobs[SMF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-UPF')) {
upstreamJobs[UPF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-AUSF')) {
upstreamJobs[AUSF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-UDM')) {
upstreamJobs[UDM] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-UDR')) {
upstreamJobs[UDR] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-NSSF')) {
upstreamJobs[NSSF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-PCF')) {
upstreamJobs[PCF] = true
}
if (cause.toString().contains('OAI-CN5G-FED')) {
upstreamIsFED = true
}
}
sh "git clean -x -d -f > /dev/null 2>&1"
sh "git submodule foreach --recursive 'git clean -x -d -ff' > /dev/null 2>&1"
sh "git submodule deinit --force --all > /dev/null 2>&1"
if (!upstreamIsFED) {
// Manual or NF-triggered build: test the requested fed branch or tag.
sh "git fetch --no-tags origin ${upstreamTagToUse}"
sh "git checkout -f FETCH_HEAD"
}
if (upstreamIsFED && params.GIT_MERGE_REF) {
// Fed PR: test the PR-merged-into-target state (GitHub's precomputed merge ref).
sh "git fetch origin ${params.GIT_MERGE_REF}"
sh "git checkout -f FETCH_HEAD"
} else if (upstreamIsFED && params.GIT_COMMIT_SHA) {
// Fed push: fetch first; the sha may be abbreviated.
sh "git fetch --no-tags --force origin '+refs/heads/*:refs/remotes/origin/*'"
sh "git checkout -f ${params.GIT_COMMIT_SHA}"
} else if (upstreamIsFED) {
error "FED-triggered build is missing GIT_MERGE_REF and GIT_COMMIT_SHA"
}
sh "echo Current commit after checkout is \$(git rev-parse HEAD)"
// Authenticate the submodule clone: -c scopes the credential helper to just this command.
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-jenkins-oai-cn', usernameVariable: 'GITHUB_USERNAME', passwordVariable: 'GITHUB_TOKEN']
]) {
sh '''
git -c credential.helper='!f() { echo "username=$GITHUB_USERNAME"; echo "password=$GITHUB_TOKEN"; }; f' submodule update --init --recursive ci-scripts/common
'''
}
sh "mkdir -p archives"
for (ii = 0; ii < imageNames.size(); ii++) {
if (ii == NRF) {
branchNames[NRF] = params.NRF_BRANCH
imageTags[NRF] = params.NRF_TAG
if (upstreamEvent && upstreamJobs[NRF]) {
echo "Upstream Job passed NRF_TAG to use: ${imageTags[NRF]}"
echo "Upstream Job passed NRF_BRANCH to use: ${branchNames[NRF]}"
run_ebpf_upf = true
}
}
if (ii == AMF) {
branchNames[AMF] = params.AMF_BRANCH
imageTags[AMF] = params.AMF_TAG
if (upstreamEvent && upstreamJobs[AMF]) {
echo "Upstream Job passed AMF_TAG to use: ${imageTags[AMF]}"
echo "Upstream Job passed AMF_BRANCH to use: ${branchNames[AMF]}"
run_ebpf_upf = true
}
}
if (ii == SMF) {
branchNames[SMF] = params.SMF_BRANCH
imageTags[SMF] = params.SMF_TAG
if (upstreamEvent && upstreamJobs[SMF]) {
echo "Upstream Job passed SMF_TAG to use: ${imageTags[SMF]}"
echo "Upstream Job passed SMF_BRANCH to use: ${branchNames[SMF]}"
run_ebpf_upf = true
}
}
if (ii == UPF) {
branchNames[UPF] = params.UPF_BRANCH
imageTags[UPF] = params.UPF_TAG
if (upstreamEvent && upstreamJobs[UPF]) {
echo "Upstream Job passed UPF_TAG to use: ${imageTags[UPF]}"
echo "Upstream Job passed UPF_BRANCH to use: ${branchNames[UPF]}"
run_ebpf_upf = true
}
}
if (ii == AUSF) {
branchNames[AUSF] = params.AUSF_BRANCH
imageTags[AUSF] = params.AUSF_TAG
if (upstreamEvent && upstreamJobs[AUSF]) {
echo "Upstream Job passed AUSF_TAG to use: ${imageTags[AUSF]}"
echo "Upstream Job passed AUSF_BRANCH to use: ${branchNames[AUSF]}"
run_ebpf_upf = true
}
}
if (ii == UDM) {
branchNames[UDM] = params.UDM_BRANCH
imageTags[UDM] = params.UDM_TAG
if (upstreamEvent && upstreamJobs[UDM]) {
echo "Upstream Job passed UDM_TAG to use: ${imageTags[UDM]}"
echo "Upstream Job passed UDM_BRANCH to use: ${branchNames[UDM]}"
run_ebpf_upf = true
}
}
if (ii == UDR) {
branchNames[UDR] = params.UDR_BRANCH
imageTags[UDR] = params.UDR_TAG
if (upstreamEvent && upstreamJobs[UDR]) {
echo "Upstream Job passed UDR_TAG to use: ${imageTags[UDR]}"
echo "Upstream Job passed UDR_BRANCH to use: ${branchNames[UDR]}"
run_ebpf_upf = true
}
}
if (ii == NSSF) {
branchNames[NSSF] = params.NSSF_BRANCH
imageTags[NSSF] = params.NSSF_TAG
if (upstreamEvent && upstreamJobs[NSSF]) {
echo "Upstream Job passed NSSF_TAG to use: ${imageTags[NSSF]}"
echo "Upstream Job passed NSSF_BRANCH to use: ${branchNames[NSSF]}"
run_ebpf_upf = false
}
}
if (ii == PCF) {
branchNames[PCF] = params.PCF_BRANCH
imageTags[PCF] = params.PCF_TAG
if (upstreamEvent && upstreamJobs[PCF]) {
echo "Upstream Job passed PCF_TAG to use: ${imageTags[PCF]}"
echo "Upstream Job passed PCF_BRANCH to use: ${branchNames[PCF]}"
run_ebpf_upf = false
}
}
}
// On Ubuntu servers, we shall pull from private local registry
if ((cn_ci_host == 'Selfix') || (cn_ci_host == 'Alambix') || (cn_ci_host == 'Cetautomatix')) {
pullFromSelfix = true
try {
// Login
sh 'docker login -u oaicicd -p oaicicd gracehopper3-oai.sboai.cs.eurecom.fr > /dev/null 2>&1'
} catch (Exception e) {
echo 'Problem w/ selfix registry. Let see if we can use local images'
pullFromSelfix = false
}
if (pullFromSelfix) {
// We will try to pull from Selfix registry.
// If the NF CI is yet ready, it's OK, it will fail but keep working with local registry
for (ii = 0; ii < imageNames.size(); ii++) {
imageTags[ii] = pullImageFromSelfix(ii, imageNames[ii], imageTags[ii], branchNames[ii])
}
// Logout
sh 'docker logout gracehopper3-oai.sboai.cs.eurecom.fr > /dev/null 2>&1'
}
}
// Verify that the images are available
imageStatus = 0
for (ii = 0; ii < imageNames.size(); ii++) {
imageStatus += checkImageInfo(imageNames[ii], imageTags[ii])
}
if (imageStatus > 0) {
error ("Some images are not present!")
}
}
}
}
stage ('Check Basic w/ eBPF Deployment Tutorial') {
when { expression {run_ebpf_upf} }
steps {
script {
updateDockerCompose('docker-compose/docker-compose-basic-nrf-ebpf.yaml', ranTag)
dir ('ci-scripts') {
// Tee will make the command always pass
// Please use the same log name as the folder used in the tutorial
sh './checkTutorial.py --tutorial DEPLOY_SA5G_WITH_UPF_EBPF.md | tee ../archives/upf-ebpf-gnbsim.log'
}
try {
sh 'grep -l "is PASS" archives/upf-ebpf-gnbsim.log > /dev/null'
echo "Basic eBPF Tutorial PASSED"
} catch (Exception e) {
currentBuild.result = 'FAILURE'
echo "Basic eBPF Tutorial FAILED"
}
archivesArtifacts('docker-compose/docker-compose-basic-nrf-ebpf.yaml', 'upf-ebpf-gnbsim')
cleanUpDockerCompose('docker-compose/docker-compose-basic-nrf-ebpf.yaml')
}
}
}
}
post {
always {
script {
// Zipping all archived log files
sh "zip -r -qq cn5g_fed_tutorials_logs.zip archives"
if (fileExists('cn5g_fed_tutorials_logs.zip')) {
archiveArtifacts artifacts: 'cn5g_fed_tutorials_logs.zip'
}
sh './ci-scripts/checkTutorialHtmlReport.py --job_name ' + JOB_NAME + ' --job_id ' + BUILD_ID + ' --job_url ' + BUILD_URL
if (fileExists('test_results_oai_cn5g_tutorials.html')) {
sh 'mv test_results_oai_cn5g_tutorials.html test_results_oai_cn5g_tutorials_ebpf.html'
archiveArtifacts artifacts: 'test_results_oai_cn5g_tutorials_ebpf.html'
}
}
}
cleanup {
script {
sh 'docker volume prune --force'
// Removing the images that we pulled.
for (ii = 0; ii < imageNames.size(); ii++) {
if (pulledImages[ii]) {
sh 'docker rmi ' + imageNames[ii] + ':' + imageTags[ii]
}
}
}
}
}
}
def pullImageFromSelfix(idx, imageName, imageTag, branchName) {
if ((imageTag == 'develop') && (branchName == 'develop')) {
try {
tag = sh returnStdout: true, script: './ci-scripts/retrieveLatestTagOnPrivateRepo.py --repo-name ' + imageName
tag = tag.trim()
} catch (Exception e) {
return imageTag
}
} else {
tag = imageTag
}
// We may have wrong image tag?
try {
sh 'docker pull gracehopper3-oai.sboai.cs.eurecom.fr/' + imageName + ':' + tag
sh 'docker image tag gracehopper3-oai.sboai.cs.eurecom.fr/' + imageName + ':' + tag + ' ' + imageName + ':' + tag
sh 'docker rmi gracehopper3-oai.sboai.cs.eurecom.fr/' + imageName + ':' + tag
pulledImages[idx] = true
} catch (Exception e) {
echo "${imageName} Image tag to test (${imageName}:${tag} does not exist on selfix private registry!"
tag = imageTag
}
return tag
}
def checkImageInfo(imageName, origTag) {
status = 0
sh "echo 'Tested Tag is ${imageName}:${origTag}' > archives/${imageName}-image-info.log"
try {
sh "docker image inspect --format='Size = {{.Size}} bytes' ${imageName}:${origTag} >> archives/${imageName}-image-info.log"
sh "docker image inspect --format='Date = {{.Created}}' ${imageName}:${origTag} >> archives/${imageName}-image-info.log"
} catch (Exception e) {
echo "${imageName} Image tag to test (${imageName}:${origTag} does not exist!"
status = 1
}
return status
}
def updateDockerCompose(filename, lRanTag) {
for (ii = 0; ii < imageNames.size(); ii++) {
sh 'sed -i -e "s@oaisoftwarealliance/' + imageNames[ii] + ':develop@' + imageNames[ii] + ':' + imageTags[ii] + '@" ' + filename
}
sh 'sed -i -e "s@oaisoftwarealliance/trf-gen-cn5g:latest@trf-gen-cn5g:latest@" ' + filename
// Using the develop variant of gnbsim
sh 'sed -i -e "s@gnbsim:latest@gnbsim:develop@" docker-compose/docker-compose-gnbsim*.y*ml docker-compose/docker-compose*ransim.y*ml'
// Using a dedicated version of the OAI RAN images
sh 'sed -i -e "s@oaisoftwarealliance/oai-gnb:develop@oai-gnb:' + lRanTag + '@" docker-compose/docker-compose-slicing-ransim.yaml'
sh 'sed -i -e "s@oaisoftwarealliance/oai-nr-ue:develop@oai-nr-ue:' + lRanTag + '@" docker-compose/docker-compose-slicing-ransim.yaml'
}
def archivesArtifacts(filename,folder) {
sh 'cp -Rf /tmp/oai/' + folder + ' archives || true'
// Making a copy of the docker-compose for debugging
sh 'cp ' + filename + ' archives/' + folder + ' || true'
}
def cleanUpDockerCompose(filename) {
sh 'git checkout -- ' + filename
sh 'git checkout -- docker-compose/docker-compose-gnbsim*.y*ml docker-compose/docker-compose*ransim.y*ml'
sh 'docker network prune --force'
sh 'docker volume prune --force'
}