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