blob: 41720cd43153f7f6e22071ca9553f4f76ad9ba40 [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
Andrea Campanella47811142021-03-15 10:20:28 +010055 return "--set images.bbsim.tag=citest,images.bbsim.pullPolicy=Never"
Matteo Scandolo85c26f82021-03-12 11:08:22 -080056 break
57 default:
Matteo Scandolo85c26f82021-03-12 11:08:22 -080058 break
59 }
60
61 return "--set ${chart}.images.${image}.tag=citest,${chart}.images.${image}.pullPolicy=Never "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080062}
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
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080072 def localCharts = false
73 if (gerritProject == "voltha-helm-charts") {
74 localCharts = true
75 }
76
77 volthaDeploy([workflow: name, extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080078 // 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
Hardik Windlass64486132021-02-02 13:35:22 +0000108 if [[ "${gerritProject}" == "bbsim" ]]; then
109 echo "Running BBSim specific Tests"
110 export TARGET=sanity-bbsim-${name}
111 fi
112
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800113 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
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800135 get_pods_info("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800136 helmTeardown(['infra', 'voltha'])
137 }
138}
139
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800140def get_pods_info(dest) {
141 // collect pod details, this is here in case of failure
142 sh """
143 mkdir -p ${dest}
Andrea Campanellaf2460e8fb2021-03-15 22:03:09 +0100144 kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800145 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
Matteo Scandoloa5990672021-03-15 10:41:06 -0700148 helm ls --all-namespaces | tee ${dest}/helm-charts.txt
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800149 """
150}
151
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800152pipeline {
153
154 /* no label, executor is determined by JJB */
155 agent {
156 label "${params.buildNode}"
157 }
158 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800159 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800160 }
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 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800195 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 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800209 stage('Run Test') {
210 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800211 timeout(time: 30, unit: 'MINUTES') {
212 test_workflow("att")
213 test_workflow("dt")
214 test_workflow("tt")
215 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800216 }
217 }
218 }
219
220 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800221 aborted {
222 get_pods_info("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700223 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700224 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
Matteo Scandoloa5990672021-03-15 10:41:06 -0700225 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700226 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800227 }
228 failure {
229 get_pods_info("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700230 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700231 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs
Matteo Scandoloa5990672021-03-15 10:41:06 -0700232 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700233 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800234 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800235 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]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800250 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800251 }
252 }
253}