blob: 527bf65ebbf21daed2329770fd6b7dc9325776e8 [file] [log] [blame]
Hardik Windlassec9341b2021-06-07 11:58:29 +00001// Copyright 2021-present Open Networking Foundation
Matteo Scandolo42f6e572021-01-25 15:11:34 -08002//
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
Hardik Windlassec9341b2021-06-07 11:58:29 +000015// voltha-2.x e2e tests for openonu-go
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016// uses bbsim to simulate OLT/ONUs
17
Matteo Scandoloa156b572021-02-04 11:52:18 -080018library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
Hardik Windlassec9341b2021-06-07 11:58:29 +000024def clusterName = "kind-ci"
25
Hardik Windlass60fc0da2021-10-14 07:02:40 +000026def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "") {
Hardik Windlassec9341b2021-06-07 11:58:29 +000027 def infraNamespace = "default"
28 def volthaNamespace = "voltha"
Matteo Scandolo9c230bb2021-10-22 12:48:39 -070029 def logsDir = "$WORKSPACE/${testTarget}"
Hardik Windlassec9341b2021-06-07 11:58:29 +000030 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) {
Matteo Scandoloea6348e2021-06-10 18:44:58 +020047 timeout(10) {
Hardik Windlassec9341b2021-06-07 11:58:29 +000048 script {
49
50 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -070051 mkdir -p ${logsDir}
52 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
Hardik Windlassec9341b2021-06-07 11:58:29 +000053 """
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 Scandoloea6348e2021-06-10 18:44:58 +020057 if (volthaHelmChartsChange != "" || gerritProject == "voltha-helm-charts") {
Hardik Windlassec9341b2021-06-07 11:58:29 +000058 localCharts = true
59 }
60
61 // NOTE temporary workaround expose ONOS node ports
Andrea Campanella9e41a602021-09-14 14:45:11 +020062 def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " +
Matteo Scandolo9114c892021-05-20 11:41:55 -070063 " --set onos-classic.onosSshPort=30115 " +
Hardik Windlassec9341b2021-06-07 11:58:29 +000064 " --set onos-classic.onosApiPort=30120 " +
65 " --set onos-classic.onosOfPort=31653 " +
66 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
Matteo Scandolo42f6e572021-01-25 15:11:34 -080067
Hardik Windlassec9341b2021-06-07 11:58:29 +000068 if (gerritProject != "") {
69 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
70 }
71
72 volthaDeploy([
73 infraNamespace: infraNamespace,
74 volthaNamespace: volthaNamespace,
75 workflow: workflow.toLowerCase(),
Hardik Windlass2b164342022-02-28 03:50:48 +000076 withMacLearning: enableMacLearning.toBoolean(),
Hardik Windlassec9341b2021-06-07 11:58:29 +000077 extraHelmFlags: localHelmFlags,
78 localCharts: localCharts,
79 bbsimReplica: olts.toInteger(),
80 dockerRegistry: registry,
81 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -070082 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080083
Hardik Windlassec9341b2021-06-07 11:58:29 +000084 // stop logging
Matteo Scandolod17de3a2021-04-09 15:47:52 -070085 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +000086 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
87 if [ -n "\$P_IDS" ]; then
88 echo \$P_IDS
89 for P_ID in \$P_IDS; do
90 kill -9 \$P_ID
91 done
92 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -070093 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +000094 gzip -k onos-voltha-startup-combined.log
95 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -070096 """
Hardik Windlassec9341b2021-06-07 11:58:29 +000097 }
98 sh """
99 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"&
100 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"&
101 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"&
102 bbsimDmiPortFwd=50075
103 for i in {0..${olts.toInteger() - 1}}; do
104 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"&
105 ((bbsimDmiPortFwd++))
106 done
107 ps aux | grep port-forward
108 """
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700109 // setting ONOS log level
Matteo Scandolo9e8ba502021-11-17 13:56:56 -0800110 script {
111 setOnosLogLevels([
112 onosNamespace: infraNamespace,
113 apps: [
114 'org.opencord.dhcpl2relay',
115 'org.opencord.olt',
116 'org.opencord.aaa',
Andrea Campanellac0762392022-03-11 15:01:13 +0100117 'org.opencord.maclearner',
Matteo Scandolo9e8ba502021-11-17 13:56:56 -0800118 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
119 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
120 ],
121 logLevel: logLevel
122 ])
123 }
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700124 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800125 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000126 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
Hardik Windlass72947302021-06-14 10:36:57 +0000127 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700128 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000129 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700130 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}"
Hardik Windlass72947302021-06-14 10:36:57 +0000131 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800132
Hardik Windlass72947302021-06-14 10:36:57 +0000133 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
134 """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700135 getPodsInfo("${logsDir}")
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000136 sh """
137 set +e
138 # collect logs collected in the Robot Framework StartLogging keyword
139 cd ${logsDir}
140 gzip *-combined.log || true
141 rm *-combined.log || true
142 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800143 }
144}
145
Hardik Windlassec9341b2021-06-07 11:58:29 +0000146def collectArtifacts(exitStatus) {
147 getPodsInfo("$WORKSPACE/${exitStatus}")
148 sh """
149 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
150 """
151 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
152 sh '''
153 sync
154 pkill kail || true
155 which voltctl
156 md5sum $(which voltctl)
157 '''
158 step([$class: 'RobotPublisher',
159 disableArchiveOutput: false,
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700160 logFileName: "**/*/log*.html",
Hardik Windlassec9341b2021-06-07 11:58:29 +0000161 otherFiles: '',
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700162 outputFileName: "**/*/output*.xml",
Hardik Windlassec9341b2021-06-07 11:58:29 +0000163 outputPath: '.',
164 passThreshold: 100,
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700165 reportFileName: "**/*/report*.html",
Andrea Campanellaabc09772021-06-16 12:08:57 +0200166 unstableThreshold: 0,
167 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000168}
169
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800170pipeline {
171
172 /* no label, executor is determined by JJB */
173 agent {
174 label "${params.buildNode}"
175 }
176 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000177 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800178 }
179 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000180 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
181 VOLTCONFIG="$HOME/.volt/config"
182 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000183 DIAGS_PROFILE="VOLTHA_PROFILE"
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700184 SSHPASS="karaf"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800185 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000186 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800187 stage('Download Code') {
188 steps {
189 getVolthaCode([
190 branch: "${branch}",
191 gerritProject: "${gerritProject}",
192 gerritRefspec: "${gerritRefspec}",
193 volthaSystemTestsChange: "${volthaSystemTestsChange}",
194 volthaHelmChartsChange: "${volthaHelmChartsChange}",
195 ])
196 }
197 }
198 stage('Build patch') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000199 // build the patch only if gerritProject is specified
200 when {
201 expression {
202 return !gerritProject.isEmpty()
203 }
204 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800205 steps {
206 // NOTE that the correct patch has already been checked out
207 // during the getVolthaCode step
208 buildVolthaComponent("${gerritProject}")
209 }
210 }
211 stage('Create K8s Cluster') {
212 steps {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000213 script {
214 def clusterExists = sh returnStdout: true, script: """
215 kind get clusters | grep ${clusterName} | wc -l
216 """
217 if (clusterExists.trim() == "0") {
218 createKubernetesCluster([nodes: 3, name: clusterName])
219 }
220 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800221 }
222 }
Hardik Windlassc6ba23e2021-06-08 08:19:52 +0000223 stage('Replace voltctl') {
224 // if the project is voltctl override the downloaded one with the built one
225 when {
226 expression {
227 return gerritProject == "voltctl"
228 }
229 }
230 steps{
231 sh """
232 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
233 chmod +x $WORKSPACE/bin/voltctl
234 """
235 }
236 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800237 stage('Load image in kind nodes') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000238 when {
239 expression {
240 return !gerritProject.isEmpty()
241 }
242 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800243 steps {
244 loadToKind()
245 }
246 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000247 stage('Parse and execute tests') {
248 steps {
249 script {
250 def tests = readYaml text: testTargets
251
252 for(int i = 0;i<tests.size();i++) {
253 def test = tests[i]
254 def target = test["target"]
255 def workflow = test["workflow"]
256 def flags = test["flags"]
257 def teardown = test["teardown"].toBoolean()
Hardik Windlass24e275f2021-10-19 08:19:06 +0000258 def logging = test["logging"].toBoolean()
259 def testLogging = 'False'
260 if (logging) {
261 testLogging = 'True'
262 }
263 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
264 execute_test(target, workflow, testLogging, teardown, flags)
Hardik Windlassec9341b2021-06-07 11:58:29 +0000265 }
266 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800267 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800268 }
269 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800270 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800271 aborted {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000272 collectArtifacts("aborted")
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800273 }
274 failure {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000275 collectArtifacts("failed")
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800276 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800277 always {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000278 collectArtifacts("always")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800279 }
280 }
281}