blob: ce625071262d7c8745451600066063d1c351cb40 [file] [log] [blame]
Matteo Scandolo075740f2021-04-22 14:52:29 -07001// Copyright 2021-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 for openonu-go
16// uses bbsim to simulate OLT/ONUs
17
18library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
24def clusterName = "kind-ci"
25
Matteo Scandolo886cb8e2021-05-03 13:37:41 -070026def execute_test(testTarget, workflow, testSpecificHelmFlags = "") {
Matteo Scandolo075740f2021-04-22 14:52:29 -070027 def infraNamespace = "default"
28 def volthaNamespace = "voltha"
29 def robotLogsDir = "RobotLogs"
30 stage('Cleanup') {
31 timeout(15) {
32 script {
33 helmTeardown(["default", infraNamespace, volthaNamespace])
34 }
35 timeout(1) {
36 sh returnStdout: false, script: '''
37 # remove orphaned port-forward from different namespaces
38 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9
39 '''
40 }
Matteo Scandolo075740f2021-04-22 14:52:29 -070041 }
42 }
43 stage('Deploy Voltha') {
44 timeout(20) {
45 script {
46
47 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
48 def localCharts = false
49 if (volthaHelmChartsChange != "") {
50 localCharts = true
51 }
52
53 // NOTE temporary workaround expose ONOS node ports
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070054 def localHelmFlags = extraHelmFlags + " --set global.log_level=DEBUG --set onos-classic.onosSshPort=30115 " +
Matteo Scandolo075740f2021-04-22 14:52:29 -070055 " --set onos-classic.onosApiPort=30120 " +
56 " --set onos-classic.onosOfPort=31653 " +
57 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
58 volthaDeploy([
59 infraNamespace: infraNamespace,
60 volthaNamespace: volthaNamespace,
61 workflow: workflow.toLowerCase(),
62 extraHelmFlags: localHelmFlags,
63 localCharts: localCharts,
64 bbsimReplica: olts.toInteger(),
65 dockerRegistry: "mirror.registry.opennetworking.org"
66 ])
67 }
68 // start logging
69 sh """
Matteo Scandolo886cb8e2021-05-03 13:37:41 -070070 mkdir -p $WORKSPACE/${testTarget}
Matteo Scandoloee626e02021-05-05 08:13:16 -070071 _TAG=kail-${workflow} kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-combined.log &
Matteo Scandolo075740f2021-04-22 14:52:29 -070072 """
73 sh """
74 JENKINS_NODE_COOKIE="dontKillMe" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/voltha-voltha-api 55555:55555; done"&
75 JENKINS_NODE_COOKIE="dontKillMe" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-etcd 2379:2379; done"&
76 JENKINS_NODE_COOKIE="dontKillMe" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-kafka 9092:9092; done"&
77 ps aux | grep port-forward
78 """
Matteo Scandoloee626e02021-05-05 08:13:16 -070079 getPodsInfo("$WORKSPACE/${testTarget}-components")
Matteo Scandolo075740f2021-04-22 14:52:29 -070080 }
81 }
82 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
83 sh """
Matteo Scandoloee626e02021-05-05 08:13:16 -070084 mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot
85 export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot "
Matteo Scandolo075740f2021-04-22 14:52:29 -070086 ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120"
87 export KVSTOREPREFIX=voltha/voltha_voltha
88
89 make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
90 """
Matteo Scandolo2cc5b392021-05-03 09:33:18 -070091 // stop logging
92 sh """
93 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')"
94 if [ -n "\$P_IDS" ]; then
95 echo \$P_IDS
96 for P_ID in \$P_IDS; do
97 kill -9 \$P_ID
98 done
99 fi
100 """
Matteo Scandolo075740f2021-04-22 14:52:29 -0700101 }
102}
103
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700104def collectArtifacts(exitStatus) {
105 getPodsInfo("$WORKSPACE/${exitStatus}")
106 sh """
107 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
108 """
109 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
110 sh '''
111 sync
112 pkill kail || true
113 which voltctl
114 md5sum $(which voltctl)
115 '''
116 step([$class: 'RobotPublisher',
117 disableArchiveOutput: false,
118 logFileName: "RobotLogs/*/log*.html",
119 otherFiles: '',
120 outputFileName: "RobotLogs/*/output*.xml",
121 outputPath: '.',
122 passThreshold: 100,
123 reportFileName: "RobotLogs/*/report*.html",
124 unstableThreshold: 0]);
125}
126
Matteo Scandolo075740f2021-04-22 14:52:29 -0700127pipeline {
128
129 /* no label, executor is determined by JJB */
130 agent {
131 label "${params.buildNode}"
132 }
133 options {
134 timeout(time: 130, unit: 'MINUTES')
135 }
136 environment {
137 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
138 VOLTCONFIG="$HOME/.volt/config"
139 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
140 ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}"
141 DIAGS_PROFILE="VOLTHA_PROFILE"
142 }
143 stages {
144 stage('Download Code') {
145 steps {
146 getVolthaCode([
147 branch: "${branch}",
148 gerritProject: "${gerritProject}",
149 gerritRefspec: "${gerritRefspec}",
150 volthaSystemTestsChange: "${volthaSystemTestsChange}",
151 volthaHelmChartsChange: "${volthaHelmChartsChange}",
152 ])
153 }
154 }
155 stage('Create K8s Cluster') {
156 steps {
157 script {
158 def clusterExists = sh returnStdout: true, script: """
159 kind get clusters | grep ${clusterName} | wc -l
160 """
161 if (clusterExists.trim() == "0") {
162 createKubernetesCluster([nodes: 3, name: clusterName])
163 }
164 }
165 }
166 }
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700167 stage('Parse and execute tests') {
168 steps {
169 script {
170 def tests = readYaml text: testTargets
Matteo Scandolo075740f2021-04-22 14:52:29 -0700171
Matteo Scandolo886cb8e2021-05-03 13:37:41 -0700172 for(int i = 0;i<tests.size();i++) {
173 def test = tests[i]
174 def target = test["target"]
175 def workflow = test["workflow"]
176 def flags = test["flags"]
177 println "Executing test ${target} on workflow ${workflow} with extra flags ${flags}"
178 execute_test(target, workflow, flags)
179 }
180 }
Matteo Scandolo075740f2021-04-22 14:52:29 -0700181 }
Matteo Scandolo075740f2021-04-22 14:52:29 -0700182 }
183 }
184 post {
185 aborted {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700186 collectArtifacts("aborted")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700187 }
188 failure {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700189 collectArtifacts("failed")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700190 }
191 always {
Matteo Scandolo2cc5b392021-05-03 09:33:18 -0700192 collectArtifacts("always")
Matteo Scandolo075740f2021-04-22 14:52:29 -0700193 }
194 }
195}