blob: 4e1895f3cc25cfcc25b655c03c9ec6247437938a [file] [log] [blame]
Hardik Windlassb9d63202022-02-10 04:52:14 +00001// 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
26def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "") {
Joey Armstrong293e16b2022-11-26 20:16:33 -050027 def infraNamespace = "default"
28 def volthaNamespace = "voltha"
29 def logsDir = "$WORKSPACE/${testTarget}"
30
31 stage('IAM')
32 {
33 script
34 {
35 String iam = [
36 'ci-management',
37 'jjb',
38 'pipeline',
39 'voltha',
40 'voltha-2.9',
41 'bbsim-tests.groovy'
42 ].join('/')
43 println("** ${iam}: ENTER")
44 println("** ${iam}: LEAVE")
45 }
46 }
47
48 stage('Cleanup') {
Hardik Windlassb9d63202022-02-10 04:52:14 +000049 if (teardown) {
50 timeout(15) {
51 script {
52 helmTeardown(["default", infraNamespace, volthaNamespace])
53 }
54 timeout(1) {
55 sh returnStdout: false, script: '''
56 # remove orphaned port-forward from different namespaces
57 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
58 '''
59 }
60 }
61 }
62 }
63 stage('Deploy Voltha') {
64 if (teardown) {
65 timeout(10) {
66 script {
67
68 sh """
69 mkdir -p ${logsDir}
70 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
71 """
72
73 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
74 def localCharts = false
Matteo Scandolof2464e12022-03-28 15:37:18 -070075 if (volthaHelmChartsChange != "" || gerritProject == "voltha-helm-charts" || branch != "master") {
Hardik Windlassb9d63202022-02-10 04:52:14 +000076 localCharts = true
77 }
78
79 // NOTE temporary workaround expose ONOS node ports
80 def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " +
81 " --set onos-classic.onosSshPort=30115 " +
82 " --set onos-classic.onosApiPort=30120 " +
83 " --set onos-classic.onosOfPort=31653 " +
84 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
85
86 if (gerritProject != "") {
87 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
88 }
89
90 volthaDeploy([
91 infraNamespace: infraNamespace,
92 volthaNamespace: volthaNamespace,
93 workflow: workflow.toLowerCase(),
94 extraHelmFlags: localHelmFlags,
95 localCharts: localCharts,
96 bbsimReplica: olts.toInteger(),
97 dockerRegistry: registry,
98 ])
99 }
100
101 // stop logging
102 sh """
103 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
104 if [ -n "\$P_IDS" ]; then
105 echo \$P_IDS
106 for P_ID in \$P_IDS; do
107 kill -9 \$P_ID
108 done
109 fi
110 cd ${logsDir}
111 gzip -k onos-voltha-startup-combined.log
112 rm onos-voltha-startup-combined.log
113 """
114 }
115 sh """
116 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"&
117 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"&
118 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"&
119 bbsimDmiPortFwd=50075
120 for i in {0..${olts.toInteger() - 1}}; do
121 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"&
122 ((bbsimDmiPortFwd++))
123 done
124 ps aux | grep port-forward
125 """
126 // setting ONOS log level
127 script {
128 setOnosLogLevels([
129 onosNamespace: infraNamespace,
130 apps: [
131 'org.opencord.dhcpl2relay',
132 'org.opencord.olt',
133 'org.opencord.aaa',
134 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
135 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
136 ],
137 logLevel: logLevel
138 ])
139 }
140 }
141 }
142 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
143 sh """
144 mkdir -p ${logsDir}
145 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
146 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}"
147 export KVSTOREPREFIX=voltha/voltha_voltha
148
149 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
150 """
151 getPodsInfo("${logsDir}")
152 sh """
153 set +e
154 # collect logs collected in the Robot Framework StartLogging keyword
155 cd ${logsDir}
156 gzip *-combined.log || true
157 rm *-combined.log || true
158 """
159 }
160}
161
162def collectArtifacts(exitStatus) {
163 getPodsInfo("$WORKSPACE/${exitStatus}")
164 sh """
165 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
166 """
167 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
168 sh '''
169 sync
170 pkill kail || true
171 which voltctl
172 md5sum $(which voltctl)
173 '''
174 step([$class: 'RobotPublisher',
175 disableArchiveOutput: false,
176 logFileName: "**/*/log*.html",
177 otherFiles: '',
178 outputFileName: "**/*/output*.xml",
179 outputPath: '.',
180 passThreshold: 100,
181 reportFileName: "**/*/report*.html",
182 unstableThreshold: 0,
183 onlyCritical: true]);
184}
185
186pipeline {
187
188 /* no label, executor is determined by JJB */
189 agent {
190 label "${params.buildNode}"
191 }
192 options {
193 timeout(time: "${timeout}", unit: 'MINUTES')
194 }
195 environment {
196 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
197 VOLTCONFIG="$HOME/.volt/config"
198 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
199 DIAGS_PROFILE="VOLTHA_PROFILE"
200 SSHPASS="karaf"
201 }
202 stages {
203 stage('Download Code') {
204 steps {
205 getVolthaCode([
206 branch: "${branch}",
207 gerritProject: "${gerritProject}",
208 gerritRefspec: "${gerritRefspec}",
209 volthaSystemTestsChange: "${volthaSystemTestsChange}",
210 volthaHelmChartsChange: "${volthaHelmChartsChange}",
211 ])
212 }
213 }
214 stage('Build patch') {
215 // build the patch only if gerritProject is specified
216 when {
217 expression {
218 return !gerritProject.isEmpty()
219 }
220 }
221 steps {
222 // NOTE that the correct patch has already been checked out
223 // during the getVolthaCode step
224 buildVolthaComponent("${gerritProject}")
225 }
226 }
227 stage('Create K8s Cluster') {
228 steps {
229 script {
230 def clusterExists = sh returnStdout: true, script: """
231 kind get clusters | grep ${clusterName} | wc -l
232 """
233 if (clusterExists.trim() == "0") {
234 createKubernetesCluster([nodes: 3, name: clusterName])
235 }
236 }
237 }
238 }
239 stage('Replace voltctl') {
240 // if the project is voltctl override the downloaded one with the built one
241 when {
242 expression {
243 return gerritProject == "voltctl"
244 }
245 }
246 steps{
247 sh """
248 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
249 chmod +x $WORKSPACE/bin/voltctl
250 """
251 }
252 }
253 stage('Load image in kind nodes') {
254 when {
255 expression {
256 return !gerritProject.isEmpty()
257 }
258 }
259 steps {
260 loadToKind()
261 }
262 }
263 stage('Parse and execute tests') {
264 steps {
265 script {
266 def tests = readYaml text: testTargets
267
268 for(int i = 0;i<tests.size();i++) {
269 def test = tests[i]
270 def target = test["target"]
271 def workflow = test["workflow"]
272 def flags = test["flags"]
273 def teardown = test["teardown"].toBoolean()
274 def logging = test["logging"].toBoolean()
275 def testLogging = 'False'
276 if (logging) {
277 testLogging = 'True'
278 }
279 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
280 execute_test(target, workflow, testLogging, teardown, flags)
281 }
282 }
283 }
284 }
285 }
286 post {
287 aborted {
288 collectArtifacts("aborted")
289 }
290 failure {
291 collectArtifacts("failed")
292 }
293 always {
294 collectArtifacts("always")
295 }
296 }
297}