blob: 127f080dbda2b2930d89db5944c82446f00b9a8b [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 Scandolo42f6e572021-01-25 15:11:34 -080026def customImageFlags(image) {
27 return "--set images.${image}.tag=citest,images.${image}.pullPolicy=Never "
28}
29
30def test_workflow(name) {
31 stage('Deploy - '+ name + ' workflow') {
32 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 "
33
34 if (gerritProject != "") {
35 extraHelmFlags = extraHelmFlags + customImageFlags("${gerritProject}")
36 }
37
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080038 def localCharts = false
39 if (gerritProject == "voltha-helm-charts") {
40 localCharts = true
41 }
42
43 volthaDeploy([workflow: name, extraHelmFlags: extraHelmFlags, localCharts: localCharts])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080044 // start logging
45 sh """
46 mkdir -p $WORKSPACE/${name}
47 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
48 """
49 // forward ONOS and VOLTHA ports
50 sh """
51 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
52 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
53 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
54 """
55 }
56 stage('Test VOLTHA - '+ name + ' workflow') {
57 sh """
58 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
59 mkdir -p \$ROBOT_LOGS_DIR
60 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
61
62 # By default, all tests tagged 'sanity' are run. This covers basic functionality
63 # like running through the ATT workflow for a single subscriber.
64 export TARGET=sanity-kind-${name}
65
66 # If the Gerrit comment contains a line with "functional tests" then run the full
67 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
68 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
69 REGEX="functional tests"
70 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
71 export TARGET=functional-single-kind-${name}
72 fi
73
Hardik Windlass64486132021-02-02 13:35:22 +000074 if [[ "${gerritProject}" == "bbsim" ]]; then
75 echo "Running BBSim specific Tests"
76 export TARGET=sanity-bbsim-${name}
77 fi
78
Matteo Scandolo42f6e572021-01-25 15:11:34 -080079 export VOLTCONFIG=$HOME/.volt/config
80 export KUBECONFIG=$HOME/.kube/config
81
82 # Run the specified tests
83 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
84 """
85 // stop logging
86 sh """
87 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
88 if [ -n "\$P_IDS" ]; then
89 echo \$P_IDS
90 for P_ID in \$P_IDS; do
91 kill -9 \$P_ID
92 done
93 fi
94 """
95 // remove port-forwarding
96 sh """
97 # remove orphaned port-forward from different namespaces
98 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
99 """
100 // collect pod details
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800101 get_pods_info("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800102 helmTeardown(['infra', 'voltha'])
103 }
104}
105
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800106def get_pods_info(dest) {
107 // collect pod details, this is here in case of failure
108 sh """
109 mkdir -p ${dest}
110 kubectl get pods --all-namespaces -o wide > ${dest}/pods.txt || true
111 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true
112 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true
113 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800114 helm ls --all-namespaces > ${dest}/helm-charts.txt
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800115 """
116}
117
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800118pipeline {
119
120 /* no label, executor is determined by JJB */
121 agent {
122 label "${params.buildNode}"
123 }
124 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800125 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800126 }
127 environment {
128 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
129 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
130 }
131
132 stages{
133 stage('Download Code') {
134 steps {
135 getVolthaCode([
136 branch: "${branch}",
137 gerritProject: "${gerritProject}",
138 gerritRefspec: "${gerritRefspec}",
139 volthaSystemTestsChange: "${volthaSystemTestsChange}",
140 volthaHelmChartsChange: "${volthaHelmChartsChange}",
141 ])
142 }
143 }
144 stage('Build patch') {
145 steps {
146 // NOTE that the correct patch has already been checked out
147 // during the getVolthaCode step
148 buildVolthaComponent("${gerritProject}")
149 }
150 }
151 stage('Create K8s Cluster') {
152 steps {
153 createKubernetesCluster([nodes: 3])
154 }
155 }
156 stage('Load image in kind nodes') {
157 steps {
158 loadToKind()
159 }
160 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800161 stage('Replace voltctl') {
162 // if the project is voltctl override the downloaded one with the built one
163 when {
164 expression {
165 return gerritProject == "voltctl"
166 }
167 }
168 steps{
169 sh """
170 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
171 chmod +x $WORKSPACE/bin/voltctl
172 """
173 }
174 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800175 stage('Run Test') {
176 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800177 timeout(time: 30, unit: 'MINUTES') {
178 test_workflow("att")
179 test_workflow("dt")
180 test_workflow("tt")
181 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800182 }
183 }
184 }
185
186 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800187 aborted {
188 get_pods_info("$WORKSPACE/failed")
189 }
190 failure {
191 get_pods_info("$WORKSPACE/failed")
192 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800193 always {
194 sh '''
195 gzip $WORKSPACE/att/onos-voltha-combined.log || true
196 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
197 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
198 '''
199 step([$class: 'RobotPublisher',
200 disableArchiveOutput: false,
201 logFileName: 'RobotLogs/*/log*.html',
202 otherFiles: '',
203 outputFileName: 'RobotLogs/*/output*.xml',
204 outputPath: '.',
205 passThreshold: 100,
206 reportFileName: 'RobotLogs/*/report*.html',
207 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800208 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800209 }
210 }
211}