blob: 0dabbceacf32d20f8ed31c1f99b8e4c2954993e9 [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
101 sh """
102 kubectl get pods --all-namespaces -o wide > \$WORKSPACE/${name}/pods.txt || true
103 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee \$WORKSPACE/att/pod-images.txt || true
104 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee \$WORKSPACE/att/pod-imagesId.txt || true
105 """
106 helmTeardown(['infra', 'voltha'])
107 }
108}
109
110pipeline {
111
112 /* no label, executor is determined by JJB */
113 agent {
114 label "${params.buildNode}"
115 }
116 options {
Matteo Scandolobd176d72021-02-03 10:55:25 -0800117 timeout(time: 30, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800118 }
119 environment {
120 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
121 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
122 }
123
124 stages{
125 stage('Download Code') {
126 steps {
127 getVolthaCode([
128 branch: "${branch}",
129 gerritProject: "${gerritProject}",
130 gerritRefspec: "${gerritRefspec}",
131 volthaSystemTestsChange: "${volthaSystemTestsChange}",
132 volthaHelmChartsChange: "${volthaHelmChartsChange}",
133 ])
134 }
135 }
136 stage('Build patch') {
137 steps {
138 // NOTE that the correct patch has already been checked out
139 // during the getVolthaCode step
140 buildVolthaComponent("${gerritProject}")
141 }
142 }
143 stage('Create K8s Cluster') {
144 steps {
145 createKubernetesCluster([nodes: 3])
146 }
147 }
148 stage('Load image in kind nodes') {
149 steps {
150 loadToKind()
151 }
152 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800153 stage('Replace voltctl') {
154 // if the project is voltctl override the downloaded one with the built one
155 when {
156 expression {
157 return gerritProject == "voltctl"
158 }
159 }
160 steps{
161 sh """
162 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
163 chmod +x $WORKSPACE/bin/voltctl
164 """
165 }
166 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800167 stage('Run Test') {
168 steps {
169 test_workflow("att")
170 test_workflow("dt")
171 test_workflow("tt")
172 }
173 }
174 }
175
176 post {
177 always {
178 sh '''
179 gzip $WORKSPACE/att/onos-voltha-combined.log || true
180 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
181 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
182 '''
183 step([$class: 'RobotPublisher',
184 disableArchiveOutput: false,
185 logFileName: 'RobotLogs/*/log*.html',
186 otherFiles: '',
187 outputFileName: 'RobotLogs/*/output*.xml',
188 outputPath: '.',
189 passThreshold: 100,
190 reportFileName: 'RobotLogs/*/report*.html',
191 unstableThreshold: 0]);
192 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz'
193 }
194 }
195}