blob: 5d5085a7393bc9271b2832265e9000bd466edcbc [file] [log] [blame]
Matteo Scandolo075740f2021-04-22 14:52:29 -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
15// voltha-2.x e2e tests for openonu-go
16// uses bbsim to simulate OLT/ONUs
17
18library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
24def clusterName = "kind-ci"
25
Matteo Scandoloa57b0972021-05-03 14:04:58 -070026def execute_test(testTarget, workflow, teardown, testSpecificHelmFlags = "") {
Matteo Scandolo075740f2021-04-22 14:52:29 -070027 def infraNamespace = "default"
28 def volthaNamespace = "voltha"
29 def robotLogsDir = "RobotLogs"
30 stage('Cleanup') {
Matteo Scandoloa57b0972021-05-03 14:04:58 -070031 if (teardown) {
32 timeout(15) {
33 script {
34 helmTeardown(["default", infraNamespace, volthaNamespace])
35 }
36 timeout(1) {
37 sh returnStdout: false, script: '''
38 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +020039 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
Matteo Scandoloa57b0972021-05-03 14:04:58 -070040 '''
41 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070042 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070043 }
44 }
45 stage('Deploy Voltha') {
Matteo Scandoloa57b0972021-05-03 14:04:58 -070046 if (teardown) {
47 timeout(20) {
48 script {
Matteo Scandolo075740f2021-04-22 14:52:29 -070049
Matteo Scandolo0d04af82021-05-06 08:36:34 -070050 sh """
51 mkdir -p $WORKSPACE/${testTarget}-components
52 _TAG=kail-startup kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-startup-combined.log &
53 """
54
Matteo Scandoloa57b0972021-05-03 14:04:58 -070055 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
56 def localCharts = false
57 if (volthaHelmChartsChange != "") {
58 localCharts = true
59 }
60
61 // NOTE temporary workaround expose ONOS node ports
Hardik Windlass696002d2021-05-07 11:38:28 +000062 def localHelmFlags = extraHelmFlags + " --set global.log_level=${logLevel.toUpperCase()} " +
63 " --set onos-classic.onosSshPort=30115 " +
Matteo Scandoloa57b0972021-05-03 14:04:58 -070064 " --set onos-classic.onosApiPort=30120 " +
65 " --set onos-classic.onosOfPort=31653 " +
66 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
67 volthaDeploy([
68 infraNamespace: infraNamespace,
69 volthaNamespace: volthaNamespace,
70 workflow: workflow.toLowerCase(),
71 extraHelmFlags: localHelmFlags,
72 localCharts: localCharts,
73 bbsimReplica: olts.toInteger(),
74 dockerRegistry: registry,
75 ])
Matteo Scandolo075740f2021-04-22 14:52:29 -070076 }
Matteo Scandolo0d04af82021-05-06 08:36:34 -070077
78 // stop logging
79 sh """
80 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
81 if [ -n "\$P_IDS" ]; then
82 echo \$P_IDS
83 for P_ID in \$P_IDS; do
84 kill -9 \$P_ID
85 done
86 fi
87 """
Matteo Scandolo075740f2021-04-22 14:52:29 -070088 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070089 sh """
Matteo Scandoloa57b0972021-05-03 14:04:58 -070090 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"&
91 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"&
92 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"&
Matteo Scandolo075740f2021-04-22 14:52:29 -070093 ps aux | grep port-forward
94 """
Matteo Scandolo075740f2021-04-22 14:52:29 -070095 }
96 }
97 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
Matteo Scandolo0d04af82021-05-06 08:36:34 -070098 // start logging
99 sh """
100 mkdir -p $WORKSPACE/${testTarget}-components
101 _TAG=kail-${workflow} kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-combined.log &
102 """
Matteo Scandolo075740f2021-04-22 14:52:29 -0700103 sh """
Matteo Scandoloee626e02021-05-05 08:13:16 -0700104 mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot
105 export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot "
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700106 ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v INFRA_NAMESPACE:${infraNamespace}"
Matteo Scandolo075740f2021-04-22 14:52:29 -0700107 export KVSTOREPREFIX=voltha/voltha_voltha
108
109 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
110 """
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700111 // stop logging
112 sh """
113 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')"
114 if [ -n "\$P_IDS" ]; then
115 echo \$P_IDS
116 for P_ID in \$P_IDS; do
117 kill -9 \$P_ID
118 done
119 fi
120 """
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700121 getPodsInfo("$WORKSPACE/${testTarget}-components")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700122 }
123}
124
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700125def collectArtifacts(exitStatus) {
126 getPodsInfo("$WORKSPACE/${exitStatus}")
127 sh """
Matteo Scandolo0da60532021-05-06 08:59:42 -0700128 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700129 """
130 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
131 sh '''
132 sync
133 pkill kail || true
134 which voltctl
135 md5sum $(which voltctl)
136 '''
137 step([$class: 'RobotPublisher',
138 disableArchiveOutput: false,
139 logFileName: "RobotLogs/*/log*.html",
140 otherFiles: '',
141 outputFileName: "RobotLogs/*/output*.xml",
142 outputPath: '.',
143 passThreshold: 100,
144 reportFileName: "RobotLogs/*/report*.html",
145 unstableThreshold: 0]);
146}
147
Matteo Scandolo075740f2021-04-22 14:52:29 -0700148pipeline {
149
150 /* no label, executor is determined by JJB */
151 agent {
152 label "${params.buildNode}"
153 }
154 options {
155 timeout(time: 130, unit: 'MINUTES')
156 }
157 environment {
158 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
159 VOLTCONFIG="$HOME/.volt/config"
160 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
161 ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}"
162 DIAGS_PROFILE="VOLTHA_PROFILE"
163 }
164 stages {
165 stage('Download Code') {
166 steps {
167 getVolthaCode([
168 branch: "${branch}",
169 gerritProject: "${gerritProject}",
170 gerritRefspec: "${gerritRefspec}",
171 volthaSystemTestsChange: "${volthaSystemTestsChange}",
172 volthaHelmChartsChange: "${volthaHelmChartsChange}",
173 ])
174 }
175 }
176 stage('Create K8s Cluster') {
177 steps {
178 script {
179 def clusterExists = sh returnStdout: true, script: """
180 kind get clusters | grep ${clusterName} | wc -l
181 """
182 if (clusterExists.trim() == "0") {
183 createKubernetesCluster([nodes: 3, name: clusterName])
184 }
185 }
186 }
187 }
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700188 stage('Parse and execute tests') {
189 steps {
190 script {
191 def tests = readYaml text: testTargets
Matteo Scandolo075740f2021-04-22 14:52:29 -0700192
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700193 for(int i = 0;i<tests.size();i++) {
194 def test = tests[i]
195 def target = test["target"]
196 def workflow = test["workflow"]
197 def flags = test["flags"]
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700198 def teardown = test["teardown"].toBoolean()
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700199 println "Executing test ${target} on workflow ${workflow} with extra flags ${flags}"
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700200 execute_test(target, workflow, teardown, flags)
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700201 }
202 }
Matteo Scandolo075740f2021-04-22 14:52:29 -0700203 }
Matteo Scandolo075740f2021-04-22 14:52:29 -0700204 }
205 }
206 post {
207 aborted {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700208 collectArtifacts("aborted")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700209 }
210 failure {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700211 collectArtifacts("failed")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700212 }
213 always {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700214 collectArtifacts("always")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700215 }
216 }
217}