blob: 2e2179c460008cf1a1b757817b2ecec14452badf [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 test_workflow(name) {
Matteo Scandolod17de3a2021-04-09 15:47:52 -070027 timeout(time: 10, unit: 'MINUTES') {
28 stage('Deploy - '+ name + ' workflow') {
29 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080030
Matteo Scandolod17de3a2021-04-09 15:47:52 -070031 if (gerritProject != "") {
Matteo Scandolo9b644ba2021-04-19 11:21:07 -070032 extraHelmFlags = extraHelmFlags + getVolthaImageFlags("${gerritProject}")
Matteo Scandolod17de3a2021-04-09 15:47:52 -070033 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080034
Matteo Scandolod17de3a2021-04-09 15:47:52 -070035 def localCharts = false
36 if (gerritProject == "voltha-helm-charts") {
37 localCharts = true
38 }
39
Matteo Scandolo37f168b2021-04-15 16:20:46 -070040 volthaDeploy([
41 workflow: name,
42 extraHelmFlags:extraHelmFlags,
43 localCharts: localCharts,
44 dockerRegistry: "mirror.registry.opennetworking.org"
45 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -070046 // start logging
47 sh """
48 mkdir -p $WORKSPACE/${name}
49 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
50 """
51 // forward ONOS and VOLTHA ports
52 sh """
53 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
54 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
55 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
56 """
57 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -080058 }
59 stage('Test VOLTHA - '+ name + ' workflow') {
60 sh """
61 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
62 mkdir -p \$ROBOT_LOGS_DIR
63 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
64
65 # By default, all tests tagged 'sanity' are run. This covers basic functionality
66 # like running through the ATT workflow for a single subscriber.
67 export TARGET=sanity-kind-${name}
68
69 # If the Gerrit comment contains a line with "functional tests" then run the full
70 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
71 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
72 REGEX="functional tests"
73 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
74 export TARGET=functional-single-kind-${name}
75 fi
76
Hardik Windlass64486132021-02-02 13:35:22 +000077 if [[ "${gerritProject}" == "bbsim" ]]; then
78 echo "Running BBSim specific Tests"
79 export TARGET=sanity-bbsim-${name}
80 fi
81
Matteo Scandolo42f6e572021-01-25 15:11:34 -080082 export VOLTCONFIG=$HOME/.volt/config
83 export KUBECONFIG=$HOME/.kube/config
84
85 # Run the specified tests
86 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
87 """
88 // stop logging
89 sh """
90 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
91 if [ -n "\$P_IDS" ]; then
92 echo \$P_IDS
93 for P_ID in \$P_IDS; do
94 kill -9 \$P_ID
95 done
96 fi
97 """
98 // remove port-forwarding
99 sh """
100 # remove orphaned port-forward from different namespaces
101 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
102 """
103 // collect pod details
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700104 getPodsInfo("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800105 helmTeardown(['infra', 'voltha'])
106 }
107}
108
109pipeline {
110
111 /* no label, executor is determined by JJB */
112 agent {
113 label "${params.buildNode}"
114 }
115 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800116 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800117 }
118 environment {
119 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
120 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
121 }
122
123 stages{
124 stage('Download Code') {
125 steps {
126 getVolthaCode([
127 branch: "${branch}",
128 gerritProject: "${gerritProject}",
129 gerritRefspec: "${gerritRefspec}",
130 volthaSystemTestsChange: "${volthaSystemTestsChange}",
131 volthaHelmChartsChange: "${volthaHelmChartsChange}",
132 ])
133 }
134 }
135 stage('Build patch') {
136 steps {
137 // NOTE that the correct patch has already been checked out
138 // during the getVolthaCode step
139 buildVolthaComponent("${gerritProject}")
140 }
141 }
142 stage('Create K8s Cluster') {
143 steps {
144 createKubernetesCluster([nodes: 3])
145 }
146 }
147 stage('Load image in kind nodes') {
148 steps {
149 loadToKind()
150 }
151 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800152 stage('Replace voltctl') {
153 // if the project is voltctl override the downloaded one with the built one
154 when {
155 expression {
156 return gerritProject == "voltctl"
157 }
158 }
159 steps{
160 sh """
161 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
162 chmod +x $WORKSPACE/bin/voltctl
163 """
164 }
165 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800166 stage('Run Test') {
167 steps {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800168 timeout(time: 30, unit: 'MINUTES') {
169 test_workflow("att")
170 test_workflow("dt")
171 test_workflow("tt")
172 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800173 }
174 }
175 }
176
177 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800178 aborted {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700179 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700180 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700181 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
Matteo Scandoloa5990672021-03-15 10:41:06 -0700182 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700183 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800184 }
185 failure {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700186 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700187 sh """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700188 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs
Matteo Scandoloa5990672021-03-15 10:41:06 -0700189 """
Matteo Scandolo2411a3c2021-03-15 16:00:20 -0700190 archiveArtifacts artifacts: '**/*.log,**/*.txt'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800191 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800192 always {
193 sh '''
194 gzip $WORKSPACE/att/onos-voltha-combined.log || true
195 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
196 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
197 '''
198 step([$class: 'RobotPublisher',
199 disableArchiveOutput: false,
200 logFileName: 'RobotLogs/*/log*.html',
201 otherFiles: '',
202 outputFileName: 'RobotLogs/*/output*.xml',
203 outputPath: '.',
204 passThreshold: 100,
205 reportFileName: 'RobotLogs/*/report*.html',
206 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800207 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800208 }
209 }
210}