blob: 6bcc5bad4efdcd28f88198fcae7274115dc8f573 [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 Scandoloc953a8c2021-05-19 13:26:12 -070027 timeout(time: 5, unit: 'MINUTES') {
Matteo Scandolod17de3a2021-04-09 15:47:52 -070028 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
Matteo Scandolofe9e87d2021-05-19 15:55:16 -070036 if (gerritProject == "voltha-helm-charts" || branch != "master") {
Matteo Scandolod17de3a2021-04-09 15:47:52 -070037 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') {
Matteo Scandoloc953a8c2021-05-19 13:26:12 -070060 timeout(time: 5, unit: 'MINUTES') {
Matteo Scandolo42f6e572021-01-25 15:11:34 -080061 sh """
62 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
63 mkdir -p \$ROBOT_LOGS_DIR
64 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
65
66 # By default, all tests tagged 'sanity' are run. This covers basic functionality
67 # like running through the ATT workflow for a single subscriber.
68 export TARGET=sanity-kind-${name}
69
70 # If the Gerrit comment contains a line with "functional tests" then run the full
71 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
72 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
73 REGEX="functional tests"
74 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
75 export TARGET=functional-single-kind-${name}
76 fi
77
Hardik Windlass64486132021-02-02 13:35:22 +000078 if [[ "${gerritProject}" == "bbsim" ]]; then
79 echo "Running BBSim specific Tests"
80 export TARGET=sanity-bbsim-${name}
81 fi
82
Matteo Scandolo42f6e572021-01-25 15:11:34 -080083 export VOLTCONFIG=$HOME/.volt/config
84 export KUBECONFIG=$HOME/.kube/config
85
86 # Run the specified tests
87 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
88 """
89 // stop logging
90 sh """
91 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
92 if [ -n "\$P_IDS" ]; then
93 echo \$P_IDS
94 for P_ID in \$P_IDS; do
95 kill -9 \$P_ID
96 done
97 fi
98 """
99 // remove port-forwarding
100 sh """
101 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200102 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800103 """
104 // collect pod details
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700105 getPodsInfo("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800106 helmTeardown(['infra', 'voltha'])
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700107 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800108 }
109}
110
111pipeline {
112
113 /* no label, executor is determined by JJB */
114 agent {
115 label "${params.buildNode}"
116 }
117 options {
Matteo Scandolo5dcde382021-03-11 15:52:54 -0800118 timeout(time: 35, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800119 }
120 environment {
121 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
122 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
123 }
124
125 stages{
126 stage('Download Code') {
127 steps {
128 getVolthaCode([
129 branch: "${branch}",
130 gerritProject: "${gerritProject}",
131 gerritRefspec: "${gerritRefspec}",
132 volthaSystemTestsChange: "${volthaSystemTestsChange}",
133 volthaHelmChartsChange: "${volthaHelmChartsChange}",
134 ])
135 }
136 }
137 stage('Build patch') {
138 steps {
139 // NOTE that the correct patch has already been checked out
140 // during the getVolthaCode step
141 buildVolthaComponent("${gerritProject}")
142 }
143 }
144 stage('Create K8s Cluster') {
145 steps {
146 createKubernetesCluster([nodes: 3])
147 }
148 }
149 stage('Load image in kind nodes') {
150 steps {
151 loadToKind()
152 }
153 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800154 stage('Replace voltctl') {
155 // if the project is voltctl override the downloaded one with the built one
156 when {
157 expression {
158 return gerritProject == "voltctl"
159 }
160 }
161 steps{
162 sh """
163 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
164 chmod +x $WORKSPACE/bin/voltctl
165 """
166 }
167 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800168 stage('Run Test') {
169 steps {
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700170 // preload the venv so it's not included in the timeout for the first test execution
171 sh """
172 make -C $WORKSPACE/voltha-system-tests vst_venv || true
173 """
174 test_workflow("att")
175 test_workflow("dt")
176 test_workflow("tt")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800177 }
178 }
179 }
180
181 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800182 aborted {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700183 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700184 sh """
Matteo Scandolo0da60532021-05-06 08:59:42 -0700185 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log || true
Matteo Scandoloa5990672021-03-15 10:41:06 -0700186 """
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700187 archiveArtifacts artifacts: '**/*.log,**/*.txt,**/*.html'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800188 }
189 failure {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700190 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700191 sh """
Matteo Scandolo0da60532021-05-06 08:59:42 -0700192 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs || true
Matteo Scandoloa5990672021-03-15 10:41:06 -0700193 """
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700194 archiveArtifacts artifacts: '**/*.log,**/*.txt,**/*.html'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800195 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800196 always {
197 sh '''
198 gzip $WORKSPACE/att/onos-voltha-combined.log || true
199 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
200 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
201 '''
202 step([$class: 'RobotPublisher',
203 disableArchiveOutput: false,
204 logFileName: 'RobotLogs/*/log*.html',
205 otherFiles: '',
206 outputFileName: 'RobotLogs/*/output*.xml',
207 outputPath: '.',
208 passThreshold: 100,
209 reportFileName: 'RobotLogs/*/report*.html',
210 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800211 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800212 }
213 }
214}