blob: 6027cf53c65975dc0d48e135c5359976c7893d10 [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
38 volthaDeploy([workflow: name, extraHelmFlags: extraHelmFlags])
39 // start logging
40 sh """
41 mkdir -p $WORKSPACE/${name}
42 _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log &
43 """
44 // forward ONOS and VOLTHA ports
45 sh """
46 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101&
47 _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181&
48 _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555&
49 """
50 }
51 stage('Test VOLTHA - '+ name + ' workflow') {
52 sh """
53 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow"
54 mkdir -p \$ROBOT_LOGS_DIR
55 export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch"
56
57 # By default, all tests tagged 'sanity' are run. This covers basic functionality
58 # like running through the ATT workflow for a single subscriber.
59 export TARGET=sanity-kind-${name}
60
61 # If the Gerrit comment contains a line with "functional tests" then run the full
62 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
63 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
64 REGEX="functional tests"
65 if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
66 export TARGET=functional-single-kind-${name}
67 fi
68
Hardik Windlass64486132021-02-02 13:35:22 +000069 if [[ "${gerritProject}" == "bbsim" ]]; then
70 echo "Running BBSim specific Tests"
71 export TARGET=sanity-bbsim-${name}
72 fi
73
Matteo Scandolo42f6e572021-01-25 15:11:34 -080074 export VOLTCONFIG=$HOME/.volt/config
75 export KUBECONFIG=$HOME/.kube/config
76
77 # Run the specified tests
78 make -C $WORKSPACE/voltha-system-tests \$TARGET || true
79 """
80 // stop logging
81 sh """
82 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
83 if [ -n "\$P_IDS" ]; then
84 echo \$P_IDS
85 for P_ID in \$P_IDS; do
86 kill -9 \$P_ID
87 done
88 fi
89 """
90 // remove port-forwarding
91 sh """
92 # remove orphaned port-forward from different namespaces
93 ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9
94 """
95 // collect pod details
96 sh """
97 kubectl get pods --all-namespaces -o wide > \$WORKSPACE/${name}/pods.txt || true
98 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee \$WORKSPACE/att/pod-images.txt || true
99 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee \$WORKSPACE/att/pod-imagesId.txt || true
100 """
101 helmTeardown(['infra', 'voltha'])
102 }
103}
104
105pipeline {
106
107 /* no label, executor is determined by JJB */
108 agent {
109 label "${params.buildNode}"
110 }
111 options {
Matteo Scandolobd176d72021-02-03 10:55:25 -0800112 timeout(time: 30, unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800113 }
114 environment {
115 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
116 KUBECONFIG="$HOME/.kube/kind-config-${clusterName}"
117 }
118
119 stages{
120 stage('Download Code') {
121 steps {
122 getVolthaCode([
123 branch: "${branch}",
124 gerritProject: "${gerritProject}",
125 gerritRefspec: "${gerritRefspec}",
126 volthaSystemTestsChange: "${volthaSystemTestsChange}",
127 volthaHelmChartsChange: "${volthaHelmChartsChange}",
128 ])
129 }
130 }
131 stage('Build patch') {
132 steps {
133 // NOTE that the correct patch has already been checked out
134 // during the getVolthaCode step
135 buildVolthaComponent("${gerritProject}")
136 }
137 }
138 stage('Create K8s Cluster') {
139 steps {
140 createKubernetesCluster([nodes: 3])
141 }
142 }
143 stage('Load image in kind nodes') {
144 steps {
145 loadToKind()
146 }
147 }
148 stage('Run Test') {
149 steps {
150 test_workflow("att")
151 test_workflow("dt")
152 test_workflow("tt")
153 }
154 }
155 }
156
157 post {
158 always {
159 sh '''
160 gzip $WORKSPACE/att/onos-voltha-combined.log || true
161 gzip $WORKSPACE/dt/onos-voltha-combined.log || true
162 gzip $WORKSPACE/tt/onos-voltha-combined.log || true
163 '''
164 step([$class: 'RobotPublisher',
165 disableArchiveOutput: false,
166 logFileName: 'RobotLogs/*/log*.html',
167 otherFiles: '',
168 outputFileName: 'RobotLogs/*/output*.xml',
169 outputPath: '.',
170 passThreshold: 100,
171 reportFileName: 'RobotLogs/*/report*.html',
172 unstableThreshold: 0]);
173 archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz'
174 }
175 }
176}