blob: da6e82f6e5e0edcec3abbc83cb51dab11999fa22 [file] [log] [blame]
Andrea Campanelladb8eac22021-03-30 14:27:16 +02001// 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
18// 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
26// 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
55 return "--set images.bbsim.tag=citest,images.bbsim.pullPolicy=Never"
56 break
57 default:
58 break
59 }
60
61 return "--set ${chart}.images.${image}.tag=citest,${chart}.images.${image}.pullPolicy=Never "
62}
63
64def test_workflow(name) {
65 stage('Deploy - '+ name + ' workflow') {
66 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 "
67
68 if (gerritProject != "") {
69 extraHelmFlags = extraHelmFlags + customImageFlags("${gerritProject}")
70 }
71
72 def localCharts = false
Matteo Scandolofe9e87d2021-05-19 15:55:16 -070073 if (gerritProject == "voltha-helm-charts" || branch != "master") {
Andrea Campanelladb8eac22021-03-30 14:27:16 +020074 localCharts = true
75 }
76
Matteo Scandolofe9e87d2021-05-19 15:55:16 -070077 volthaDeploy([
78 workflow: name,
79 extraHelmFlags: extraHelmFlags,
80 localCharts: localCharts,
81 dockerRegistry: "mirror.registry.opennetworking.org"
82 ])
Andrea Campanelladb8eac22021-03-30 14:27:16 +020083 // start logging
84 sh """
85 mkdir -p $WORKSPACE/${name}
86 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
87 """
88 // forward ONOS and VOLTHA ports
89 sh """
90 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
91 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
92 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
93 """
94 }
95 stage('Test VOLTHA - '+ name + ' workflow') {
96 sh """
97 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
98 mkdir -p \$ROBOT_LOGS_DIR
99 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
100
101 # By default, all tests tagged 'sanity' are run. This covers basic functionality
102 # like running through the ATT workflow for a single subscriber.
103 export TARGET=sanity-kind-${name}
104
105 # If the Gerrit comment contains a line with "functional tests" then run the full
106 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
107 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
108 REGEX="functional tests"
109 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
110 export TARGET=functional-single-kind-${name}
111 fi
112
113 if [[ "${gerritProject}" == "bbsim" ]]; then
114 echo "Running BBSim specific Tests"
115 export TARGET=sanity-bbsim-${name}
116 fi
117
118 export VOLTCONFIG=$HOME/.volt/config
119 export KUBECONFIG=$HOME/.kube/config
120
121 # Run the specified tests
122 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
123 """
124 // stop logging
125 sh """
126 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
127 if [ -n "\$P_IDS" ]; then
128 echo \$P_IDS
129 for P_ID in \$P_IDS; do
130 kill -9 \$P_ID
131 done
132 fi
133 """
134 // remove port-forwarding
135 sh """
136 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200137 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
Andrea Campanelladb8eac22021-03-30 14:27:16 +0200138 """
139 // collect pod details
140 get_pods_info("$WORKSPACE/${name}")
141 helmTeardown(['infra', 'voltha'])
142 }
143}
144
145def get_pods_info(dest) {
146 // collect pod details, this is here in case of failure
147 sh """
148 mkdir -p ${dest}
149 kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true
150 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
151 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
152 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt
153 helm ls --all-namespaces | tee ${dest}/helm-charts.txt
154 """
155}
156
157pipeline {
158
159 /* no label, executor is determined by JJB */
160 agent {
161 label "${params.buildNode}"
162 }
163 options {
164 timeout(time: 35, unit: 'MINUTES')
165 }
166 environment {
167 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
168 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
169 }
170
171 stages{
172 stage('Download Code') {
173 steps {
174 getVolthaCode([
175 branch: "${branch}",
176 gerritProject: "${gerritProject}",
177 gerritRefspec: "${gerritRefspec}",
178 volthaSystemTestsChange: "${volthaSystemTestsChange}",
179 volthaHelmChartsChange: "${volthaHelmChartsChange}",
180 ])
181 }
182 }
183 stage('Build patch') {
184 steps {
185 // NOTE that the correct patch has already been checked out
186 // during the getVolthaCode step
187 buildVolthaComponent("${gerritProject}")
188 }
189 }
190 stage('Create K8s Cluster') {
191 steps {
192 createKubernetesCluster([nodes: 3])
193 }
194 }
195 stage('Load image in kind nodes') {
196 steps {
197 loadToKind()
198 }
199 }
200 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 }
214 stage('Run Test') {
215 steps {
216 timeout(time: 30, unit: 'MINUTES') {
217 test_workflow("att")
218 test_workflow("dt")
219 test_workflow("tt")
220 }
221 }
222 }
223 }
224
225 post {
226 aborted {
227 get_pods_info("$WORKSPACE/failed")
228 sh """
229 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
230 """
231 archiveArtifacts artifacts: '**/*.log,**/*.txt'
232 }
233 failure {
234 get_pods_info("$WORKSPACE/failed")
235 sh """
236 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs
237 """
238 archiveArtifacts artifacts: '**/*.log,**/*.txt'
239 }
240 always {
241 sh '''
242 gzip $WORKSPACE/att/onos-voltha-combined.log || true
243 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
244 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
245 '''
246 step([$class: 'RobotPublisher',
247 disableArchiveOutput: false,
248 logFileName: 'RobotLogs/*/log*.html',
249 otherFiles: '',
250 outputFileName: 'RobotLogs/*/output*.xml',
251 outputPath: '.',
252 passThreshold: 100,
253 reportFileName: 'RobotLogs/*/report*.html',
254 unstableThreshold: 0]);
255 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
256 }
257 }
258}