blob: 449e64aa6e29da75858a5da5d8414dfef1057ead [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 Armstrongdd0cd6b2023-08-25 17:27:56 -0400147 // stop logging
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400148 sh """
149 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
150 if [ -n "\$P_IDS" ]; then
151 echo \$P_IDS
152 for P_ID in \$P_IDS; do
153 kill -9 \$P_ID
154 done
155 fi
156 cd ${logsDir}
157 gzip -k onos-voltha-startup-combined.log
158 rm onos-voltha-startup-combined.log
159 """
160 // forward ONOS and VOLTHA ports
Joey Armstrongdeb75292023-08-24 17:06:33 -0400161 sh('''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400162 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 " &
163 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 " &
164 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 -0400165 ''')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400166 sh """
167 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
168 """
169 }
170 }
171 stage('Test - '+ name) {
172 timeout(75) {
173 sh """
174 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
175 mkdir -p \$ROBOT_LOGS_DIR
176 if [[ ${name} == 'onos-app-upgrade' ]]; then
177 export ONOS_APPS_UNDER_TEST+=''
178 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
179 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
180 fi
181 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
182 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
183 fi
184 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
185 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
186 fi
187 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
188 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
189 fi
190 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
191 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
192 fi
193 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
194 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
195 fi
196 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
197 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
198 fi
199 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
200 export TARGET=onos-app-upgrade-test
201 fi
202 if [ ${name} == 'voltha-component-upgrade' ] || [ ${name} == 'voltha-component-rolling-upgrade' ]; then
203 export VOLTHA_COMPS_UNDER_TEST+=''
204 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,voltha/voltha-openolt-adapter:${openolt_adapter_test_tag}*"
205 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,voltha/voltha-openonu-adapter-go:${openonu_adapter_test_tag}*"
206 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,voltha/voltha-rw-core:${rw_core_test_tag}*"
207 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,voltha/voltha-ofagent-go:${ofagent_test_tag}*"
208 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
209 fi
210 if [[ ${name} == 'voltha-component-upgrade' ]]; then
211 export TARGET=voltha-comp-upgrade-test
212 fi
213 if [[ ${name} == 'voltha-component-rolling-upgrade' ]]; then
214 export TARGET=voltha-comp-rolling-upgrade-test
215 fi
216 if [ ${name} == 'onu-software-upgrade' ] || [ ${name} == 'onu-software-upgrade-omci-extended-msg' ]; then
217 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"
218 export TARGET=onu-upgrade-test
219 fi
220 if [[ ${name} == 'onu-image-dwl-simultaneously' ]]; then
221 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"
222 export TARGET=onu-upgrade-test-multiolt-kind-att
223 fi
224 testLogging='False'
225 if [ ${logging} = true ]; then
226 testLogging='True'
227 fi
228 export VOLTCONFIG=$HOME/.volt/config-minimal
229 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
230 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"
231 # Run the specified tests
232 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
233 """
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400234 // remove port-forwarding
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400235 sh """
236 # remove orphaned port-forward from different namespaces
237 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
238 """
239 // collect pod details
240 get_pods_info("$WORKSPACE/${name}")
241 sh """
242 set +e
243 # collect logs collected in the Robot Framework StartLogging keyword
244 cd ${logsDir}
245 gzip *-combined.log || true
246 rm *-combined.log || true
247 """
248 helmTeardown(['infra', 'voltha'])
249 }
250 }
251}
252def get_pods_info(dest) {
253 // collect pod details, this is here in case of failure
254 sh """
255 mkdir -p ${dest} || true
256 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
257 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
258 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
259 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
260 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
261 helm ls --all-namespaces > ${dest}/helm-charts.txt
262 """
263 sh '''
264 # copy the ONOS logs directly from the container to avoid the color codes
265 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
266 '''
267}
268pipeline {
269 /* no label, executor is determined by JJB */
270 agent {
271 label "${params.buildNode}"
272 }
273 options {
274 timeout(time: 220, unit: 'MINUTES')
275 }
276 environment {
277 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
278 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
279 SSHPASS="karaf"
280 }
281 stages{
282 stage('Download Code') {
283 steps {
284 getVolthaCode([
285 branch: "${branch}",
286 volthaSystemTestsChange: "${volthaSystemTestsChange}",
287 volthaHelmChartsChange: "${volthaHelmChartsChange}",
288 ])
289 }
290 }
Joey Armstrongdeb75292023-08-24 17:06:33 -0400291
292 // -----------------------------------------------------------------------
293 // -----------------------------------------------------------------------
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400294 stage('Install Tools')
295 {
296 steps
297 {
298 script
299 {
Joey Armstrongdeb75292023-08-24 17:06:33 -0400300 String iam = getIam('Install Kind')
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400301 println("${iam}: ENTER")
302 installKind("$branch") // needed early by stage(Cleanup)
303 println("${iam}: LEAVE")
Joey Armstrongdeb75292023-08-24 17:06:33 -0400304 } // script
305 } // steps
306 } // stage
307
308 // -----------------------------------------------------------------------
309 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400310 stage('Cleanup') {
Joey Armstrongb9a6f122023-08-24 22:00:04 -0400311 steps {
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400312
313 script {
314 println('''
315** -----------------------------------------------------------------------
316** Raw process listing
317** -----------------------------------------------------------------------
318''')
319 sh(''' ps faaux ''')
320
321 println('''
322** -----------------------------------------------------------------------
323** pgrep --list-full port
324** -----------------------------------------------------------------------
325''')
326 sh(''' set +euo pipefail && pgrep --list-full 'port' ''')
327 }
328
329 // remove port-forwarding
330 sh """
331 # remove orphaned port-forward from different namespaces
332 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
333 """
334 helmTeardown(['infra', 'voltha'])
335 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400336 }
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400337 stage('Create K8s Cluster') {
338 steps {
339 createKubernetesCluster([nodes: 3])
340 }
341 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400342 stage('Run Test') {
343 steps {
344 test_software_upgrade("onos-app-upgrade")
345 test_software_upgrade("voltha-component-upgrade")
346 test_software_upgrade("voltha-component-rolling-upgrade")
347 test_software_upgrade("onu-software-upgrade")
348 test_software_upgrade("onu-software-upgrade-omci-extended-msg")
349 test_software_upgrade("onu-image-dwl-simultaneously")
350 }
351 }
352 }
353 post {
354 aborted {
355 get_pods_info("$WORKSPACE/failed")
356 }
357 failure {
358 get_pods_info("$WORKSPACE/failed")
359 }
360 always {
361 step([$class: 'RobotPublisher',
362 disableArchiveOutput: false,
363 logFileName: 'RobotLogs/*/log*.html',
364 otherFiles: '',
365 outputFileName: 'RobotLogs/*/output*.xml',
366 outputPath: '.',
367 passThreshold: 100,
368 reportFileName: 'RobotLogs/*/report*.html',
369 unstableThreshold: 0,
370 onlyCritical: true]);
371 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
372 }
373 }
374}