blob: 2dad953a3621ca89ae02432c88b9f5cdc5224ef5 [file] [log] [blame]
Joey Armstrongbeef4cd2023-01-18 09:59:58 -05001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
Hardik Windlass6d9a82e2021-07-08 16:23:21 +00002//
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
Hardik Windlass60fc0da2021-10-14 07:02:40 +000026def 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.8',
41 'bbsim-tests.groovy'
42 ].join('/')
43 println("** ${iam}: ENTER")
44 println("** ${iam}: LEAVE")
45 }
46 }
47
48 stage('Cleanup') {
Hardik Windlass6d9a82e2021-07-08 16:23:21 +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 """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -070069 mkdir -p ${logsDir}
70 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000071 """
72
73 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
74 def localCharts = false
75 if (gerritProject == "voltha-helm-charts" || branch != "master") {
76 localCharts = true
77 }
78
79 // NOTE temporary workaround expose ONOS node ports
Andrea Campanella9e41a602021-09-14 14:45:11 +020080 def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " +
Hardik Windlass6d9a82e2021-07-08 16:23:21 +000081 " --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
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700110 cd ${logsDir}
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000111 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 }
127 }
128 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000129 sh """
Hardik Windlass476c2f02021-11-01 06:49:41 +0000130 mkdir -p ${logsDir}
131 export ROBOT_MISC_ARGS="-d ${logsDir} "
132 ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:${logsDir} -v logging:${testLogging}"
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000133 export KVSTOREPREFIX=voltha/voltha_voltha
134
135 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
136 """
Hardik Windlass476c2f02021-11-01 06:49:41 +0000137 getPodsInfo("${logsDir}")
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000138 sh """
139 set +e
140 # collect logs collected in the Robot Framework StartLogging keyword
141 cd ${logsDir}
142 gzip *-combined.log || true
143 rm *-combined.log || true
144 """
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000145 }
146}
147
148def collectArtifacts(exitStatus) {
149 getPodsInfo("$WORKSPACE/${exitStatus}")
150 sh """
151 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
152 """
153 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
154 sh '''
155 sync
156 pkill kail || true
157 which voltctl
158 md5sum $(which voltctl)
159 '''
160 step([$class: 'RobotPublisher',
161 disableArchiveOutput: false,
Hardik Windlass476c2f02021-11-01 06:49:41 +0000162 logFileName: "**/*/log*.html",
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000163 otherFiles: '',
Hardik Windlass476c2f02021-11-01 06:49:41 +0000164 outputFileName: "**/*/output*.xml",
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000165 outputPath: '.',
166 passThreshold: 100,
Hardik Windlass476c2f02021-11-01 06:49:41 +0000167 reportFileName: "**/*/report*.html",
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000168 unstableThreshold: 0,
169 onlyCritical: true]);
170}
171
172pipeline {
173
174 /* no label, executor is determined by JJB */
175 agent {
176 label "${params.buildNode}"
177 }
178 options {
179 timeout(time: "${timeout}", unit: 'MINUTES')
180 }
181 environment {
182 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
183 VOLTCONFIG="$HOME/.volt/config"
184 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
185 ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}"
186 DIAGS_PROFILE="VOLTHA_PROFILE"
187 }
188 stages {
189 stage('Download Code') {
190 steps {
191 getVolthaCode([
192 branch: "${branch}",
193 gerritProject: "${gerritProject}",
194 gerritRefspec: "${gerritRefspec}",
195 volthaSystemTestsChange: "${volthaSystemTestsChange}",
196 volthaHelmChartsChange: "${volthaHelmChartsChange}",
197 ])
198 }
199 }
200 stage('Build patch') {
201 // build the patch only if gerritProject is specified
202 when {
203 expression {
204 return !gerritProject.isEmpty()
205 }
206 }
207 steps {
208 // NOTE that the correct patch has already been checked out
209 // during the getVolthaCode step
210 buildVolthaComponent("${gerritProject}")
211 }
212 }
213 stage('Create K8s Cluster') {
214 steps {
215 script {
216 def clusterExists = sh returnStdout: true, script: """
217 kind get clusters | grep ${clusterName} | wc -l
218 """
219 if (clusterExists.trim() == "0") {
Hardik Windlass6f854a12021-07-12 13:20:21 +0000220 createKubernetesCluster([branch: "${branch}", nodes: 3, name: clusterName])
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000221 }
222 }
223 }
224 }
225 stage('Replace voltctl') {
226 // if the project is voltctl override the downloaded one with the built one
227 when {
228 expression {
229 return gerritProject == "voltctl"
230 }
231 }
232 steps{
233 sh """
234 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
235 chmod +x $WORKSPACE/bin/voltctl
236 """
237 }
238 }
239 stage('Load image in kind nodes') {
240 when {
241 expression {
242 return !gerritProject.isEmpty()
243 }
244 }
245 steps {
246 loadToKind()
247 }
248 }
249 stage('Parse and execute tests') {
250 steps {
251 script {
252 def tests = readYaml text: testTargets
253
254 for(int i = 0;i<tests.size();i++) {
255 def test = tests[i]
256 def target = test["target"]
257 def workflow = test["workflow"]
258 def flags = test["flags"]
259 def teardown = test["teardown"].toBoolean()
Hardik Windlass24e275f2021-10-19 08:19:06 +0000260 def logging = test["logging"].toBoolean()
261 def testLogging = 'False'
262 if (logging) {
263 testLogging = 'True'
264 }
265 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
266 execute_test(target, workflow, testLogging, teardown, flags)
Hardik Windlass6d9a82e2021-07-08 16:23:21 +0000267 }
268 }
269 }
270 }
271 }
272 post {
273 aborted {
274 collectArtifacts("aborted")
275 }
276 failure {
277 collectArtifacts("failed")
278 }
279 always {
280 collectArtifacts("always")
281 }
282 }
283}