blob: c24a586e73c1fb6756447ede286001f769cf5f74 [file] [log] [blame]
Joey Armstrong65405412022-11-22 10:43:06 -05001// Copyright 2021-2022 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo42f6e572021-01-25 15:11:34 -08002//
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
Hardik Windlassec9341b2021-06-07 11:58:29 +000015// voltha-2.x e2e tests for openonu-go
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016// uses bbsim to simulate OLT/ONUs
17
Matteo Scandoloa156b572021-02-04 11:52:18 -080018library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
Hardik Windlassec9341b2021-06-07 11:58:29 +000024def clusterName = "kind-ci"
25
Hardik Windlass60fc0da2021-10-14 07:02:40 +000026def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "") {
Hardik Windlassec9341b2021-06-07 11:58:29 +000027 def infraNamespace = "default"
28 def volthaNamespace = "voltha"
Matteo Scandolo9c230bb2021-10-22 12:48:39 -070029 def logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong293e16b2022-11-26 20:16:33 -050030
31 stage('IAM')
32 {
33 script
34 {
35 String iam = [
36 'ci-management',
37 'jjb',
38 'pipeline',
39 'voltha',
40 'master',
41 'bbsim-tests.groovy'
42 ].join('/')
43 println("** ${iam}: ENTER")
44
45 String cmd = "which pkill"
46 def stream = sh(
47 returnStatus:false,
48 returnStdout: true,
49 script: cmd)
50 println(" ** ${cmd}:\n${stream}")
51
52 println("** ${iam}: LEAVE")
53 }
54 }
55
56 stage('Cleanup') {
Hardik Windlassec9341b2021-06-07 11:58:29 +000057 if (teardown) {
58 timeout(15) {
59 script {
60 helmTeardown(["default", infraNamespace, volthaNamespace])
61 }
62 timeout(1) {
63 sh returnStdout: false, script: '''
64 # remove orphaned port-forward from different namespaces
65 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
66 '''
67 }
68 }
69 }
70 }
Hardik Windlasse1660492022-03-14 15:12:46 +000071 stage('Deploy common infrastructure') {
72 sh '''
73 helm repo add onf https://charts.opencord.org
74 helm repo update
75 if [ ${withMonitoring} = true ] ; then
76 helm install nem-monitoring onf/nem-monitoring \
77 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
78 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
79 fi
80 '''
81 }
Hardik Windlassec9341b2021-06-07 11:58:29 +000082 stage('Deploy Voltha') {
83 if (teardown) {
Matteo Scandoloea6348e2021-06-10 18:44:58 +020084 timeout(10) {
Hardik Windlassec9341b2021-06-07 11:58:29 +000085 script {
86
87 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -070088 mkdir -p ${logsDir}
89 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
Hardik Windlassec9341b2021-06-07 11:58:29 +000090 """
91
92 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
93 def localCharts = false
Matteo Scandoloea6348e2021-06-10 18:44:58 +020094 if (volthaHelmChartsChange != "" || gerritProject == "voltha-helm-charts") {
Hardik Windlassec9341b2021-06-07 11:58:29 +000095 localCharts = true
96 }
97
98 // NOTE temporary workaround expose ONOS node ports
Andrea Campanella9e41a602021-09-14 14:45:11 +020099 def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " +
Matteo Scandolo9114c892021-05-20 11:41:55 -0700100 " --set onos-classic.onosSshPort=30115 " +
Hardik Windlassec9341b2021-06-07 11:58:29 +0000101 " --set onos-classic.onosApiPort=30120 " +
102 " --set onos-classic.onosOfPort=31653 " +
103 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800104
Hardik Windlassec9341b2021-06-07 11:58:29 +0000105 if (gerritProject != "") {
106 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
107 }
108
109 volthaDeploy([
110 infraNamespace: infraNamespace,
111 volthaNamespace: volthaNamespace,
112 workflow: workflow.toLowerCase(),
Hardik Windlass2b164342022-02-28 03:50:48 +0000113 withMacLearning: enableMacLearning.toBoolean(),
Hardik Windlassec9341b2021-06-07 11:58:29 +0000114 extraHelmFlags: localHelmFlags,
115 localCharts: localCharts,
116 bbsimReplica: olts.toInteger(),
117 dockerRegistry: registry,
118 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700119 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800120
Hardik Windlassec9341b2021-06-07 11:58:29 +0000121 // stop logging
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700122 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000123 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
124 if [ -n "\$P_IDS" ]; then
125 echo \$P_IDS
126 for P_ID in \$P_IDS; do
127 kill -9 \$P_ID
128 done
129 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700130 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +0000131 gzip -k onos-voltha-startup-combined.log
132 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700133 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000134 }
135 sh """
136 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/voltha-voltha-api 55555:55555; done"&
137 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-etcd" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-etcd 2379:2379; done"&
138 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-kafka" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-kafka 9092:9092; done"&
139 bbsimDmiPortFwd=50075
140 for i in {0..${olts.toInteger() - 1}}; do
141 JENKINS_NODE_COOKIE="dontKillMe" _TAG="bbsim\${i}" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/bbsim\${i} \${bbsimDmiPortFwd}:50075; done"&
142 ((bbsimDmiPortFwd++))
143 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000144 if [ ${withMonitoring} = true ] ; then
145 JENKINS_NODE_COOKIE="dontKillMe" _TAG="nem-monitoring-prometheus-server" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n default svc/nem-monitoring-prometheus-server 31301:80; done"&
146 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000147 ps aux | grep port-forward
148 """
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700149 // setting ONOS log level
Matteo Scandolo9e8ba502021-11-17 13:56:56 -0800150 script {
151 setOnosLogLevels([
152 onosNamespace: infraNamespace,
153 apps: [
154 'org.opencord.dhcpl2relay',
155 'org.opencord.olt',
156 'org.opencord.aaa',
Andrea Campanellac0762392022-03-11 15:01:13 +0100157 'org.opencord.maclearner',
Matteo Scandolo9e8ba502021-11-17 13:56:56 -0800158 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
159 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
160 ],
161 logLevel: logLevel
162 ])
163 }
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700164 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800165 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000166 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
Hardik Windlass72947302021-06-14 10:36:57 +0000167 sh """
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000168 if [ ${withMonitoring} = true ] ; then
169 mkdir -p $WORKSPACE/voltha-pods-mem-consumption-${workflow}
170 cd $WORKSPACE/voltha-system-tests
171 make vst_venv
172 source ./vst_venv/bin/activate || true
173 # Collect initial memory consumption
174 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true
175 fi
Hardik Windlasse1660492022-03-14 15:12:46 +0000176 """
177 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700178 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000179 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700180 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}"
Hardik Windlass72947302021-06-14 10:36:57 +0000181 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800182
Hardik Windlass72947302021-06-14 10:36:57 +0000183 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
184 """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700185 getPodsInfo("${logsDir}")
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000186 sh """
187 set +e
188 # collect logs collected in the Robot Framework StartLogging keyword
189 cd ${logsDir}
190 gzip *-combined.log || true
191 rm *-combined.log || true
192 """
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000193 sh """
194 if [ ${withMonitoring} = true ] ; then
195 cd $WORKSPACE/voltha-system-tests
196 source ./vst_venv/bin/activate || true
197 # Collect memory consumption of voltha pods once all the tests are complete
198 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true
199 fi
200 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800201 }
202}
203
Hardik Windlassec9341b2021-06-07 11:58:29 +0000204def collectArtifacts(exitStatus) {
205 getPodsInfo("$WORKSPACE/${exitStatus}")
206 sh """
207 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
208 """
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000209 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
Hardik Windlassec9341b2021-06-07 11:58:29 +0000210 sh '''
211 sync
212 pkill kail || true
213 which voltctl
214 md5sum $(which voltctl)
215 '''
216 step([$class: 'RobotPublisher',
217 disableArchiveOutput: false,
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700218 logFileName: "**/*/log*.html",
Hardik Windlassec9341b2021-06-07 11:58:29 +0000219 otherFiles: '',
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700220 outputFileName: "**/*/output*.xml",
Hardik Windlassec9341b2021-06-07 11:58:29 +0000221 outputPath: '.',
222 passThreshold: 100,
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700223 reportFileName: "**/*/report*.html",
Andrea Campanellaabc09772021-06-16 12:08:57 +0200224 unstableThreshold: 0,
225 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000226}
227
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800228pipeline {
229
230 /* no label, executor is determined by JJB */
231 agent {
232 label "${params.buildNode}"
233 }
234 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000235 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800236 }
237 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000238 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
239 VOLTCONFIG="$HOME/.volt/config"
240 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000241 DIAGS_PROFILE="VOLTHA_PROFILE"
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700242 SSHPASS="karaf"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800243 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000244 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800245 stage('Download Code') {
246 steps {
247 getVolthaCode([
248 branch: "${branch}",
249 gerritProject: "${gerritProject}",
250 gerritRefspec: "${gerritRefspec}",
251 volthaSystemTestsChange: "${volthaSystemTestsChange}",
252 volthaHelmChartsChange: "${volthaHelmChartsChange}",
253 ])
254 }
255 }
256 stage('Build patch') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000257 // build the patch only if gerritProject is specified
258 when {
259 expression {
260 return !gerritProject.isEmpty()
261 }
262 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800263 steps {
264 // NOTE that the correct patch has already been checked out
265 // during the getVolthaCode step
266 buildVolthaComponent("${gerritProject}")
267 }
268 }
269 stage('Create K8s Cluster') {
270 steps {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000271 script {
272 def clusterExists = sh returnStdout: true, script: """
273 kind get clusters | grep ${clusterName} | wc -l
274 """
275 if (clusterExists.trim() == "0") {
276 createKubernetesCluster([nodes: 3, name: clusterName])
277 }
278 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800279 }
280 }
Hardik Windlassc6ba23e2021-06-08 08:19:52 +0000281 stage('Replace voltctl') {
282 // if the project is voltctl override the downloaded one with the built one
283 when {
284 expression {
285 return gerritProject == "voltctl"
286 }
287 }
288 steps{
289 sh """
290 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
291 chmod +x $WORKSPACE/bin/voltctl
292 """
293 }
294 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800295 stage('Load image in kind nodes') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000296 when {
297 expression {
298 return !gerritProject.isEmpty()
299 }
300 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800301 steps {
302 loadToKind()
303 }
304 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000305 stage('Parse and execute tests') {
306 steps {
307 script {
308 def tests = readYaml text: testTargets
309
310 for(int i = 0;i<tests.size();i++) {
311 def test = tests[i]
312 def target = test["target"]
313 def workflow = test["workflow"]
314 def flags = test["flags"]
315 def teardown = test["teardown"].toBoolean()
Hardik Windlass24e275f2021-10-19 08:19:06 +0000316 def logging = test["logging"].toBoolean()
317 def testLogging = 'False'
318 if (logging) {
319 testLogging = 'True'
320 }
321 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
322 execute_test(target, workflow, testLogging, teardown, flags)
Hardik Windlassec9341b2021-06-07 11:58:29 +0000323 }
324 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800325 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800326 }
327 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800328 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800329 aborted {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000330 collectArtifacts("aborted")
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800331 }
332 failure {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000333 collectArtifacts("failed")
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800334 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800335 always {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000336 collectArtifacts("always")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800337 }
338 }
339}