blob: d7427bb9cb48c02e20912309e4920567553be2c3 [file] [log] [blame]
Joey Armstrong7bcb5782023-06-07 12:25:57 -04001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// voltha-2.x e2e tests
15// uses bbsim to simulate OLT/ONUs
16// NOTE we are importing the library even if it's global so that it's
17// easier to change the keywords during a replay
18library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
Joey Armstrong39f90382023-08-24 20:37:40 -040024// -----------------------------------------------------------------------
25// Intent:
26// -----------------------------------------------------------------------
27String branchName() {
28 String name = 'voltha-2.12'
29
30 // [TODO] Sanity check the target branch
31 // if (name != jenkins.branch) { fatal }
32 return(name)
33}
34
35// -----------------------------------------------------------------------
36// Intent: Due to lack of a reliable stack trace, construct a literal.
37// Jenkins will re-write the call stack for serialization.
38// -----------------------------------------------------------------------
39String getIam(String func) {
40 String branchName = branchName()
41 String src = [
42 'ci-management',
43 'jjb',
44 'pipeline',
45 'voltha',
46 branchName,
47 'software-upgrades.groovy'
48 ].join('/')
49
50 String name = [src, func].join('::')
51 return(name)
52}
53
Joey Armstrong7bcb5782023-06-07 12:25:57 -040054// fetches the versions/tags of the voltha component
55// returns the deployment version which is one less than the latest available tag of the repo, first voltha stack gets deployed using this;
56// returns the test version which is the latest tag of the repo, the component upgrade gets tested on this.
57// Note: if there is a major version change between deployment and test tags, then deployment tag will be same as test tag, i.e. both as latest.
58def get_voltha_comp_versions(component, base_deploy_tag) {
59 def comp_test_tag = sh (
60 script: "git ls-remote --refs --tags https://github.com/opencord/${component} | cut --delimiter='/' --fields=3 | tr '-' '~' | sort --version-sort | tail --lines=1 | sed 's/v//'",
61 returnStdout: true
62 ).trim()
63 def comp_deploy_tag = sh (
64 script: "git ls-remote --refs --tags https://github.com/opencord/${component} | cut --delimiter='/' --fields=3 | tr '-' '~' | sort --version-sort | tail --lines=2 | head -n 1 | sed 's/v//'",
65 returnStdout: true
66 ).trim()
67 def comp_deploy_major = comp_deploy_tag.substring(0, comp_deploy_tag.indexOf('.'))
68 def comp_test_major = comp_test_tag.substring(0, comp_test_tag.indexOf('.'))
69 if ( "${comp_deploy_major.trim()}" != "${comp_test_major.trim()}") {
70 comp_deploy_tag = comp_test_tag
71 }
72 if ( "${comp_test_tag.trim()}" == "${base_deploy_tag.trim()}") {
73 comp_deploy_tag = comp_test_tag
74 comp_test_tag = "master"
75 }
76 println "${component}: deploy_tag: ${comp_deploy_tag}, test_tag: ${comp_test_tag}"
77 return [comp_deploy_tag, comp_test_tag]
78}
79
80def test_software_upgrade(name) {
81 def infraNamespace = "infra"
82 def volthaNamespace = "voltha"
Joey Armstrongdeb75292023-08-24 17:06:33 -040083 def openolt_adapter_deploy_tag = ''
84 def openolt_adapter_test_tag = ''
85 def openonu_adapter_deploy_tag = ''
86 def openonu_adapter_test_tag = ''
87 def rw_core_deploy_tag = ''
88 def rw_core_test_tag = ''
89 def ofagent_deploy_tag = ''
90 def ofagent_test_tag = ''
Joey Armstrong7bcb5782023-06-07 12:25:57 -040091 def logsDir = "$WORKSPACE/${name}"
92 stage('Deploy Voltha - '+ name) {
93 timeout(10) {
94 // start logging
95 sh """
96 rm -rf ${logsDir} || true
97 mkdir -p ${logsDir}
98 _TAG=kail-${name} kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
99 """
Joey Armstrongdeb75292023-08-24 17:06:33 -0400100 String extraHelmFlags = extraHelmFlags.trim()
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400101 if ("${name}" == "onos-app-upgrade" || "${name}" == "onu-software-upgrade" || "${name}" == "onu-software-upgrade-omci-extended-msg" || "${name}" == "voltha-component-upgrade" || "${name}" == "voltha-component-rolling-upgrade") {
102 extraHelmFlags = " --set global.log_level=${logLevel.toUpperCase()},onu=1,pon=1 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 " + extraHelmFlags
103 }
104 if ("${name}" == "onu-software-upgrade" || "${name}" == "onu-software-upgrade-omci-extended-msg") {
105 extraHelmFlags = " --set global.extended_omci_support.enabled=true " + extraHelmFlags
106 }
107 if ("${name}" == "onu-software-upgrade-omci-extended-msg") {
108 extraHelmFlags = " --set omccVersion=180 " + extraHelmFlags
109 }
110 if ("${name}" == "onu-image-dwl-simultaneously") {
111 extraHelmFlags = " --set global.log_level=${logLevel.toUpperCase()},onu=2,pon=2 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 " + extraHelmFlags
112 }
113 if ("${name}" == "onos-app-upgrade" || "${name}" == "onu-software-upgrade" || "${name}" == "onu-software-upgrade-omci-extended-msg" || "${name}" == "onu-image-dwl-simultaneously") {
114 extraHelmFlags = " --set global.image_tag=master --set onos-classic.image.tag=master " + extraHelmFlags
115 }
116 if ("${name}" == "voltha-component-upgrade" || "${name}" == "voltha-component-rolling-upgrade") {
117 extraHelmFlags = " --set images.onos_config_loader.tag=master-onos-config-loader --set onos-classic.image.tag=master " + extraHelmFlags
118 }
Joey Armstrongdeb75292023-08-24 17:06:33 -0400119 extraHelmFlags += " --set onos-classic.onosSshPort=30115 --set onos-classic.onosApiPort=30120 "
120 extraHelmFlags += " --set voltha.onos_classic.replicas=3"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400121 //ONOS custom image handling
122 if ( onosImg.trim() != '' ) {
123 String[] split;
124 onosImg = onosImg.trim()
125 split = onosImg.split(':')
Joey Armstrongdeb75292023-08-24 17:06:33 -0400126 extraHelmFlags += " --set onos-classic.image.repository=" + split[0] +",onos-classic.image.tag=" + split[1] + " "
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400127 }
128 Integer olts = 1
129 if ("${name}" == "onu-image-dwl-simultaneously") {
130 olts = 2
131 }
132 if ("${name}" == "voltha-component-upgrade" || "${name}" == "voltha-component-rolling-upgrade") {
133 // fetch voltha components versions/tags
134 (openolt_adapter_deploy_tag, openolt_adapter_test_tag) = get_voltha_comp_versions("voltha-openolt-adapter", openoltAdapterDeployBaseTag.trim())
Joey Armstrongdeb75292023-08-24 17:06:33 -0400135 extraHelmFlags += " --set voltha-adapter-openolt.images.adapter_open_olt.tag=${openolt_adapter_deploy_tag} "
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400136 (openonu_adapter_deploy_tag, openonu_adapter_test_tag) = get_voltha_comp_versions("voltha-openonu-adapter-go", openonuAdapterDeployBaseTag.trim())
Joey Armstrongdeb75292023-08-24 17:06:33 -0400137 extraHelmFlags += " --set voltha-adapter-openonu.images.adapter_open_onu_go.tag=${openonu_adapter_deploy_tag} "
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400138 (rw_core_deploy_tag, rw_core_test_tag) = get_voltha_comp_versions("voltha-go", rwCoreDeployBaseTag.trim())
Joey Armstrongdeb75292023-08-24 17:06:33 -0400139 extraHelmFlags += " --set voltha.images.rw_core.tag=${rw_core_deploy_tag} "
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400140 (ofagent_deploy_tag, ofagent_test_tag) = get_voltha_comp_versions("ofagent-go", ofagentDeployBaseTag.trim())
Joey Armstrongdeb75292023-08-24 17:06:33 -0400141 extraHelmFlags += " --set voltha.images.ofagent.tag=${ofagent_deploy_tag} "
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400142 }
143 def localCharts = false
144 // Currently only testing with ATT workflow
145 // TODO: Support for other workflows
Joey Armstrongdeb75292023-08-24 17:06:33 -0400146 volthaDeploy([bbsimReplica: olts.toInteger(), workflow: 'att', extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400147
148 // [TODO] pkill_proc("_TAG=kail-${name}")
149 // stop logging
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400150 sh """
151 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
152 if [ -n "\$P_IDS" ]; then
153 echo \$P_IDS
154 for P_ID in \$P_IDS; do
155 kill -9 \$P_ID
156 done
157 fi
158 cd ${logsDir}
159 gzip -k onos-voltha-startup-combined.log
160 rm onos-voltha-startup-combined.log
161 """
162 // forward ONOS and VOLTHA ports
Joey Armstrongdeb75292023-08-24 17:06:33 -0400163 sh('''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400164 JENKINS_NODE_COOKIE="dontKillMe" _TAG=onos-port-forward /bin/bash -c "while true; do kubectl -n infra port-forward --address 0.0.0.0 service/voltha-infra-onos-classic-hs 8101:8101; done 2>&1 " &
165 JENKINS_NODE_COOKIE="dontKillMe" _TAG=onos-port-forward /bin/bash -c "while true; do kubectl -n infra port-forward --address 0.0.0.0 service/voltha-infra-onos-classic-hs 8181:8181; done 2>&1 " &
166 JENKINS_NODE_COOKIE="dontKillMe" _TAG=port-forward-voltha-api /bin/bash -c "while true; do kubectl -n voltha port-forward --address 0.0.0.0 service/voltha-voltha-api 55555:55555; done 2>&1 " &
Joey Armstrongdeb75292023-08-24 17:06:33 -0400167 ''')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400168 sh """
169 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
170 """
171 }
172 }
173 stage('Test - '+ name) {
174 timeout(75) {
175 sh """
176 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
177 mkdir -p \$ROBOT_LOGS_DIR
178 if [[ ${name} == 'onos-app-upgrade' ]]; then
179 export ONOS_APPS_UNDER_TEST+=''
180 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
181 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
182 fi
183 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
184 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
185 fi
186 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
187 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
188 fi
189 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
190 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
191 fi
192 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
193 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
194 fi
195 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
196 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
197 fi
198 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
199 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
200 fi
201 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
202 export TARGET=onos-app-upgrade-test
203 fi
204 if [ ${name} == 'voltha-component-upgrade' ] || [ ${name} == 'voltha-component-rolling-upgrade' ]; then
205 export VOLTHA_COMPS_UNDER_TEST+=''
206 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,voltha/voltha-openolt-adapter:${openolt_adapter_test_tag}*"
207 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,voltha/voltha-openonu-adapter-go:${openonu_adapter_test_tag}*"
208 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,voltha/voltha-rw-core:${rw_core_test_tag}*"
209 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,voltha/voltha-ofagent-go:${ofagent_test_tag}*"
210 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
211 fi
212 if [[ ${name} == 'voltha-component-upgrade' ]]; then
213 export TARGET=voltha-comp-upgrade-test
214 fi
215 if [[ ${name} == 'voltha-component-rolling-upgrade' ]]; then
216 export TARGET=voltha-comp-rolling-upgrade-test
217 fi
218 if [ ${name} == 'onu-software-upgrade' ] || [ ${name} == 'onu-software-upgrade-omci-extended-msg' ]; then
219 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v image_version:${onuImageVersion.trim()} -v image_url:${onuImageUrl.trim()} -v image_vendor:${onuImageVendor.trim()} -v image_activate_on_success:${onuImageActivateOnSuccess.trim()} -v image_commit_on_success:${onuImageCommitOnSuccess.trim()} -v image_crc:${onuImageCrc.trim()} -e PowerSwitch"
220 export TARGET=onu-upgrade-test
221 fi
222 if [[ ${name} == 'onu-image-dwl-simultaneously' ]]; then
223 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v image_version:${onuImageVersion.trim()} -v image_url:${onuImageUrl.trim()} -v image_vendor:${onuImageVendor.trim()} -v image_activate_on_success:${onuImageActivateOnSuccess.trim()} -v image_commit_on_success:${onuImageCommitOnSuccess.trim()} -v image_crc:${onuImageCrc.trim()} -e PowerSwitch"
224 export TARGET=onu-upgrade-test-multiolt-kind-att
225 fi
226 testLogging='False'
227 if [ ${logging} = true ]; then
228 testLogging='True'
229 fi
230 export VOLTCONFIG=$HOME/.volt/config-minimal
231 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
232 ROBOT_MISC_ARGS+=" -v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:${logsDir} -v logging:\$testLogging"
233 # Run the specified tests
234 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
235 """
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400236
237 pkill_proc('port-forw')
238 // remove port-forwarding
239 /*
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400240 sh """
241 # remove orphaned port-forward from different namespaces
242 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
243 """
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400244 */
245
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400246 // collect pod details
247 get_pods_info("$WORKSPACE/${name}")
248 sh """
249 set +e
250 # collect logs collected in the Robot Framework StartLogging keyword
251 cd ${logsDir}
252 gzip *-combined.log || true
253 rm *-combined.log || true
254 """
255 helmTeardown(['infra', 'voltha'])
256 }
257 }
258}
259def get_pods_info(dest) {
260 // collect pod details, this is here in case of failure
261 sh """
262 mkdir -p ${dest} || true
263 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
264 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
265 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
266 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
267 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
268 helm ls --all-namespaces > ${dest}/helm-charts.txt
269 """
270 sh '''
271 # copy the ONOS logs directly from the container to avoid the color codes
272 printf '%s\\n' $(kubectl get pods -n infra -l app=onos-classic -o=jsonpath="{.items[*]['metadata.name']}") | xargs --no-run-if-empty -I# bash -c 'kubectl -n infra cp #:apache-karaf-4.2.14/data/log/karaf.log ''' + dest + '''/#.log' || true
273 '''
274}
275pipeline {
276 /* no label, executor is determined by JJB */
277 agent {
278 label "${params.buildNode}"
279 }
280 options {
281 timeout(time: 220, unit: 'MINUTES')
282 }
283 environment {
284 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
285 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
286 SSHPASS="karaf"
287 }
288 stages{
289 stage('Download Code') {
290 steps {
291 getVolthaCode([
292 branch: "${branch}",
293 volthaSystemTestsChange: "${volthaSystemTestsChange}",
294 volthaHelmChartsChange: "${volthaHelmChartsChange}",
295 ])
296 }
297 }
Joey Armstrongdeb75292023-08-24 17:06:33 -0400298
299 // -----------------------------------------------------------------------
300 // -----------------------------------------------------------------------
Joey Armstrong39f90382023-08-24 20:37:40 -0400301 stage('Install Tools') {
302 steps {
303 script {
304 String branchName = branchName()
Joey Armstrongdeb75292023-08-24 17:06:33 -0400305 String iam = getIam('Install Kind')
Joey Armstrong39f90382023-08-24 20:37:40 -0400306
307 println("${iam}: ENTER (branch=$branch)")
308 installKind(branch) // needed early by stage(Cleanup)
309 println("${iam}: LEAVE (branch=$branch)")
Joey Armstrongdeb75292023-08-24 17:06:33 -0400310 } // script
311 } // steps
312 } // stage
313
314 // -----------------------------------------------------------------------
315 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400316 stage('Cleanup') {
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400317 steps {
318 script {
319 pgrep_proc('port-forw')
320 pkill_proc('port-forw')
321 } // script
322 helmTeardown(['infra', 'voltha'])
323 } // steps
324 } // stage
325
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400326 stage('Create K8s Cluster') {
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400327 steps {
328 createKubernetesCluster([nodes: 3])
329 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400330 }
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400331
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400332 stage('Run Test') {
333 steps {
334 test_software_upgrade("onos-app-upgrade")
335 test_software_upgrade("voltha-component-upgrade")
336 test_software_upgrade("voltha-component-rolling-upgrade")
337 test_software_upgrade("onu-software-upgrade")
338 test_software_upgrade("onu-software-upgrade-omci-extended-msg")
339 test_software_upgrade("onu-image-dwl-simultaneously")
340 }
341 }
342 }
343 post {
344 aborted {
345 get_pods_info("$WORKSPACE/failed")
346 }
347 failure {
348 get_pods_info("$WORKSPACE/failed")
349 }
350 always {
351 step([$class: 'RobotPublisher',
352 disableArchiveOutput: false,
353 logFileName: 'RobotLogs/*/log*.html',
354 otherFiles: '',
355 outputFileName: 'RobotLogs/*/output*.xml',
356 outputPath: '.',
357 passThreshold: 100,
358 reportFileName: 'RobotLogs/*/report*.html',
359 unstableThreshold: 0,
360 onlyCritical: true]);
361 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
362 }
363 }
364}
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400365
366// [EOF]