blob: 98b0b23a51b1f4aa64715c2fdb1938cc2351671e [file] [log] [blame]
Joey Armstrong65405412022-11-22 10:43:06 -05001// Copyright 2021-2022 Open Networking Foundation (ONF) and the ONF Contributors//
Hardik Windlass19605da2022-06-30 22:05:57 +05302// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// voltha-2.x e2e tests for openonu-go
15// uses bbsim to simulate OLT/ONUs
16
17library identifier: 'cord-jenkins-libraries@master',
18 retriever: modernSCM([
19 $class: 'GitSCMSource',
20 remote: 'https://gerrit.opencord.org/ci-management.git'
21])
22
23def clusterName = "kind-ci"
24
25def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "") {
26 def infraNamespace = "default"
27 def volthaNamespace = "voltha"
28 def logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong65405412022-11-22 10:43:06 -050029
30 stage('IAM')
31 {
32 script
33 {
34 String iam = [
35 'ci-management',
36 'jjb',
37 'pipeline',
38 'voltha',
39 'voltha-2.10',
40 'bbsim-tests.groovy'
41 ].join('/')
42 println("** ${iam}: ENTER")
Joey Armstrong65405412022-11-22 10:43:06 -050043 println("** ${iam}: LEAVE")
44 }
45 }
46
47 stage('Cleanup') {
Hardik Windlass19605da2022-06-30 22:05:57 +053048 if (teardown) {
49 timeout(15) {
50 script {
51 helmTeardown(["default", infraNamespace, volthaNamespace])
52 }
53 timeout(1) {
54 sh returnStdout: false, script: '''
55 # remove orphaned port-forward from different namespaces
56 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
57 '''
58 }
59 }
60 }
61 }
62 stage('Deploy common infrastructure') {
63 sh '''
64 helm repo add onf https://charts.opencord.org
65 helm repo update
66 if [ ${withMonitoring} = true ] ; then
67 helm install nem-monitoring onf/nem-monitoring \
68 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
69 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
70 fi
71 '''
72 }
73 stage('Deploy Voltha') {
74 if (teardown) {
75 timeout(10) {
76 script {
77
78 sh """
79 mkdir -p ${logsDir}
80 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
81 """
82
83 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
84 def localCharts = false
85 if (volthaHelmChartsChange != "" || gerritProject == "voltha-helm-charts") {
86 localCharts = true
87 }
88
89 // NOTE temporary workaround expose ONOS node ports
90 def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " +
91 " --set onos-classic.onosSshPort=30115 " +
92 " --set onos-classic.onosApiPort=30120 " +
93 " --set onos-classic.onosOfPort=31653 " +
94 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
95
96 if (gerritProject != "") {
97 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
98 }
99
100 volthaDeploy([
101 infraNamespace: infraNamespace,
102 volthaNamespace: volthaNamespace,
103 workflow: workflow.toLowerCase(),
104 withMacLearning: enableMacLearning.toBoolean(),
105 extraHelmFlags: localHelmFlags,
106 localCharts: localCharts,
107 bbsimReplica: olts.toInteger(),
108 dockerRegistry: registry,
109 ])
110 }
111
112 // stop logging
113 sh """
114 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
115 if [ -n "\$P_IDS" ]; then
116 echo \$P_IDS
117 for P_ID in \$P_IDS; do
118 kill -9 \$P_ID
119 done
120 fi
121 cd ${logsDir}
122 gzip -k onos-voltha-startup-combined.log
123 rm onos-voltha-startup-combined.log
124 """
125 }
126 sh """
127 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"&
128 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"&
129 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"&
130 bbsimDmiPortFwd=50075
131 for i in {0..${olts.toInteger() - 1}}; do
132 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"&
133 ((bbsimDmiPortFwd++))
134 done
135 if [ ${withMonitoring} = true ] ; then
136 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"&
137 fi
138 ps aux | grep port-forward
139 """
140 // setting ONOS log level
141 script {
142 setOnosLogLevels([
143 onosNamespace: infraNamespace,
144 apps: [
145 'org.opencord.dhcpl2relay',
146 'org.opencord.olt',
147 'org.opencord.aaa',
148 'org.opencord.maclearner',
149 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
150 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
151 ],
152 logLevel: logLevel
153 ])
154 }
155 }
156 }
157 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
158 sh """
159 if [ ${withMonitoring} = true ] ; then
160 mkdir -p $WORKSPACE/voltha-pods-mem-consumption-${workflow}
161 cd $WORKSPACE/voltha-system-tests
162 make vst_venv
163 source ./vst_venv/bin/activate || true
164 # Collect initial memory consumption
165 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true
166 fi
167 """
168 sh """
169 mkdir -p ${logsDir}
170 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
171 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}"
172 export KVSTOREPREFIX=voltha/voltha_voltha
173
174 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
175 """
176 getPodsInfo("${logsDir}")
177 sh """
178 set +e
179 # collect logs collected in the Robot Framework StartLogging keyword
180 cd ${logsDir}
181 gzip *-combined.log || true
182 rm *-combined.log || true
183 """
184 sh """
185 if [ ${withMonitoring} = true ] ; then
186 cd $WORKSPACE/voltha-system-tests
187 source ./vst_venv/bin/activate || true
188 # Collect memory consumption of voltha pods once all the tests are complete
189 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true
190 fi
191 """
192 }
193}
194
195def collectArtifacts(exitStatus) {
196 getPodsInfo("$WORKSPACE/${exitStatus}")
197 sh """
198 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
199 """
200 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
201 sh '''
202 sync
203 pkill kail || true
204 which voltctl
205 md5sum $(which voltctl)
206 '''
207 step([$class: 'RobotPublisher',
208 disableArchiveOutput: false,
209 logFileName: "**/*/log*.html",
210 otherFiles: '',
211 outputFileName: "**/*/output*.xml",
212 outputPath: '.',
213 passThreshold: 100,
214 reportFileName: "**/*/report*.html",
215 unstableThreshold: 0,
216 onlyCritical: true]);
217}
218
219pipeline {
220
221 /* no label, executor is determined by JJB */
222 agent {
223 label "${params.buildNode}"
224 }
225 options {
226 timeout(time: "${timeout}", unit: 'MINUTES')
227 }
228 environment {
229 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
230 VOLTCONFIG="$HOME/.volt/config"
231 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
232 DIAGS_PROFILE="VOLTHA_PROFILE"
233 SSHPASS="karaf"
234 }
235 stages {
236 stage('Download Code') {
237 steps {
238 getVolthaCode([
239 branch: "${branch}",
240 gerritProject: "${gerritProject}",
241 gerritRefspec: "${gerritRefspec}",
242 volthaSystemTestsChange: "${volthaSystemTestsChange}",
243 volthaHelmChartsChange: "${volthaHelmChartsChange}",
244 ])
245 }
246 }
247 stage('Build patch') {
248 // build the patch only if gerritProject is specified
249 when {
250 expression {
251 return !gerritProject.isEmpty()
252 }
253 }
254 steps {
255 // NOTE that the correct patch has already been checked out
256 // during the getVolthaCode step
257 buildVolthaComponent("${gerritProject}")
258 }
259 }
260 stage('Create K8s Cluster') {
261 steps {
262 script {
263 def clusterExists = sh returnStdout: true, script: """
264 kind get clusters | grep ${clusterName} | wc -l
265 """
266 if (clusterExists.trim() == "0") {
267 createKubernetesCluster([nodes: 3, name: clusterName])
268 }
269 }
270 }
271 }
272 stage('Replace voltctl') {
273 // if the project is voltctl override the downloaded one with the built one
274 when {
275 expression {
276 return gerritProject == "voltctl"
277 }
278 }
279 steps{
280 sh """
281 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
282 chmod +x $WORKSPACE/bin/voltctl
283 """
284 }
285 }
286 stage('Load image in kind nodes') {
287 when {
288 expression {
289 return !gerritProject.isEmpty()
290 }
291 }
292 steps {
293 loadToKind()
294 }
295 }
296 stage('Parse and execute tests') {
297 steps {
298 script {
299 def tests = readYaml text: testTargets
300
301 for(int i = 0;i<tests.size();i++) {
302 def test = tests[i]
303 def target = test["target"]
304 def workflow = test["workflow"]
305 def flags = test["flags"]
306 def teardown = test["teardown"].toBoolean()
307 def logging = test["logging"].toBoolean()
308 def testLogging = 'False'
309 if (logging) {
310 testLogging = 'True'
311 }
312 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
313 execute_test(target, workflow, testLogging, teardown, flags)
314 }
315 }
316 }
317 }
318 }
319 post {
320 aborted {
321 collectArtifacts("aborted")
322 }
323 failure {
324 collectArtifacts("failed")
325 }
326 always {
327 collectArtifacts("always")
328 }
329 }
330}
Joey Armstrong65405412022-11-22 10:43:06 -0500331
332// EOF