blob: 63d258227cdb7b5a2e176f1a1f92b911d70a3ee4 [file] [log] [blame]
Matteo Scandolo42f6e572021-01-25 15:11:34 -08001// Copyright 2017-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
16// uses bbsim to simulate OLT/ONUs
17
Matteo Scandoloa156b572021-02-04 11:52:18 -080018// NOTE we are importing the library even if it's global so that it's
19// easier to change the keywords during a replay
20library identifier: 'cord-jenkins-libraries@master',
21 retriever: modernSCM([
22 $class: 'GitSCMSource',
23 remote: 'https://gerrit.opencord.org/ci-management.git'
24])
25
Matteo Scandolo85c26f82021-03-12 11:08:22 -080026// TODO move this in a keyword so it can be shared across pipelines
27def customImageFlags(project) {
28 def chart = "unknown"
29 def image = "unknown"
30 switch(project) {
31 case "ofagent-go":
32 chart = "voltha"
33 image = "ofagent"
34 break
35 case "voltha-go":
36 chart = "voltha"
37 image = "rw_core"
38 break
39 case "voltha-openonu-adapter-go":
40 chart = "voltha-adapter-openonu"
41 image = "adapter_open_onu_go"
42 break
43 // TODO remove after 2.7
44 case "voltha-openonu-adapter":
45 chart = "voltha-adapter-openonu"
46 image = "adapter_open_onu"
47 break
48 // TODO end
49 case "voltha-openolt-adapter":
50 chart = "voltha-adapter-openolt"
51 image = "adapter_open_olt"
52 break
53 case "bbsim":
54 // BBSIM has a different format that voltha, return directly
Matteo Scandolod17de3a2021-04-09 15:47:52 -070055 return "--set images.bbsim.tag=citest,images.bbsim.pullPolicy=Never,images.bbsim.registry='' "
Matteo Scandolo85c26f82021-03-12 11:08:22 -080056 break
57 default:
Matteo Scandolo59470992021-04-20 11:30:57 -070058 return ""
Matteo Scandolo85c26f82021-03-12 11:08:22 -080059 }
60
Matteo Scandolod17de3a2021-04-09 15:47:52 -070061 return "--set ${chart}.images.${image}.tag=citest,${chart}.images.${image}.pullPolicy=Never,${chart}.images.${image}.registry='' "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080062}
63
64def test_workflow(name) {
Matteo Scandolod17de3a2021-04-09 15:47:52 -070065 timeout(time: 10, unit: 'MINUTES') {
66 stage('Deploy - '+ name + ' workflow') {
67 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080068
Matteo Scandolod17de3a2021-04-09 15:47:52 -070069 if (gerritProject != "") {
70 extraHelmFlags = extraHelmFlags + customImageFlags("${gerritProject}")
71 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080072
Matteo Scandolod17de3a2021-04-09 15:47:52 -070073 def localCharts = false
74 if (gerritProject == "voltha-helm-charts") {
75 localCharts = true
76 }
77
Matteo Scandolo37f168b2021-04-15 16:20:46 -070078 volthaDeploy([
79 workflow: name,
80 extraHelmFlags:extraHelmFlags,
81 localCharts: localCharts,
82 dockerRegistry: "mirror.registry.opennetworking.org"
83 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -070084 // start logging
85 sh """
86 mkdir -p $WORKSPACE/${name}
87 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
88 """
89 // forward ONOS and VOLTHA ports
90 sh """
91 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
92 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
93 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
94 """
95 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -080096 }
97 stage('Test VOLTHA - '+ name + ' workflow') {
98 sh """
99 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
100 mkdir -p \$ROBOT_LOGS_DIR
101 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
102
103 # By default, all tests tagged 'sanity' are run. This covers basic functionality
104 # like running through the ATT workflow for a single subscriber.
105 export TARGET=sanity-kind-${name}
106
107 # If the Gerrit comment contains a line with "functional tests" then run the full
108 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
109 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
110 REGEX="functional tests"
111 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
112 export TARGET=functional-single-kind-${name}
113 fi
114
Hardik Windlass64486132021-02-02 13:35:22 +0000115 if [[ "${gerritProject}" == "bbsim" ]]; then
116 echo "Running BBSim specific Tests"
117 export TARGET=sanity-bbsim-${name}
118 fi
119
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800120 export VOLTCONFIG=$HOME/.volt/config
121 export KUBECONFIG=$HOME/.kube/config
122
123 # Run the specified tests
124 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
125 """
126 // stop logging
127 sh """
128 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
129 if [ -n "\$P_IDS" ]; then
130 echo \$P_IDS
131 for P_ID in \$P_IDS; do
132 kill -9 \$P_ID
133 done
134 fi
135 """
136 // remove port-forwarding
137 sh """
138 # remove orphaned port-forward from different namespaces
139 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
140 """
141 // collect pod details
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700142 getPodsInfo("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800143 helmTeardown(['infra', 'voltha'])
144 }
145}
146
147pipeline {
148
149 /* no label, executor is determined by JJB */
150 agent {
151 label "${params.buildNode}"
152 }
153 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800154 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800155 }
156 environment {
157 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
158 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
159 }
160
161 stages{
162 stage('Download Code') {
163 steps {
164 getVolthaCode([
165 branch: "${branch}",
166 gerritProject: "${gerritProject}",
167 gerritRefspec: "${gerritRefspec}",
168 volthaSystemTestsChange: "${volthaSystemTestsChange}",
169 volthaHelmChartsChange: "${volthaHelmChartsChange}",
170 ])
171 }
172 }
173 stage('Build patch') {
174 steps {
175 // NOTE that the correct patch has already been checked out
176 // during the getVolthaCode step
177 buildVolthaComponent("${gerritProject}")
178 }
179 }
180 stage('Create K8s Cluster') {
181 steps {
182 createKubernetesCluster([nodes: 3])
183 }
184 }
185 stage('Load image in kind nodes') {
186 steps {
187 loadToKind()
188 }
189 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800190 stage('Replace voltctl') {
191 // if the project is voltctl override the downloaded one with the built one
192 when {
193 expression {
194 return gerritProject == "voltctl"
195 }
196 }
197 steps{
198 sh """
199 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
200 chmod +x $WORKSPACE/bin/voltctl
201 """
202 }
203 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800204 stage('Run Test') {
205 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800206 timeout(time: 30, unit: 'MINUTES') {
207 test_workflow("att")
208 test_workflow("dt")
209 test_workflow("tt")
210 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800211 }
212 }
213 }
214
215 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800216 aborted {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700217 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700218 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700219 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
Matteo Scandoloa5990672021-03-15 10:41:06 -0700220 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700221 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800222 }
223 failure {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700224 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700225 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700226 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs
Matteo Scandoloa5990672021-03-15 10:41:06 -0700227 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700228 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800229 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800230 always {
231 sh '''
232 gzip $WORKSPACE/att/onos-voltha-combined.log || true
233 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
234 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
235 '''
236 step([$class: 'RobotPublisher',
237 disableArchiveOutput: false,
238 logFileName: 'RobotLogs/*/log*.html',
239 otherFiles: '',
240 outputFileName: 'RobotLogs/*/output*.xml',
241 outputPath: '.',
242 passThreshold: 100,
243 reportFileName: 'RobotLogs/*/report*.html',
244 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800245 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800246 }
247 }
248}