blob: e38bc9a66abdc2a01051fe33856138266ffe5359 [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') {
Matteo Scandolo9114c892021-05-20 11:41:55 -070029 def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 " +
30 " --set onos-classic.onosSshPort=30115 " +
31 "--set onos-classic.onosApiPort=30120 "
Matteo Scandolo42f6e572021-01-25 15:11:34 -080032
Matteo Scandolod17de3a2021-04-09 15:47:52 -070033 if (gerritProject != "") {
Matteo Scandolo9b644ba2021-04-19 11:21:07 -070034 extraHelmFlags = extraHelmFlags + getVolthaImageFlags("${gerritProject}")
Matteo Scandolod17de3a2021-04-09 15:47:52 -070035 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080036
Matteo Scandolod17de3a2021-04-09 15:47:52 -070037 def localCharts = false
Matteo Scandolofe9e87d2021-05-19 15:55:16 -070038 if (gerritProject == "voltha-helm-charts" || branch != "master") {
Matteo Scandolod17de3a2021-04-09 15:47:52 -070039 localCharts = true
40 }
41
Matteo Scandolo37f168b2021-04-15 16:20:46 -070042 volthaDeploy([
43 workflow: name,
44 extraHelmFlags:extraHelmFlags,
45 localCharts: localCharts,
46 dockerRegistry: "mirror.registry.opennetworking.org"
47 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -070048 // start logging
49 sh """
50 mkdir -p $WORKSPACE/${name}
51 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
52 """
53 // forward ONOS and VOLTHA ports
54 sh """
Matteo Scandolo9114c892021-05-20 11:41:55 -070055 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555; done"&
Matteo Scandolod17de3a2021-04-09 15:47:52 -070056 """
57 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -080058 }
59 stage('Test VOLTHA - '+ name + ' workflow') {
Matteo Scandolo9114c892021-05-20 11:41:55 -070060 timeout(time: 10, 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
Matteo Scandolo9114c892021-05-20 11:41:55 -070064 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch "
65 ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120"
Matteo Scandolo42f6e572021-01-25 15:11:34 -080066
67 # By default, all tests tagged 'sanity' are run. This covers basic functionality
68 # like running through the ATT workflow for a single subscriber.
69 export TARGET=sanity-kind-${name}
70
71 # If the Gerrit comment contains a line with "functional tests" then run the full
72 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
73 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
74 REGEX="functional tests"
75 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
76 export TARGET=functional-single-kind-${name}
77 fi
78
Hardik Windlass64486132021-02-02 13:35:22 +000079 if [[ "${gerritProject}" == "bbsim" ]]; then
80 echo "Running BBSim specific Tests"
81 export TARGET=sanity-bbsim-${name}
82 fi
83
Matteo Scandolo42f6e572021-01-25 15:11:34 -080084 export VOLTCONFIG=$HOME/.volt/config
85 export KUBECONFIG=$HOME/.kube/config
86
87 # Run the specified tests
88 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
89 """
90 // stop logging
91 sh """
92 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
93 if [ -n "\$P_IDS" ]; then
94 echo \$P_IDS
95 for P_ID in \$P_IDS; do
96 kill -9 \$P_ID
97 done
98 fi
99 """
100 // remove port-forwarding
101 sh """
102 # remove orphaned port-forward from different namespaces
Andrea Campanella4c8af942021-05-12 10:12:13 +0200103 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 -0800104 """
105 // collect pod details
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700106 getPodsInfo("$WORKSPACE/${name}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800107 helmTeardown(['infra', 'voltha'])
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700108 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800109 }
110}
111
112pipeline {
113
114 /* no label, executor is determined by JJB */
115 agent {
116 label "${params.buildNode}"
117 }
118 options {
Matteo Scandolo9114c892021-05-20 11:41:55 -0700119 timeout(time: 50, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800120 }
121 environment {
122 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
123 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
124 }
125
126 stages{
127 stage('Download Code') {
128 steps {
129 getVolthaCode([
130 branch: "${branch}",
131 gerritProject: "${gerritProject}",
132 gerritRefspec: "${gerritRefspec}",
133 volthaSystemTestsChange: "${volthaSystemTestsChange}",
134 volthaHelmChartsChange: "${volthaHelmChartsChange}",
135 ])
136 }
137 }
138 stage('Build patch') {
139 steps {
140 // NOTE that the correct patch has already been checked out
141 // during the getVolthaCode step
142 buildVolthaComponent("${gerritProject}")
143 }
144 }
145 stage('Create K8s Cluster') {
146 steps {
147 createKubernetesCluster([nodes: 3])
148 }
149 }
150 stage('Load image in kind nodes') {
151 steps {
152 loadToKind()
153 }
154 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800155 stage('Replace voltctl') {
156 // if the project is voltctl override the downloaded one with the built one
157 when {
158 expression {
159 return gerritProject == "voltctl"
160 }
161 }
162 steps{
163 sh """
164 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
165 chmod +x $WORKSPACE/bin/voltctl
166 """
167 }
168 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800169 stage('Run Test') {
170 steps {
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700171 // preload the venv so it's not included in the timeout for the first test execution
172 sh """
173 make -C $WORKSPACE/voltha-system-tests vst_venv || true
174 """
175 test_workflow("att")
176 test_workflow("dt")
177 test_workflow("tt")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800178 }
179 }
180 }
181
182 post {
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800183 aborted {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700184 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700185 sh """
Matteo Scandolo0da60532021-05-06 08:59:42 -0700186 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log || true
Matteo Scandoloa5990672021-03-15 10:41:06 -0700187 """
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700188 archiveArtifacts artifacts: '**/*.log,**/*.txt,**/*.html'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800189 }
190 failure {
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700191 getPodsInfo("$WORKSPACE/failed")
Matteo Scandoloa5990672021-03-15 10:41:06 -0700192 sh """
Matteo Scandolo0da60532021-05-06 08:59:42 -0700193 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs || true
Matteo Scandoloa5990672021-03-15 10:41:06 -0700194 """
Matteo Scandoloc953a8c2021-05-19 13:26:12 -0700195 archiveArtifacts artifacts: '**/*.log,**/*.txt,**/*.html'
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800196 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800197 always {
198 sh '''
199 gzip $WORKSPACE/att/onos-voltha-combined.log || true
200 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
201 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
202 '''
203 step([$class: 'RobotPublisher',
204 disableArchiveOutput: false,
205 logFileName: 'RobotLogs/*/log*.html',
206 otherFiles: '',
207 outputFileName: 'RobotLogs/*/output*.xml',
208 outputPath: '.',
209 passThreshold: 100,
210 reportFileName: 'RobotLogs/*/report*.html',
211 unstableThreshold: 0]);
Matteo Scandoloe543c4c2021-03-09 07:34:29 -0800212 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800213 }
214 }
215}