blob: 779c506c2a95a6d809613a833df70b25e350bc72 [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 // use harbor as passthrough cache for docker containers
70 extraHelmFlags += " --set global.image_registry=mirror.registry.opennetworking.org/ "
71 extraHelmFlags += " --set etcd.image.registry=mirror.registry.opennetworking.org "
72 extraHelmFlags += " --set kafka.image.registry=mirror.registry.opennetworking.org "
73 extraHelmFlags += " --set kafka.zookeper.image.registry=mirror.registry.opennetworking.org "
74 extraHelmFlags += " --set onos-classic.image.repository=mirror.registry.opennetworking.org/voltha/voltha-onos "
75 extraHelmFlags += " --set onos-classic.atomix.image.repository=mirror.registry.opennetworking.org/atomix/atomix "
76 extraHelmFlags += " --set freeradius.images.radius.registry=mirror.registry.opennetworking.org/ "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080077
Matteo Scandolod17de3a2021-04-09 15:47:52 -070078 if (gerritProject != "") {
79 extraHelmFlags = extraHelmFlags + customImageFlags("${gerritProject}")
80 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080081
Matteo Scandolod17de3a2021-04-09 15:47:52 -070082 def localCharts = false
83 if (gerritProject == "voltha-helm-charts") {
84 localCharts = true
85 }
86
87 volthaDeploy([workflow: name, extraHelmFlags: extraHelmFlags, localCharts: localCharts])
88 // start logging
89 sh """
90 mkdir -p $WORKSPACE/${name}
91 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
92 """
93 // forward ONOS and VOLTHA ports
94 sh """
95 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
96 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
97 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
98 """
99 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800100 }
101 stage('Test VOLTHA - '+ name + ' workflow') {
102 sh """
103 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
104 mkdir -p \$ROBOT_LOGS_DIR
105 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
106
107 # By default, all tests tagged 'sanity' are run. This covers basic functionality
108 # like running through the ATT workflow for a single subscriber.
109 export TARGET=sanity-kind-${name}
110
111 # If the Gerrit comment contains a line with "functional tests" then run the full
112 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
113 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
114 REGEX="functional tests"
115 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
116 export TARGET=functional-single-kind-${name}
117 fi
118
Hardik Windlass64486132021-02-02 13:35:22 +0000119 if [[ "${gerritProject}" == "bbsim" ]]; then
120 echo "Running BBSim specific Tests"
121 export TARGET=sanity-bbsim-${name}
122 fi
123
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800124 export VOLTCONFIG=$HOME/.volt/config
125 export KUBECONFIG=$HOME/.kube/config
126
127 # Run the specified tests
128 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
129 """
130 // stop logging
131 sh """
132 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
133 if [ -n "\$P_IDS" ]; then
134 echo \$P_IDS
135 for P_ID in \$P_IDS; do
136 kill -9 \$P_ID
137 done
138 fi
139 """
140 // remove port-forwarding
141 sh """
142 # remove orphaned port-forward from different namespaces
143 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
144 """
145 // collect pod details
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800146 get_pods_info("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800147 helmTeardown(['infra', 'voltha'])
148 }
149}
150
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800151def get_pods_info(dest) {
152 // collect pod details, this is here in case of failure
153 sh """
154 mkdir -p ${dest}
Andrea Campanellaf2460e8fb2021-03-15 22:03:09 +0100155 kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800156 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
157 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
158 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt
Matteo Scandoloa5990672021-03-15 10:41:06 -0700159 helm ls --all-namespaces | tee ${dest}/helm-charts.txt
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800160 """
161}
162
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800163pipeline {
164
165 /* no label, executor is determined by JJB */
166 agent {
167 label "${params.buildNode}"
168 }
169 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800170 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800171 }
172 environment {
173 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
174 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
175 }
176
177 stages{
178 stage('Download Code') {
179 steps {
180 getVolthaCode([
181 branch: "${branch}",
182 gerritProject: "${gerritProject}",
183 gerritRefspec: "${gerritRefspec}",
184 volthaSystemTestsChange: "${volthaSystemTestsChange}",
185 volthaHelmChartsChange: "${volthaHelmChartsChange}",
186 ])
187 }
188 }
189 stage('Build patch') {
190 steps {
191 // NOTE that the correct patch has already been checked out
192 // during the getVolthaCode step
193 buildVolthaComponent("${gerritProject}")
194 }
195 }
196 stage('Create K8s Cluster') {
197 steps {
198 createKubernetesCluster([nodes: 3])
199 }
200 }
201 stage('Load image in kind nodes') {
202 steps {
203 loadToKind()
204 }
205 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800206 stage('Replace voltctl') {
207 // if the project is voltctl override the downloaded one with the built one
208 when {
209 expression {
210 return gerritProject == "voltctl"
211 }
212 }
213 steps{
214 sh """
215 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
216 chmod +x $WORKSPACE/bin/voltctl
217 """
218 }
219 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800220 stage('Run Test') {
221 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800222 timeout(time: 30, unit: 'MINUTES') {
223 test_workflow("att")
224 test_workflow("dt")
225 test_workflow("tt")
226 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800227 }
228 }
229 }
230
231 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800232 aborted {
233 get_pods_info("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700234 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700235 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
Matteo Scandoloa5990672021-03-15 10:41:06 -0700236 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700237 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800238 }
239 failure {
240 get_pods_info("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700241 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700242 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs
Matteo Scandoloa5990672021-03-15 10:41:06 -0700243 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700244 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800245 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800246 always {
247 sh '''
248 gzip $WORKSPACE/att/onos-voltha-combined.log || true
249 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
250 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
251 '''
252 step([$class: 'RobotPublisher',
253 disableArchiveOutput: false,
254 logFileName: 'RobotLogs/*/log*.html',
255 otherFiles: '',
256 outputFileName: 'RobotLogs/*/output*.xml',
257 outputPath: '.',
258 passThreshold: 100,
259 reportFileName: 'RobotLogs/*/report*.html',
260 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800261 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800262 }
263 }
264}