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