blob: 8b02a8818f21fe935746072ca7f455a959f0b550 [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 Scandolo85c26f82021-03-12 11:08:22 -080058 break
59 }
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 Scandoloe543c4c2021-03-09 07:34:29 -0800142 get_pods_info("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800143 helmTeardown(['infra', 'voltha'])
144 }
145}
146
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800147def get_pods_info(dest) {
148 // collect pod details, this is here in case of failure
149 sh """
150 mkdir -p ${dest}
Andrea Campanellaf2460e8fb2021-03-15 22:03:09 +0100151 kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800152 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
153 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
154 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt
Matteo Scandoloa5990672021-03-15 10:41:06 -0700155 helm ls --all-namespaces | tee ${dest}/helm-charts.txt
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800156 """
157}
158
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800159pipeline {
160
161 /* no label, executor is determined by JJB */
162 agent {
163 label "${params.buildNode}"
164 }
165 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800166 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800167 }
168 environment {
169 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
170 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
171 }
172
173 stages{
174 stage('Download Code') {
175 steps {
176 getVolthaCode([
177 branch: "${branch}",
178 gerritProject: "${gerritProject}",
179 gerritRefspec: "${gerritRefspec}",
180 volthaSystemTestsChange: "${volthaSystemTestsChange}",
181 volthaHelmChartsChange: "${volthaHelmChartsChange}",
182 ])
183 }
184 }
185 stage('Build patch') {
186 steps {
187 // NOTE that the correct patch has already been checked out
188 // during the getVolthaCode step
189 buildVolthaComponent("${gerritProject}")
190 }
191 }
192 stage('Create K8s Cluster') {
193 steps {
194 createKubernetesCluster([nodes: 3])
195 }
196 }
197 stage('Load image in kind nodes') {
198 steps {
199 loadToKind()
200 }
201 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800202 stage('Replace voltctl') {
203 // if the project is voltctl override the downloaded one with the built one
204 when {
205 expression {
206 return gerritProject == "voltctl"
207 }
208 }
209 steps{
210 sh """
211 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
212 chmod +x $WORKSPACE/bin/voltctl
213 """
214 }
215 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800216 stage('Run Test') {
217 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800218 timeout(time: 30, unit: 'MINUTES') {
219 test_workflow("att")
220 test_workflow("dt")
221 test_workflow("tt")
222 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800223 }
224 }
225 }
226
227 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800228 aborted {
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.log
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 }
235 failure {
236 get_pods_info("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700237 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700238 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs
Matteo Scandoloa5990672021-03-15 10:41:06 -0700239 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700240 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800241 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800242 always {
243 sh '''
244 gzip $WORKSPACE/att/onos-voltha-combined.log || true
245 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
246 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
247 '''
248 step([$class: 'RobotPublisher',
249 disableArchiveOutput: false,
250 logFileName: 'RobotLogs/*/log*.html',
251 otherFiles: '',
252 outputFileName: 'RobotLogs/*/output*.xml',
253 outputPath: '.',
254 passThreshold: 100,
255 reportFileName: 'RobotLogs/*/report*.html',
256 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800257 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800258 }
259 }
260}