blob: 5b15e102f615bcd59ac84f88aaa6b9cf81f95826 [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
55 return "images.bbsim.tag=citest,images.bbsim.pullPolicy=Never"
56 break
57 default:
58 throw new Exception("Don't know how to customize helm flags for custom image on project ${project}")
59 break
60 }
61
62 return "--set ${chart}.images.${image}.tag=citest,${chart}.images.${image}.pullPolicy=Never "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080063}
64
65def test_workflow(name) {
66 stage('Deploy - '+ name + ' workflow') {
67 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 "
68
69 if (gerritProject != "") {
70 extraHelmFlags = extraHelmFlags + customImageFlags("${gerritProject}")
71 }
72
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080073 def localCharts = false
74 if (gerritProject == "voltha-helm-charts") {
75 localCharts = true
76 }
77
78 volthaDeploy([workflow: name, extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080079 // start logging
80 sh """
81 mkdir -p $WORKSPACE/${name}
82 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
83 """
84 // forward ONOS and VOLTHA ports
85 sh """
86 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
87 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
88 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
89 """
90 }
91 stage('Test VOLTHA - '+ name + ' workflow') {
92 sh """
93 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
94 mkdir -p \$ROBOT_LOGS_DIR
95 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
96
97 # By default, all tests tagged 'sanity' are run. This covers basic functionality
98 # like running through the ATT workflow for a single subscriber.
99 export TARGET=sanity-kind-${name}
100
101 # If the Gerrit comment contains a line with "functional tests" then run the full
102 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
103 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
104 REGEX="functional tests"
105 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
106 export TARGET=functional-single-kind-${name}
107 fi
108
Hardik Windlass64486132021-02-02 13:35:22 +0000109 if [[ "${gerritProject}" == "bbsim" ]]; then
110 echo "Running BBSim specific Tests"
111 export TARGET=sanity-bbsim-${name}
112 fi
113
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800114 export VOLTCONFIG=$HOME/.volt/config
115 export KUBECONFIG=$HOME/.kube/config
116
117 # Run the specified tests
118 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
119 """
120 // stop logging
121 sh """
122 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
123 if [ -n "\$P_IDS" ]; then
124 echo \$P_IDS
125 for P_ID in \$P_IDS; do
126 kill -9 \$P_ID
127 done
128 fi
129 """
130 // remove port-forwarding
131 sh """
132 # remove orphaned port-forward from different namespaces
133 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
134 """
135 // collect pod details
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800136 get_pods_info("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800137 helmTeardown(['infra', 'voltha'])
138 }
139}
140
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800141def get_pods_info(dest) {
142 // collect pod details, this is here in case of failure
143 sh """
144 mkdir -p ${dest}
145 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
146 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
147 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
148 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800149 helm ls --all-namespaces > ${dest}/helm-charts.txt
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800150 """
151}
152
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800153pipeline {
154
155 /* no label, executor is determined by JJB */
156 agent {
157 label "${params.buildNode}"
158 }
159 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800160 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800161 }
162 environment {
163 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
164 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
165 }
166
167 stages{
168 stage('Download Code') {
169 steps {
170 getVolthaCode([
171 branch: "${branch}",
172 gerritProject: "${gerritProject}",
173 gerritRefspec: "${gerritRefspec}",
174 volthaSystemTestsChange: "${volthaSystemTestsChange}",
175 volthaHelmChartsChange: "${volthaHelmChartsChange}",
176 ])
177 }
178 }
179 stage('Build patch') {
180 steps {
181 // NOTE that the correct patch has already been checked out
182 // during the getVolthaCode step
183 buildVolthaComponent("${gerritProject}")
184 }
185 }
186 stage('Create K8s Cluster') {
187 steps {
188 createKubernetesCluster([nodes: 3])
189 }
190 }
191 stage('Load image in kind nodes') {
192 steps {
193 loadToKind()
194 }
195 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800196 stage('Replace voltctl') {
197 // if the project is voltctl override the downloaded one with the built one
198 when {
199 expression {
200 return gerritProject == "voltctl"
201 }
202 }
203 steps{
204 sh """
205 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
206 chmod +x $WORKSPACE/bin/voltctl
207 """
208 }
209 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800210 stage('Run Test') {
211 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800212 timeout(time: 30, unit: 'MINUTES') {
213 test_workflow("att")
214 test_workflow("dt")
215 test_workflow("tt")
216 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800217 }
218 }
219 }
220
221 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800222 aborted {
223 get_pods_info("$WORKSPACE/failed")
224 }
225 failure {
226 get_pods_info("$WORKSPACE/failed")
227 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800228 always {
229 sh '''
230 gzip $WORKSPACE/att/onos-voltha-combined.log || true
231 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
232 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
233 '''
234 step([$class: 'RobotPublisher',
235 disableArchiveOutput: false,
236 logFileName: 'RobotLogs/*/log*.html',
237 otherFiles: '',
238 outputFileName: 'RobotLogs/*/output*.xml',
239 outputPath: '.',
240 passThreshold: 100,
241 reportFileName: 'RobotLogs/*/report*.html',
242 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800243 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800244 }
245 }
246}