blob: 8cae8d67ec48d63cfbab1046884ddfd9e526be34 [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()
Hardik Windlasscb955822021-10-21 14:59:11 +000036 extraHelmFlags = extraHelmFlags + " --set global.log_level=${logLevel.toUpperCase()},onu=1,pon=1 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 "
Matteo Scandolo4b040342021-10-08 14:26:06 -070037
Andrea Campanella834f27b2021-06-08 17:08:41 +020038 extraHelmFlags = extraHelmFlags + " --set onos-classic.onosSshPort=30115 --set onos-classic.onosApiPort=30120 "
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000039 extraHelmFlags = extraHelmFlags + " --set voltha.onos_classic.replicas=3"
Matteo Scandolof593a0f2021-04-14 10:16:06 -070040 //ONOS custom image handling
41 if ( onosImg.trim() != '' ) {
42 String[] split;
43 onosImg = onosImg.trim()
44 split = onosImg.split(':')
45 extraHelmFlags = extraHelmFlags + "--set onos-classic.image.repository=" + split[0] +",onos-classic.image.tag=" + split[1] + " "
46 }
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000047 def localCharts = false
48 if (branch != "master") {
49 localCharts = true
50 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -070051 // Currently only testing with ATT workflow
52 // TODO: Support for other workflows
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000053 volthaDeploy([workflow: "att", extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Hardik Windlasscb955822021-10-21 14:59:11 +000054 // stop logging
Matteo Scandolof593a0f2021-04-14 10:16:06 -070055 sh """
Hardik Windlasscb955822021-10-21 14:59:11 +000056 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
57 if [ -n "\$P_IDS" ]; then
58 echo \$P_IDS
59 for P_ID in \$P_IDS; do
60 kill -9 \$P_ID
61 done
62 fi
Hardik Windlassdad8e5c2021-11-11 05:19:47 +000063 cd ${logsDir}
Hardik Windlasscb955822021-10-21 14:59:11 +000064 gzip -k onos-voltha-startup-combined.log
65 rm onos-voltha-startup-combined.log
Matteo Scandolof593a0f2021-04-14 10:16:06 -070066 """
67 // forward ONOS and VOLTHA ports
68 sh """
69 _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 &"
70 _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 &"
71 _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 &"
72 """
73 sh """
74 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
75 """
Matteo Scandolo4b040342021-10-08 14:26:06 -070076 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -070077 }
78 stage('Test - '+ name) {
Matteo Scandolo4b040342021-10-08 14:26:06 -070079 timeout(20) {
Matteo Scandolof593a0f2021-04-14 10:16:06 -070080 sh """
81 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
82 mkdir -p \$ROBOT_LOGS_DIR
83 if [[ ${name} == 'onos-app-upgrade' ]]; then
84 export ONOS_APPS_UNDER_TEST+=''
85 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
86 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
87 fi
88 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
89 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
90 fi
91 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
92 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
93 fi
94 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
95 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
96 fi
97 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
98 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
99 fi
100 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
101 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
102 fi
103 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
104 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
105 fi
106 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
107 export TARGET=onos-app-upgrade-test
108 fi
109 if [[ ${name} == 'voltha-component-upgrade' ]]; then
110 export VOLTHA_COMPS_UNDER_TEST+=''
111 if [ ${adapterOpenOltImage.trim()} != '' ]; then
112 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,${adapterOpenOltImage.trim()}*"
113 fi
114 if [ ${adapterOpenOnuImage.trim()} != '' ]; then
115 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,${adapterOpenOnuImage.trim()}*"
116 fi
117 if [ ${rwCoreImage.trim()} != '' ]; then
118 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,${rwCoreImage.trim()}*"
119 fi
120 if [ ${ofAgentImage.trim()} != '' ]; then
121 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,${ofAgentImage.trim()}*"
122 fi
123 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
124 export TARGET=voltha-comp-upgrade-test
125 fi
126 if [[ ${name} == 'onu-software-upgrade' ]]; then
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000127 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 -0700128 export TARGET=onu-upgrade-test
129 fi
Hardik Windlass85491a02021-10-21 17:14:37 +0000130 testLogging='False'
Hardik Windlasscb955822021-10-21 14:59:11 +0000131 if [ ${logging} = true ]; then
Hardik Windlass85491a02021-10-21 17:14:37 +0000132 testLogging='True'
Hardik Windlasscb955822021-10-21 14:59:11 +0000133 fi
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700134 export VOLTCONFIG=$HOME/.volt/config-minimal
135 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000136 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 -0700137 # Run the specified tests
138 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
139 """
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700140 // remove port-forwarding
141 sh """
142 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200143 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 -0700144 """
145 // collect pod details
146 get_pods_info("$WORKSPACE/${name}")
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000147 sh """
148 set +e
149 # collect logs collected in the Robot Framework StartLogging keyword
150 cd ${logsDir}
151 gzip *-combined.log || true
152 rm *-combined.log || true
153 """
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700154 helmTeardown(['infra', 'voltha'])
Matteo Scandolo4b040342021-10-08 14:26:06 -0700155 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700156 }
157}
158def get_pods_info(dest) {
159 // collect pod details, this is here in case of failure
160 sh """
161 mkdir -p ${dest} || true
162 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
163 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
164 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
165 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
166 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
167 helm ls --all-namespaces > ${dest}/helm-charts.txt
168 """
169 sh '''
170 # copy the ONOS logs directly from the container to avoid the color codes
171 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
172 '''
173}
174pipeline {
175 /* no label, executor is determined by JJB */
176 agent {
177 label "${params.buildNode}"
178 }
179 options {
Hardik Windlass973230d2021-05-17 11:08:59 +0530180 timeout(time: 60, unit: 'MINUTES')
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700181 }
182 environment {
183 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
184 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
185 SSHPASS="karaf"
186 }
187 stages{
188 stage('Download Code') {
189 steps {
190 getVolthaCode([
191 branch: "${branch}",
192 volthaSystemTestsChange: "${volthaSystemTestsChange}",
193 volthaHelmChartsChange: "${volthaHelmChartsChange}",
194 ])
195 }
196 }
197 stage('Cleanup') {
198 steps {
199 // remove port-forwarding
200 sh """
201 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200202 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 -0700203 """
204 helmTeardown(['infra', 'voltha'])
205 }
206 }
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000207 stage('Create K8s Cluster') {
208 steps {
Hardik Windlass6f854a12021-07-12 13:20:21 +0000209 createKubernetesCluster([branch: "${branch}", nodes: 3])
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000210 }
211 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700212 stage('Run Test') {
213 steps {
214 test_software_upgrade("onos-app-upgrade")
215 test_software_upgrade("voltha-component-upgrade")
216 test_software_upgrade("onu-software-upgrade")
217 }
218 }
219 }
220 post {
221 aborted {
222 get_pods_info("$WORKSPACE/failed")
223 }
224 failure {
225 get_pods_info("$WORKSPACE/failed")
226 }
227 always {
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700228 step([$class: 'RobotPublisher',
229 disableArchiveOutput: false,
230 logFileName: 'RobotLogs/*/log*.html',
231 otherFiles: '',
232 outputFileName: 'RobotLogs/*/output*.xml',
233 outputPath: '.',
234 passThreshold: 100,
235 reportFileName: 'RobotLogs/*/report*.html',
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000236 unstableThreshold: 0,
237 onlyCritical: true]);
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700238 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
239 }
240 }
241}