blob: 83ee47b37e3c73b4fce73d576cb5bdd411dbc9e0 [file] [log] [blame]
Hardik Windlass0f9621d2021-02-24 21:23:19 +05301// 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.
Hardik Windlass0f9621d2021-02-24 21:23:19 +053014// voltha-2.x e2e tests
15// uses bbsim to simulate OLT/ONUs
Hardik Windlass0f9621d2021-02-24 21:23:19 +053016// 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])
Hardik Windlass0f9621d2021-02-24 21:23:19 +053023def test_software_upgrade(name) {
24 stage('Deploy Voltha - '+ name) {
Andrea Campanella5764e182021-03-18 14:17:59 +010025 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 "
Hardik Windlassd87caad2021-05-06 06:55:09 +000026 if ("${name}" == "onos-app-upgrade" || "${name}" == "onu-software-upgrade") {
27 extraHelmFlags = extraHelmFlags + "--set global.image_tag=master --set onos-classic.image.tag=master "
28 }
29 if ("${name}" == "voltha-component-upgrade") {
30 extraHelmFlags = extraHelmFlags + "--set images.onos_config_loader.tag=master-onos-config-loader --set onos-classic.image.tag=master "
Hardik Windlassff97f652021-03-18 15:11:13 +053031 }
Andrea Campanella834f27b2021-06-08 17:08:41 +020032 extraHelmFlags = extraHelmFlags + " --set onos-classic.onosSshPort=30115 --set onos-classic.onosApiPort=30120 "
33 extraHelmFlags = extraHelmFlags + " --set voltha.onos_classic.replicas=3"
Andrea Campanella5764e182021-03-18 14:17:59 +010034 //ONOS custom image handling
35 if ( onosImg.trim() != '' ) {
36 String[] split;
37 onosImg = onosImg.trim()
38 split = onosImg.split(':')
Andrea Campanellaea2379a2021-03-22 13:56:26 +010039 extraHelmFlags = extraHelmFlags + "--set onos-classic.image.repository=" + split[0] +",onos-classic.image.tag=" + split[1] + " "
Andrea Campanella5764e182021-03-18 14:17:59 +010040 }
Hardik Windlass0f9621d2021-02-24 21:23:19 +053041 def localCharts = false
Hardik Windlass0f9621d2021-02-24 21:23:19 +053042 // Currently only testing with ATT workflow
43 // TODO: Support for other workflows
44 volthaDeploy([workflow: "att", extraHelmFlags: extraHelmFlags, localCharts: localCharts])
45 // start logging
46 sh """
Hardik Windlass3db9adf2021-03-25 15:49:45 +053047 rm -rf $WORKSPACE/${name} || true
Hardik Windlass0f9621d2021-02-24 21:23:19 +053048 mkdir -p $WORKSPACE/${name}
49 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
50 """
51 // forward ONOS and VOLTHA ports
52 sh """
Matteo Scandolof593a0f2021-04-14 10:16:06 -070053 _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 &"
54 _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 &"
55 _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 &"
Hardik Windlass0f9621d2021-02-24 21:23:19 +053056 """
Andrea Campanella9eeb4e72021-03-19 10:00:43 +010057 sh """
58 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
59 """
Hardik Windlass0f9621d2021-02-24 21:23:19 +053060 }
61 stage('Test - '+ name) {
62 sh """
Hardik Windlass25c8ddb2021-03-05 20:26:16 +053063 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
64 mkdir -p \$ROBOT_LOGS_DIR
65 if [[ ${name} == 'onos-app-upgrade' ]]; then
66 export ONOS_APPS_UNDER_TEST+=''
Hardik Windlassb360f6e2021-03-09 17:46:21 +053067 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053068 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
69 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053070 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053071 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
72 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053073 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053074 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
75 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053076 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053077 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
78 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053079 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053080 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
81 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053082 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053083 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
84 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053085 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053086 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
Hardik Windlass25c8ddb2021-03-05 20:26:16 +053087 fi
88 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
89 export TARGET=onos-app-upgrade-test
90 fi
91 if [[ ${name} == 'voltha-component-upgrade' ]]; then
92 export VOLTHA_COMPS_UNDER_TEST+=''
Hardik Windlassb360f6e2021-03-09 17:46:21 +053093 if [ ${adapterOpenOltImage.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053094 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,${adapterOpenOltImage.trim()}*"
95 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053096 if [ ${adapterOpenOnuImage.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +053097 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,${adapterOpenOnuImage.trim()}*"
98 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +053099 if [ ${rwCoreImage.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +0530100 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,${rwCoreImage.trim()}*"
101 fi
Hardik Windlassb360f6e2021-03-09 17:46:21 +0530102 if [ ${ofAgentImage.trim()} != '' ]; then
Hardik Windlass98506e72021-03-09 14:29:17 +0530103 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,${ofAgentImage.trim()}*"
Hardik Windlass25c8ddb2021-03-05 20:26:16 +0530104 fi
105 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
106 export TARGET=voltha-comp-upgrade-test
107 fi
Hardik Windlass834afbb2021-03-23 11:48:15 +0530108 if [[ ${name} == 'onu-software-upgrade' ]]; then
Hardik Windlass88814542021-06-22 09:43:46 +0000109 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"
Hardik Windlass834afbb2021-03-23 11:48:15 +0530110 export TARGET=onu-upgrade-test
111 fi
Hardik Windlass25c8ddb2021-03-05 20:26:16 +0530112 export VOLTCONFIG=$HOME/.volt/config-minimal
113 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
Andrea Campanella834f27b2021-06-08 17:08:41 +0200114 ROBOT_MISC_ARGS+=" -v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120"
Hardik Windlass25c8ddb2021-03-05 20:26:16 +0530115 # Run the specified tests
116 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530117 """
118 // stop logging
119 sh """
120 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
121 if [ -n "\$P_IDS" ]; then
122 echo \$P_IDS
123 for P_ID in \$P_IDS; do
124 kill -9 \$P_ID
125 done
126 fi
127 """
128 // remove port-forwarding
129 sh """
130 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200131 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530132 """
133 // collect pod details
Hardik Windlass428f5132021-03-15 12:17:47 +0530134 get_pods_info("$WORKSPACE/${name}")
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530135 helmTeardown(['infra', 'voltha'])
136 }
137}
Hardik Windlass428f5132021-03-15 12:17:47 +0530138def get_pods_info(dest) {
139 // collect pod details, this is here in case of failure
140 sh """
Hardik Windlass3db9adf2021-03-25 15:49:45 +0530141 mkdir -p ${dest} || true
Hardik Windlass428f5132021-03-15 12:17:47 +0530142 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
143 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
144 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
Andrea Campanellaea2379a2021-03-22 13:56:26 +0100145 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
146 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
Hardik Windlass428f5132021-03-15 12:17:47 +0530147 helm ls --all-namespaces > ${dest}/helm-charts.txt
148 """
Andrea Campanella5764e182021-03-18 14:17:59 +0100149 sh '''
150 # copy the ONOS logs directly from the container to avoid the color codes
Andrea Campanella9eeb4e72021-03-19 10:00:43 +0100151 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
Andrea Campanella5764e182021-03-18 14:17:59 +0100152 '''
Hardik Windlass428f5132021-03-15 12:17:47 +0530153}
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530154pipeline {
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530155 /* no label, executor is determined by JJB */
156 agent {
157 label "${params.buildNode}"
158 }
159 options {
Hardik Windlass973230d2021-05-17 11:08:59 +0530160 timeout(time: 60, unit: 'MINUTES')
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530161 }
162 environment {
163 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Hardik Windlass25c8ddb2021-03-05 20:26:16 +0530164 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
Andrea Campanella9eeb4e72021-03-19 10:00:43 +0100165 SSHPASS="karaf"
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530166 }
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530167 stages{
168 stage('Download Code') {
169 steps {
170 getVolthaCode([
171 branch: "${branch}",
172 volthaSystemTestsChange: "${volthaSystemTestsChange}",
173 volthaHelmChartsChange: "${volthaHelmChartsChange}",
174 ])
175 }
176 }
Hardik Windlass834afbb2021-03-23 11:48:15 +0530177 stage('Cleanup') {
178 steps {
179 // remove port-forwarding
180 sh """
181 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200182 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
Hardik Windlass834afbb2021-03-23 11:48:15 +0530183 """
184 helmTeardown(['infra', 'voltha'])
185 }
186 }
Hardik Windlassabd342c2021-03-25 12:20:43 +0530187 stage('Install latest voltctl') {
188 steps {
189 sh """
Hardik Windlass60230a22021-04-01 12:20:52 +0530190 mkdir -p $WORKSPACE/bin || true
Hardik Windlassabd342c2021-03-25 12:20:43 +0530191 # install voltctl
192 HOSTOS="\$(uname -s | tr "[:upper:]" "[:lower:"])"
193 HOSTARCH="\$(uname -m | tr "[:upper:]" "[:lower:"])"
194 if [ "\$HOSTARCH" == "x86_64" ]; then
195 HOSTARCH="amd64"
196 fi
197 VC_VERSION="\$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')"
198 curl -Lo $WORKSPACE/bin/voltctl https://github.com/opencord/voltctl/releases/download/v\$VC_VERSION/voltctl-\$VC_VERSION-\$HOSTOS-\$HOSTARCH
199 chmod +x $WORKSPACE/bin/voltctl
200 """
201 }
202 }
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000203 stage('Create K8s Cluster') {
204 steps {
205 createKubernetesCluster([nodes: 3])
206 }
207 }
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530208 stage('Run Test') {
209 steps {
210 test_software_upgrade("onos-app-upgrade")
211 test_software_upgrade("voltha-component-upgrade")
Hardik Windlass834afbb2021-03-23 11:48:15 +0530212 test_software_upgrade("onu-software-upgrade")
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530213 }
214 }
215 }
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530216 post {
Hardik Windlass428f5132021-03-15 12:17:47 +0530217 aborted {
218 get_pods_info("$WORKSPACE/failed")
219 }
220 failure {
221 get_pods_info("$WORKSPACE/failed")
222 }
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530223 always {
224 sh '''
225 gzip $WORKSPACE/onos-app-upgrade/onos-voltha-combined.log || true
226 gzip $WORKSPACE/voltha-component-upgrade/onos-voltha-combined.log || true
Hardik Windlass834afbb2021-03-23 11:48:15 +0530227 gzip $WORKSPACE/onu-software-upgrade/onos-voltha-combined.log || true
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530228 '''
229 step([$class: 'RobotPublisher',
230 disableArchiveOutput: false,
231 logFileName: 'RobotLogs/*/log*.html',
232 otherFiles: '',
233 outputFileName: 'RobotLogs/*/output*.xml',
234 outputPath: '.',
235 passThreshold: 100,
236 reportFileName: 'RobotLogs/*/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200237 unstableThreshold: 0,
238 onlyCritical: true]);
Hardik Windlass428f5132021-03-15 12:17:47 +0530239 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Hardik Windlass0f9621d2021-02-24 21:23:19 +0530240 }
241 }
242}