blob: 0d7c4a6bf6965dcea7ccc9ebc2718640ef74bd2d [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
114 """
115}
116
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800117pipeline {
118
119 /* no label, executor is determined by JJB */
120 agent {
121 label "${params.buildNode}"
122 }
123 options {
Matteo Scandolobd176d72021-02-03 10:55:25 -0800124 timeout(time: 30, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800125 }
126 environment {
127 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
128 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
129 }
130
131 stages{
132 stage('Download Code') {
133 steps {
134 getVolthaCode([
135 branch: "${branch}",
136 gerritProject: "${gerritProject}",
137 gerritRefspec: "${gerritRefspec}",
138 volthaSystemTestsChange: "${volthaSystemTestsChange}",
139 volthaHelmChartsChange: "${volthaHelmChartsChange}",
140 ])
141 }
142 }
143 stage('Build patch') {
144 steps {
145 // NOTE that the correct patch has already been checked out
146 // during the getVolthaCode step
147 buildVolthaComponent("${gerritProject}")
148 }
149 }
150 stage('Create K8s Cluster') {
151 steps {
152 createKubernetesCluster([nodes: 3])
153 }
154 }
155 stage('Load image in kind nodes') {
156 steps {
157 loadToKind()
158 }
159 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800160 stage('Replace voltctl') {
161 // if the project is voltctl override the downloaded one with the built one
162 when {
163 expression {
164 return gerritProject == "voltctl"
165 }
166 }
167 steps{
168 sh """
169 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
170 chmod +x $WORKSPACE/bin/voltctl
171 """
172 }
173 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800174 stage('Run Test') {
175 steps {
176 test_workflow("att")
177 test_workflow("dt")
178 test_workflow("tt")
179 }
180 }
181 }
182
183 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800184 aborted {
185 get_pods_info("$WORKSPACE/failed")
186 }
187 failure {
188 get_pods_info("$WORKSPACE/failed")
189 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800190 always {
191 sh '''
192 gzip $WORKSPACE/att/onos-voltha-combined.log || true
193 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
194 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
195 '''
196 step([$class: 'RobotPublisher',
197 disableArchiveOutput: false,
198 logFileName: 'RobotLogs/*/log*.html',
199 otherFiles: '',
200 outputFileName: 'RobotLogs/*/output*.xml',
201 outputPath: '.',
202 passThreshold: 100,
203 reportFileName: 'RobotLogs/*/report*.html',
204 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800205 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800206 }
207 }
208}