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