blob: 2423d23c4ec8205ea13bbc7f2d8ab9035fcbf28f [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"
29 def robotLogsDir = "RobotLogs"
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) {
Matteo Scandoloea6348e2021-06-10 18:44:58 +020047 timeout(10) {
Hardik Windlassec9341b2021-06-07 11:58:29 +000048 script {
49
50 sh """
51 mkdir -p $WORKSPACE/${testTarget}-components
Matteo Scandolof2460e8ff2021-06-21 17:53:20 +020052 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > $WORKSPACE/${testTarget}-components/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(),
76 extraHelmFlags: localHelmFlags,
77 localCharts: localCharts,
78 bbsimReplica: olts.toInteger(),
79 dockerRegistry: registry,
80 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -070081 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080082
Hardik Windlassec9341b2021-06-07 11:58:29 +000083 // stop logging
Matteo Scandolod17de3a2021-04-09 15:47:52 -070084 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +000085 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 $WORKSPACE/${testTarget}-components/
93 gzip -k onos-voltha-startup-combined.log
94 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -070095 """
Hardik Windlassec9341b2021-06-07 11:58:29 +000096 }
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 """
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700108 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800109 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000110 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
Hardik Windlass72947302021-06-14 10:36:57 +0000111 sh """
112 mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot
113 export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot "
Hardik Windlass60fc0da2021-10-14 07:02:40 +0000114 ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:$WORKSPACE/${robotLogsDir}/${testTarget}-robot -v logging:${testLogging}"
Hardik Windlass72947302021-06-14 10:36:57 +0000115 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800116
Hardik Windlass72947302021-06-14 10:36:57 +0000117 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
118 """
Hardik Windlass72947302021-06-14 10:36:57 +0000119 getPodsInfo("$WORKSPACE/${testTarget}-components")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800120 }
121}
122
Hardik Windlassec9341b2021-06-07 11:58:29 +0000123def collectArtifacts(exitStatus) {
124 getPodsInfo("$WORKSPACE/${exitStatus}")
125 sh """
126 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
127 """
128 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
129 sh '''
130 sync
131 pkill kail || true
132 which voltctl
133 md5sum $(which voltctl)
134 '''
135 step([$class: 'RobotPublisher',
136 disableArchiveOutput: false,
137 logFileName: "RobotLogs/*/log*.html",
138 otherFiles: '',
139 outputFileName: "RobotLogs/*/output*.xml",
140 outputPath: '.',
141 passThreshold: 100,
142 reportFileName: "RobotLogs/*/report*.html",
Andrea Campanellaabc09772021-06-16 12:08:57 +0200143 unstableThreshold: 0,
144 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000145}
146
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800147pipeline {
148
149 /* no label, executor is determined by JJB */
150 agent {
151 label "${params.buildNode}"
152 }
153 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000154 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800155 }
156 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000157 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
158 VOLTCONFIG="$HOME/.volt/config"
159 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
160 ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}"
161 DIAGS_PROFILE="VOLTHA_PROFILE"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800162 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000163 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800164 stage('Download Code') {
165 steps {
166 getVolthaCode([
167 branch: "${branch}",
168 gerritProject: "${gerritProject}",
169 gerritRefspec: "${gerritRefspec}",
170 volthaSystemTestsChange: "${volthaSystemTestsChange}",
171 volthaHelmChartsChange: "${volthaHelmChartsChange}",
172 ])
173 }
174 }
175 stage('Build patch') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000176 // build the patch only if gerritProject is specified
177 when {
178 expression {
179 return !gerritProject.isEmpty()
180 }
181 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800182 steps {
183 // NOTE that the correct patch has already been checked out
184 // during the getVolthaCode step
185 buildVolthaComponent("${gerritProject}")
186 }
187 }
188 stage('Create K8s Cluster') {
189 steps {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000190 script {
191 def clusterExists = sh returnStdout: true, script: """
192 kind get clusters | grep ${clusterName} | wc -l
193 """
194 if (clusterExists.trim() == "0") {
195 createKubernetesCluster([nodes: 3, name: clusterName])
196 }
197 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800198 }
199 }
Hardik Windlassc6ba23e2021-06-08 08:19:52 +0000200 stage('Replace voltctl') {
201 // if the project is voltctl override the downloaded one with the built one
202 when {
203 expression {
204 return gerritProject == "voltctl"
205 }
206 }
207 steps{
208 sh """
209 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
210 chmod +x $WORKSPACE/bin/voltctl
211 """
212 }
213 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800214 stage('Load image in kind nodes') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000215 when {
216 expression {
217 return !gerritProject.isEmpty()
218 }
219 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800220 steps {
221 loadToKind()
222 }
223 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000224 stage('Parse and execute tests') {
225 steps {
226 script {
227 def tests = readYaml text: testTargets
228
229 for(int i = 0;i<tests.size();i++) {
230 def test = tests[i]
231 def target = test["target"]
232 def workflow = test["workflow"]
233 def flags = test["flags"]
234 def teardown = test["teardown"].toBoolean()
Hardik Windlass60fc0da2021-10-14 07:02:40 +0000235 def logging = test["logging"]
236 println "Executing test ${target} on workflow ${workflow} with logging ${logging} and extra flags ${flags}"
237 execute_test(target, workflow, logging, teardown, flags)
Hardik Windlassec9341b2021-06-07 11:58:29 +0000238 }
239 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800240 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800241 }
242 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800243 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800244 aborted {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000245 collectArtifacts("aborted")
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800246 }
247 failure {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000248 collectArtifacts("failed")
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800249 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800250 always {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000251 collectArtifacts("always")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800252 }
253 }
254}