blob: f2cbf09080d6f436cdf2cd91f6e0c614d02f5259 [file] [log] [blame]
Matteo Scandolo075740f2021-04-22 14:52:29 -07001// 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
Matteo Scandoloa57b0972021-05-03 14:04:58 -070026def execute_test(testTarget, workflow, teardown, testSpecificHelmFlags = "") {
Matteo Scandolo075740f2021-04-22 14:52:29 -070027 def infraNamespace = "default"
28 def volthaNamespace = "voltha"
29 def robotLogsDir = "RobotLogs"
30 stage('Cleanup') {
Matteo Scandoloa57b0972021-05-03 14:04:58 -070031 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
40 '''
41 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070042 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070043 }
44 }
45 stage('Deploy Voltha') {
Matteo Scandoloa57b0972021-05-03 14:04:58 -070046 if (teardown) {
47 timeout(20) {
48 script {
Matteo Scandolo075740f2021-04-22 14:52:29 -070049
Matteo Scandolo0d04af82021-05-06 08:36:34 -070050 sh """
51 mkdir -p $WORKSPACE/${testTarget}-components
52 _TAG=kail-startup kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-startup-combined.log &
53 """
54
Matteo Scandoloa57b0972021-05-03 14:04:58 -070055 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
56 def localCharts = false
57 if (volthaHelmChartsChange != "") {
58 localCharts = true
59 }
60
61 // NOTE temporary workaround expose ONOS node ports
62 def localHelmFlags = extraHelmFlags + " --set onos-classic.onosSshPort=30115 " +
63 " --set onos-classic.onosApiPort=30120 " +
64 " --set onos-classic.onosOfPort=31653 " +
65 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
66 volthaDeploy([
67 infraNamespace: infraNamespace,
68 volthaNamespace: volthaNamespace,
69 workflow: workflow.toLowerCase(),
70 extraHelmFlags: localHelmFlags,
71 localCharts: localCharts,
72 bbsimReplica: olts.toInteger(),
73 dockerRegistry: registry,
74 ])
Matteo Scandolo075740f2021-04-22 14:52:29 -070075 }
Matteo Scandolo0d04af82021-05-06 08:36:34 -070076
77 // stop logging
78 sh """
79 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
80 if [ -n "\$P_IDS" ]; then
81 echo \$P_IDS
82 for P_ID in \$P_IDS; do
83 kill -9 \$P_ID
84 done
85 fi
86 """
Matteo Scandolo075740f2021-04-22 14:52:29 -070087 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070088 sh """
Matteo Scandoloa57b0972021-05-03 14:04:58 -070089 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"&
90 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"&
91 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"&
Matteo Scandolo075740f2021-04-22 14:52:29 -070092 ps aux | grep port-forward
93 """
Matteo Scandolo075740f2021-04-22 14:52:29 -070094 }
95 }
96 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
Matteo Scandolo0d04af82021-05-06 08:36:34 -070097 // start logging
98 sh """
99 mkdir -p $WORKSPACE/${testTarget}-components
100 _TAG=kail-${workflow} kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-combined.log &
101 """
Matteo Scandolo075740f2021-04-22 14:52:29 -0700102 sh """
Matteo Scandoloee626e02021-05-05 08:13:16 -0700103 mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot
104 export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot "
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700105 ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v INFRA_NAMESPACE:${infraNamespace}"
Matteo Scandolo075740f2021-04-22 14:52:29 -0700106 export KVSTOREPREFIX=voltha/voltha_voltha
107
108 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
109 """
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700110 // stop logging
111 sh """
112 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')"
113 if [ -n "\$P_IDS" ]; then
114 echo \$P_IDS
115 for P_ID in \$P_IDS; do
116 kill -9 \$P_ID
117 done
118 fi
119 """
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700120 getPodsInfo("$WORKSPACE/${testTarget}-components")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700121 }
122}
123
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700124def collectArtifacts(exitStatus) {
125 getPodsInfo("$WORKSPACE/${exitStatus}")
126 sh """
Matteo Scandolo0da60532021-05-06 08:59:42 -0700127 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700128 """
129 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
130 sh '''
131 sync
132 pkill kail || true
133 which voltctl
134 md5sum $(which voltctl)
135 '''
136 step([$class: 'RobotPublisher',
137 disableArchiveOutput: false,
138 logFileName: "RobotLogs/*/log*.html",
139 otherFiles: '',
140 outputFileName: "RobotLogs/*/output*.xml",
141 outputPath: '.',
142 passThreshold: 100,
143 reportFileName: "RobotLogs/*/report*.html",
144 unstableThreshold: 0]);
145}
146
Matteo Scandolo075740f2021-04-22 14:52:29 -0700147pipeline {
148
149 /* no label, executor is determined by JJB */
150 agent {
151 label "${params.buildNode}"
152 }
153 options {
154 timeout(time: 130, unit: 'MINUTES')
155 }
156 environment {
157 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"
162 }
163 stages {
164 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('Create K8s Cluster') {
176 steps {
177 script {
178 def clusterExists = sh returnStdout: true, script: """
179 kind get clusters | grep ${clusterName} | wc -l
180 """
181 if (clusterExists.trim() == "0") {
182 createKubernetesCluster([nodes: 3, name: clusterName])
183 }
184 }
185 }
186 }
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700187 stage('Parse and execute tests') {
188 steps {
189 script {
190 def tests = readYaml text: testTargets
Matteo Scandolo075740f2021-04-22 14:52:29 -0700191
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700192 for(int i = 0;i<tests.size();i++) {
193 def test = tests[i]
194 def target = test["target"]
195 def workflow = test["workflow"]
196 def flags = test["flags"]
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700197 def teardown = test["teardown"].toBoolean()
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700198 println "Executing test ${target} on workflow ${workflow} with extra flags ${flags}"
Matteo Scandoloa57b0972021-05-03 14:04:58 -0700199 execute_test(target, workflow, teardown, flags)
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700200 }
201 }
Matteo Scandolo075740f2021-04-22 14:52:29 -0700202 }
Matteo Scandolo075740f2021-04-22 14:52:29 -0700203 }
204 }
205 post {
206 aborted {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700207 collectArtifacts("aborted")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700208 }
209 failure {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700210 collectArtifacts("failed")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700211 }
212 always {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700213 collectArtifacts("always")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700214 }
215 }
216}