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