blob: ef28597f50010ac564ab6acd9bda61f21a9632b1 [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) {
24 stage('Deploy Voltha - '+ name) {
25 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 --set onos-classic.replicas=3,onos-classic.atomix.replicas=3 "
Matteo Scandoloc297a4c2021-04-15 11:27:27 -070026
Matteo Scandolof593a0f2021-04-14 10:16:06 -070027 extraHelmFlags = extraHelmFlags + """ --set voltha.services.controller[0].service=voltha-infra-onos-classic-0.voltha-infra-onos-classic-hs.infra.svc \
28 --set voltha.services.controller[0].port=6653 \
29 --set voltha.services.controller[0].address=voltha-infra-onos-classic-0.voltha-infra-onos-classic-hs.infra.svc:6653 \
30 --set voltha.services.controller[1].service=voltha-infra-onos-classic-1.voltha-infra-onos-classic-hs.infra.svc \
31 --set voltha.services.controller[1].port=6653 \
32 --set voltha.services.controller[1].address=voltha-infra-onos-classic-1.voltha-infra-onos-classic-hs.infra.svc:6653 \
33 --set voltha.services.controller[2].service=voltha-infra-onos-classic-2.voltha-infra-onos-classic-hs.infra.svc \
34 --set voltha.services.controller[2].port=6653 \
35 --set voltha.services.controller[2].address=voltha-infra-onos-classic-2.voltha-infra-onos-classic-hs.infra.svc:6653 """
36 //ONOS custom image handling
37 if ( onosImg.trim() != '' ) {
38 String[] split;
39 onosImg = onosImg.trim()
40 split = onosImg.split(':')
41 extraHelmFlags = extraHelmFlags + "--set onos-classic.image.repository=" + split[0] +",onos-classic.image.tag=" + split[1] + " "
42 }
Matteo Scandoloc297a4c2021-04-15 11:27:27 -070043
Matteo Scandolof593a0f2021-04-14 10:16:06 -070044 // Currently only testing with ATT workflow
45 // TODO: Support for other workflows
Matteo Scandoloc297a4c2021-04-15 11:27:27 -070046 // NOTE localCharts is set to "true" so that we use the locally cloned version of the chart (set to voltha-2.7)
47 volthaDeploy([workflow: "att", extraHelmFlags: extraHelmFlags, localCharts: true])
Matteo Scandolof593a0f2021-04-14 10:16:06 -070048 // start logging
49 sh """
50 rm -rf $WORKSPACE/${name} || true
51 mkdir -p $WORKSPACE/${name}
52 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
53 """
54 // forward ONOS and VOLTHA ports
55 sh """
56 _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 &"
57 _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 &"
58 _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 &"
59 """
60 sh """
61 sshpass -e ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@127.0.0.1 log:set DEBUG org.opencord
62 """
63 }
64 stage('Test - '+ name) {
65 sh """
66 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}"
67 mkdir -p \$ROBOT_LOGS_DIR
68 if [[ ${name} == 'onos-app-upgrade' ]]; then
69 export ONOS_APPS_UNDER_TEST+=''
70 if [ ${aaaVer.trim()} != '' ] && [ ${aaaOarUrl.trim()} != '' ]; then
71 ONOS_APPS_UNDER_TEST+="org.opencord.aaa,${aaaVer.trim()},${aaaOarUrl.trim()}*"
72 fi
73 if [ ${oltVer.trim()} != '' ] && [ ${oltOarUrl.trim()} != '' ]; then
74 ONOS_APPS_UNDER_TEST+="org.opencord.olt,${oltVer.trim()},${oltOarUrl.trim()}*"
75 fi
76 if [ ${dhcpl2relayVer.trim()} != '' ] && [ ${dhcpl2relayOarUrl.trim()} != '' ]; then
77 ONOS_APPS_UNDER_TEST+="org.opencord.dhcpl2relay,${dhcpl2relayVer.trim()},${dhcpl2relayOarUrl.trim()}*"
78 fi
79 if [ ${igmpproxyVer.trim()} != '' ] && [ ${igmpproxyOarUrl.trim()} != '' ]; then
80 ONOS_APPS_UNDER_TEST+="org.opencord.igmpproxy,${igmpproxyVer.trim()},${igmpproxyOarUrl.trim()}*"
81 fi
82 if [ ${sadisVer.trim()} != '' ] && [ ${sadisOarUrl.trim()} != '' ]; then
83 ONOS_APPS_UNDER_TEST+="org.opencord.sadis,${sadisVer.trim()},${sadisOarUrl.trim()}*"
84 fi
85 if [ ${mcastVer.trim()} != '' ] && [ ${mcastOarUrl.trim()} != '' ]; then
86 ONOS_APPS_UNDER_TEST+="org.opencord.mcast,${mcastVer.trim()},${mcastOarUrl.trim()}*"
87 fi
88 if [ ${kafkaVer.trim()} != '' ] && [ ${kafkaOarUrl.trim()} != '' ]; then
89 ONOS_APPS_UNDER_TEST+="org.opencord.kafka,${kafkaVer.trim()},${kafkaOarUrl.trim()}*"
90 fi
91 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:\$ONOS_APPS_UNDER_TEST -e PowerSwitch"
92 export TARGET=onos-app-upgrade-test
93 fi
94 if [[ ${name} == 'voltha-component-upgrade' ]]; then
95 export VOLTHA_COMPS_UNDER_TEST+=''
96 if [ ${adapterOpenOltImage.trim()} != '' ]; then
97 VOLTHA_COMPS_UNDER_TEST+="adapter-open-olt,adapter-open-olt,${adapterOpenOltImage.trim()}*"
98 fi
99 if [ ${adapterOpenOnuImage.trim()} != '' ]; then
100 VOLTHA_COMPS_UNDER_TEST+="adapter-open-onu,adapter-open-onu,${adapterOpenOnuImage.trim()}*"
101 fi
102 if [ ${rwCoreImage.trim()} != '' ]; then
103 VOLTHA_COMPS_UNDER_TEST+="rw-core,voltha,${rwCoreImage.trim()}*"
104 fi
105 if [ ${ofAgentImage.trim()} != '' ]; then
106 VOLTHA_COMPS_UNDER_TEST+="ofagent,ofagent,${ofAgentImage.trim()}*"
107 fi
108 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:\$VOLTHA_COMPS_UNDER_TEST -e PowerSwitch"
109 export TARGET=voltha-comp-upgrade-test
110 fi
111 if [[ ${name} == 'onu-software-upgrade' ]]; then
112 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onu_image_name:${onuImageName.trim()} -v onu_image_url:${onuImageUrl.trim()} -v onu_image_version:${onuImageVersion.trim()} -v onu_image_crc:${onuImageCrc.trim()} -v onu_image_local_dir:${onuImageLocalDir.trim()} -e PowerSwitch"
113 export TARGET=onu-upgrade-test
114 fi
115 export VOLTCONFIG=$HOME/.volt/config-minimal
116 export KUBECONFIG=$HOME/.kube/kind-config-voltha-minimal
117 # Run the specified tests
118 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
119 """
120 // stop logging
121 sh """
122 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
123 if [ -n "\$P_IDS" ]; then
124 echo \$P_IDS
125 for P_ID in \$P_IDS; do
126 kill -9 \$P_ID
127 done
128 fi
129 """
130 // remove port-forwarding
131 sh """
132 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200133 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 -0700134 """
135 // collect pod details
136 get_pods_info("$WORKSPACE/${name}")
137 helmTeardown(['infra', 'voltha'])
138 }
139}
140def get_pods_info(dest) {
141 // collect pod details, this is here in case of failure
142 sh """
143 mkdir -p ${dest} || true
144 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
145 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
146 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
147 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
148 kubectl describe pods -n infra -l app=onos-classic > ${dest}/onos-pods-describe.txt
149 helm ls --all-namespaces > ${dest}/helm-charts.txt
150 """
151 sh '''
152 # copy the ONOS logs directly from the container to avoid the color codes
153 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
154 '''
155}
156pipeline {
157 /* no label, executor is determined by JJB */
158 agent {
159 label "${params.buildNode}"
160 }
161 options {
Hardik Windlass973230d2021-05-17 11:08:59 +0530162 timeout(time: 60, unit: 'MINUTES')
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700163 }
164 environment {
165 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
166 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
167 SSHPASS="karaf"
168 }
169 stages{
170 stage('Download Code') {
171 steps {
172 getVolthaCode([
173 branch: "${branch}",
174 volthaSystemTestsChange: "${volthaSystemTestsChange}",
175 volthaHelmChartsChange: "${volthaHelmChartsChange}",
176 ])
177 }
178 }
179 stage('Cleanup') {
180 steps {
181 // remove port-forwarding
182 sh """
183 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200184 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 -0700185 """
186 helmTeardown(['infra', 'voltha'])
187 }
188 }
189 stage('Install latest voltctl') {
190 steps {
191 sh """
192 mkdir -p $WORKSPACE/bin || true
193 # install voltctl
194 HOSTOS="\$(uname -s | tr "[:upper:]" "[:lower:"])"
195 HOSTARCH="\$(uname -m | tr "[:upper:]" "[:lower:"])"
196 if [ "\$HOSTARCH" == "x86_64" ]; then
197 HOSTARCH="amd64"
198 fi
199 VC_VERSION="\$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')"
200 curl -Lo $WORKSPACE/bin/voltctl https://github.com/opencord/voltctl/releases/download/v\$VC_VERSION/voltctl-\$VC_VERSION-\$HOSTOS-\$HOSTARCH
201 chmod +x $WORKSPACE/bin/voltctl
202 """
203 }
204 }
Hardik Windlass9f5bee12021-05-07 06:47:21 +0000205 stage('Create K8s Cluster') {
206 steps {
207 createKubernetesCluster([nodes: 3])
208 }
209 }
Matteo Scandolof593a0f2021-04-14 10:16:06 -0700210 stage('Run Test') {
211 steps {
212 test_software_upgrade("onos-app-upgrade")
213 test_software_upgrade("voltha-component-upgrade")
214 test_software_upgrade("onu-software-upgrade")
215 }
216 }
217 }
218 post {
219 aborted {
220 get_pods_info("$WORKSPACE/failed")
221 }
222 failure {
223 get_pods_info("$WORKSPACE/failed")
224 }
225 always {
226 sh '''
227 gzip $WORKSPACE/onos-app-upgrade/onos-voltha-combined.log || true
228 gzip $WORKSPACE/voltha-component-upgrade/onos-voltha-combined.log || true
229 gzip $WORKSPACE/onu-software-upgrade/onos-voltha-combined.log || true
230 '''
231 step([$class: 'RobotPublisher',
232 disableArchiveOutput: false,
233 logFileName: 'RobotLogs/*/log*.html',
234 otherFiles: '',
235 outputFileName: 'RobotLogs/*/output*.xml',
236 outputPath: '.',
237 passThreshold: 100,
238 reportFileName: 'RobotLogs/*/report*.html',
239 unstableThreshold: 0]);
240 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
241 }
242 }
243}