blob: c4c70453e029acbf090d1c039e7e05e4989f71b4 [file] [log] [blame]
Matteo Scandolof593a0f2021-04-14 10:16:06 -07001// Copyright 2021-present Open Networking Foundation
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])
23def test_software_upgrade(name) {
Hardik Windlasscb955822021-10-21 14:59:11 +000024 def infraNamespace = "infra"
25 def volthaNamespace = "voltha"
Hardik Windlassdad8e5c2021-11-11 05:19:47 +000026 def logsDir = "$WORKSPACE/${name}"
Matteo Scandolof593a0f2021-04-14 10:16:06 -070027 stage('Deploy Voltha - '+ name) {
Matteo Scandolo4b040342021-10-08 14:26:06 -070028 timeout(10) {
Hardik Windlasscb955822021-10-21 14:59:11 +000029 // start logging
30 sh """
Hardik Windlassdad8e5c2021-11-11 05:19:47 +000031 rm -rf ${logsDir} || true
32 mkdir -p ${logsDir}
33 _TAG=kail-${name} kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
Hardik Windlasscb955822021-10-21 14:59:11 +000034 """
Andrea Campanella9e41a602021-09-14 14:45:11 +020035 def extraHelmFlags = extraHelmFlags.trim()
TorstenThieme6bb872e2022-03-04 12:54:09 +000036 if ("${name}" == "onos-app-upgrade" || "${name}" == "onu-software-upgrade" || "${name}" == "voltha-component-upgrade" || "${name}" == "voltha-component-rolling-upgrade") {
37 extraHelmFlags = " --set global.log_level=${logLevel.toUpperCase()},onu=1,pon=1 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 " + extraHelmFlags
38 }
39 if ("${name}" == "onu-image-dwl-simultaneously") {
40 extraHelmFlags = " --set global.log_level=${logLevel.toUpperCase()},onu=2,pon=2 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 " + extraHelmFlags
41 }
Matteo Scandolo4b040342021-10-08 14:26:06 -070042
Andrea Campanella0442dd02021-12-30 15:44:34 +010043 extraHelmFlags = " --set onos-classic.onosSshPort=30115 --set onos-classic.onosApiPort=30120 " + extraHelmFlags
44 extraHelmFlags = " --set voltha.onos_classic.replicas=3 " + extraHelmFlags
Matteo Scandolof593a0f2021-04-14 10:16:06 -070045 //ONOS custom image handling
46 if ( onosImg.trim() != '' ) {
47 String[] split;
48 onosImg = onosImg.trim()
49 split = onosImg.split(':')
Andrea Campanella0442dd02021-12-30 15:44:34 +010050 extraHelmFlags = extraHelmFlags + " --set onos-classic.image.repository=" + split[0] +",onos-classic.image.tag=" + split[1] + " "
Matteo Scandolof593a0f2021-04-14 10:16:06 -070051 }
TorstenThieme6bb872e2022-03-04 12:54:09 +000052 def olts = 1
53 if ("${name}" == "onu-image-dwl-simultaneously") {
54 olts = 2
55 }
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000056 def localCharts = false
57 if (branch != "master") {
58 localCharts = true
59 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -070060 // Currently only testing with ATT workflow
61 // TODO: Support for other workflows
TorstenThieme6bb872e2022-03-04 12:54:09 +000062 volthaDeploy([bbsimReplica: olts.toInteger(), workflow: "att", extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Hardik Windlasscb955822021-10-21 14:59:11 +000063 // stop logging
Matteo Scandolof593a0f2021-04-14 10:16:06 -070064 sh """
Hardik Windlasscb955822021-10-21 14:59:11 +000065 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
66 if [ -n "\$P_IDS" ]; then
67 echo \$P_IDS
68 for P_ID in \$P_IDS; do
69 kill -9 \$P_ID
70 done
71 fi
Hardik Windlassdad8e5c2021-11-11 05:19:47 +000072 cd ${logsDir}
Hardik Windlasscb955822021-10-21 14:59:11 +000073 gzip -k onos-voltha-startup-combined.log
74 rm onos-voltha-startup-combined.log
Matteo Scandolof593a0f2021-04-14 10:16:06 -070075 """
76 // forward ONOS and VOLTHA ports
77 sh """
78 _TAG=onos-port-forward bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101; done &"
79 _TAG=onos-port-forward bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181; done &"
80 _TAG=port-forward-voltha-api bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555; done &"
81 """
82 sh """
83 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
84 """
Matteo Scandolo4b040342021-10-08 14:26:06 -070085 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -070086 }
87 stage('Test - '+ name) {
TorstenThieme6bb872e2022-03-04 12:54:09 +000088 timeout(60) {
Matteo Scandolof593a0f2021-04-14 10:16:06 -070089 sh """
90 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
91 mkdir -p \$ROBOT_LOGS_DIR
92 if [[ ${name} == 'onos-app-upgrade' ]]; then
93 export ONOS_APPS_UNDER_TEST+=''
94 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
95 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
96 fi
97 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
98 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
99 fi
100 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
101 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
102 fi
103 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
104 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
105 fi
106 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
107 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
108 fi
109 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
110 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
111 fi
112 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
113 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
114 fi
115 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
116 export TARGET=onos-app-upgrade-test
117 fi
118 if [[ ${name} == 'voltha-component-upgrade' ]]; then
119 export VOLTHA_COMPS_UNDER_TEST+=''
120 if [ ${adapterOpenOltImage.trim()} != '' ]; then
121 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,${adapterOpenOltImage.trim()}*"
122 fi
123 if [ ${adapterOpenOnuImage.trim()} != '' ]; then
124 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,${adapterOpenOnuImage.trim()}*"
125 fi
126 if [ ${rwCoreImage.trim()} != '' ]; then
127 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,${rwCoreImage.trim()}*"
128 fi
129 if [ ${ofAgentImage.trim()} != '' ]; then
130 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,${ofAgentImage.trim()}*"
131 fi
132 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
133 export TARGET=voltha-comp-upgrade-test
134 fi
135 if [[ ${name} == 'onu-software-upgrade' ]]; then
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000136 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"
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700137 export TARGET=onu-upgrade-test
138 fi
TorstenThieme6bb872e2022-03-04 12:54:09 +0000139 if [[ ${name} == 'onu-image-dwl-simultaneously' ]]; then
140 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"
141 export TARGET=onu-upgrade-test-multiolt-kind-att
142 fi
Hardik Windlass85491a02021-10-21 17:14:37 +0000143 testLogging='False'
Hardik Windlasscb955822021-10-21 14:59:11 +0000144 if [ ${logging} = true ]; then
Hardik Windlass85491a02021-10-21 17:14:37 +0000145 testLogging='True'
Hardik Windlasscb955822021-10-21 14:59:11 +0000146 fi
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700147 export VOLTCONFIG=$HOME/.volt/config-minimal
148 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000149 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"
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700150 # Run the specified tests
151 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
152 """
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700153 // remove port-forwarding
154 sh """
155 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200156 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700157 """
158 // collect pod details
159 get_pods_info("$WORKSPACE/${name}")
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000160 sh """
161 set +e
162 # collect logs collected in the Robot Framework StartLogging keyword
163 cd ${logsDir}
164 gzip *-combined.log || true
165 rm *-combined.log || true
166 """
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700167 helmTeardown(['infra', 'voltha'])
Matteo Scandolo4b040342021-10-08 14:26:06 -0700168 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700169 }
170}
171def get_pods_info(dest) {
172 // collect pod details, this is here in case of failure
173 sh """
174 mkdir -p ${dest} || true
175 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
176 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
177 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
178 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
179 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
180 helm ls --all-namespaces > ${dest}/helm-charts.txt
181 """
182 sh '''
183 # copy the ONOS logs directly from the container to avoid the color codes
184 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.9/data/log/karaf.log ''' + dest + '''/#.log' || true
185 '''
186}
187pipeline {
188 /* no label, executor is determined by JJB */
189 agent {
190 label "${params.buildNode}"
191 }
192 options {
TorstenThieme6bb872e2022-03-04 12:54:09 +0000193 timeout(time: 120, unit: 'MINUTES')
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700194 }
195 environment {
196 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
197 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
198 SSHPASS="karaf"
199 }
200 stages{
201 stage('Download Code') {
202 steps {
203 getVolthaCode([
204 branch: "${branch}",
205 volthaSystemTestsChange: "${volthaSystemTestsChange}",
206 volthaHelmChartsChange: "${volthaHelmChartsChange}",
207 ])
208 }
209 }
210 stage('Cleanup') {
211 steps {
212 // remove port-forwarding
213 sh """
214 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200215 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700216 """
217 helmTeardown(['infra', 'voltha'])
218 }
219 }
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000220 stage('Create K8s Cluster') {
221 steps {
Hardik Windlass6f854a12021-07-12 13:20:21 +0000222 createKubernetesCluster([branch: "${branch}", nodes: 3])
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000223 }
224 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700225 stage('Run Test') {
226 steps {
227 test_software_upgrade("onos-app-upgrade")
228 test_software_upgrade("voltha-component-upgrade")
229 test_software_upgrade("onu-software-upgrade")
TorstenThieme6bb872e2022-03-04 12:54:09 +0000230 test_software_upgrade("onu-image-dwl-simultaneously")
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700231 }
232 }
233 }
234 post {
235 aborted {
236 get_pods_info("$WORKSPACE/failed")
237 }
238 failure {
239 get_pods_info("$WORKSPACE/failed")
240 }
241 always {
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700242 step([$class: 'RobotPublisher',
243 disableArchiveOutput: false,
244 logFileName: 'RobotLogs/*/log*.html',
245 otherFiles: '',
246 outputFileName: 'RobotLogs/*/output*.xml',
247 outputPath: '.',
248 passThreshold: 100,
249 reportFileName: 'RobotLogs/*/report*.html',
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000250 unstableThreshold: 0,
251 onlyCritical: true]);
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700252 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
253 }
254 }
255}