blob: 88fb129f2ea6970ad4d13f684dc79f9285ad1023 [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"
Matteo Scandolof593a0f2021-04-14 10:16:06 -070026 stage('Deploy Voltha - '+ name) {
Matteo Scandolo4b040342021-10-08 14:26:06 -070027 timeout(10) {
Hardik Windlasscb955822021-10-21 14:59:11 +000028 // start logging
29 sh """
30 rm -rf $WORKSPACE/${name} || true
31 mkdir -p $WORKSPACE/${name}
32 _TAG=kail-${name} kail -n ${infraNamespace} -n ${volthaNamespace} > $WORKSPACE/${name}/onos-voltha-startup-combined.log &
33 """
Andrea Campanella9e41a602021-09-14 14:45:11 +020034 def extraHelmFlags = extraHelmFlags.trim()
Hardik Windlasscb955822021-10-21 14:59:11 +000035 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 -070036
Andrea Campanella834f27b2021-06-08 17:08:41 +020037 extraHelmFlags = extraHelmFlags + " --set onos-classic.onosSshPort=30115 --set onos-classic.onosApiPort=30120 "
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000038 extraHelmFlags = extraHelmFlags + " --set voltha.onos_classic.replicas=3"
Matteo Scandolof593a0f2021-04-14 10:16:06 -070039 //ONOS custom image handling
40 if ( onosImg.trim() != '' ) {
41 String[] split;
42 onosImg = onosImg.trim()
43 split = onosImg.split(':')
44 extraHelmFlags = extraHelmFlags + "--set onos-classic.image.repository=" + split[0] +",onos-classic.image.tag=" + split[1] + " "
45 }
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000046 def localCharts = false
47 if (branch != "master") {
48 localCharts = true
49 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -070050 // Currently only testing with ATT workflow
51 // TODO: Support for other workflows
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000052 volthaDeploy([workflow: "att", extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Hardik Windlasscb955822021-10-21 14:59:11 +000053 // stop logging
Matteo Scandolof593a0f2021-04-14 10:16:06 -070054 sh """
Hardik Windlasscb955822021-10-21 14:59:11 +000055 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
56 if [ -n "\$P_IDS" ]; then
57 echo \$P_IDS
58 for P_ID in \$P_IDS; do
59 kill -9 \$P_ID
60 done
61 fi
62 cd $WORKSPACE/${name}/
63 gzip -k onos-voltha-startup-combined.log
64 rm onos-voltha-startup-combined.log
Matteo Scandolof593a0f2021-04-14 10:16:06 -070065 """
66 // forward ONOS and VOLTHA ports
67 sh """
68 _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 &"
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 8181:8181; done &"
70 _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 &"
71 """
72 sh """
73 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
74 """
Matteo Scandolo4b040342021-10-08 14:26:06 -070075 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -070076 }
77 stage('Test - '+ name) {
Matteo Scandolo4b040342021-10-08 14:26:06 -070078 timeout(20) {
Matteo Scandolof593a0f2021-04-14 10:16:06 -070079 sh """
80 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
81 mkdir -p \$ROBOT_LOGS_DIR
82 if [[ ${name} == 'onos-app-upgrade' ]]; then
83 export ONOS_APPS_UNDER_TEST+=''
84 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
85 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
86 fi
87 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
88 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
89 fi
90 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
91 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
92 fi
93 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
94 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
95 fi
96 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
97 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
98 fi
99 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
100 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
101 fi
102 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
103 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
104 fi
105 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
106 export TARGET=onos-app-upgrade-test
107 fi
108 if [[ ${name} == 'voltha-component-upgrade' ]]; then
109 export VOLTHA_COMPS_UNDER_TEST+=''
110 if [ ${adapterOpenOltImage.trim()} != '' ]; then
111 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,${adapterOpenOltImage.trim()}*"
112 fi
113 if [ ${adapterOpenOnuImage.trim()} != '' ]; then
114 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,${adapterOpenOnuImage.trim()}*"
115 fi
116 if [ ${rwCoreImage.trim()} != '' ]; then
117 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,${rwCoreImage.trim()}*"
118 fi
119 if [ ${ofAgentImage.trim()} != '' ]; then
120 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,${ofAgentImage.trim()}*"
121 fi
122 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
123 export TARGET=voltha-comp-upgrade-test
124 fi
125 if [[ ${name} == 'onu-software-upgrade' ]]; then
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000126 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 -0700127 export TARGET=onu-upgrade-test
128 fi
Hardik Windlass85491a02021-10-21 17:14:37 +0000129 testLogging='False'
Hardik Windlasscb955822021-10-21 14:59:11 +0000130 if [ ${logging} = true ]; then
Hardik Windlass85491a02021-10-21 17:14:37 +0000131 testLogging='True'
Hardik Windlasscb955822021-10-21 14:59:11 +0000132 fi
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700133 export VOLTCONFIG=$HOME/.volt/config-minimal
134 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
Hardik Windlass85491a02021-10-21 17:14:37 +0000135 ROBOT_MISC_ARGS+=" -v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:$WORKSPACE/RobotLogs/${name} -v logging:\$testLogging"
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700136 # Run the specified tests
137 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
138 """
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700139 // remove port-forwarding
140 sh """
141 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200142 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 -0700143 """
144 // collect pod details
145 get_pods_info("$WORKSPACE/${name}")
146 helmTeardown(['infra', 'voltha'])
Matteo Scandolo4b040342021-10-08 14:26:06 -0700147 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700148 }
149}
150def get_pods_info(dest) {
151 // collect pod details, this is here in case of failure
152 sh """
153 mkdir -p ${dest} || true
154 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
155 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
156 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
157 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
158 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
159 helm ls --all-namespaces > ${dest}/helm-charts.txt
160 """
161 sh '''
162 # copy the ONOS logs directly from the container to avoid the color codes
163 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
164 '''
165}
166pipeline {
167 /* no label, executor is determined by JJB */
168 agent {
169 label "${params.buildNode}"
170 }
171 options {
Hardik Windlass973230d2021-05-17 11:08:59 +0530172 timeout(time: 60, unit: 'MINUTES')
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700173 }
174 environment {
175 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
176 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
177 SSHPASS="karaf"
178 }
179 stages{
180 stage('Download Code') {
181 steps {
182 getVolthaCode([
183 branch: "${branch}",
184 volthaSystemTestsChange: "${volthaSystemTestsChange}",
185 volthaHelmChartsChange: "${volthaHelmChartsChange}",
186 ])
187 }
188 }
189 stage('Cleanup') {
190 steps {
191 // remove port-forwarding
192 sh """
193 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200194 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 -0700195 """
196 helmTeardown(['infra', 'voltha'])
197 }
198 }
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000199 stage('Create K8s Cluster') {
200 steps {
Hardik Windlass6f854a12021-07-12 13:20:21 +0000201 createKubernetesCluster([branch: "${branch}", nodes: 3])
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000202 }
203 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700204 stage('Run Test') {
205 steps {
206 test_software_upgrade("onos-app-upgrade")
207 test_software_upgrade("voltha-component-upgrade")
208 test_software_upgrade("onu-software-upgrade")
209 }
210 }
211 }
212 post {
213 aborted {
214 get_pods_info("$WORKSPACE/failed")
215 }
216 failure {
217 get_pods_info("$WORKSPACE/failed")
218 }
219 always {
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700220 step([$class: 'RobotPublisher',
221 disableArchiveOutput: false,
222 logFileName: 'RobotLogs/*/log*.html',
223 otherFiles: '',
224 outputFileName: 'RobotLogs/*/output*.xml',
225 outputPath: '.',
226 passThreshold: 100,
227 reportFileName: 'RobotLogs/*/report*.html',
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000228 unstableThreshold: 0,
229 onlyCritical: true]);
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700230 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
231 }
232 }
233}