blob: d795813ba8359ba6b305ca056a88282681514c9d [file] [log] [blame]
Joey Armstrong16bd8e82023-01-12 15:20:06 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
3// Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Suchitra Vemurif4461652020-09-03 21:47:19 -07004//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
Joey Armstrong16bd8e82023-01-12 15:20:06 -050016// -----------------------------------------------------------------------
Suchitra Vemurif4461652020-09-03 21:47:19 -070017
Hardik Windlass5e7230e2021-07-22 04:08:42 +000018library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
Suchitra Vemurif4461652020-09-03 21:47:19 -070024node {
25 // Need this so that deployment_config has global scope when it's read later
26 deployment_config = null
27}
28
Hardik Windlass5cfb29a2021-08-10 09:39:29 +000029def volthaNamespace = "voltha"
Hardik Windlass806505d2021-10-27 08:15:48 +000030def infraNamespace = "infra"
Hardik Windlass5cfb29a2021-08-10 09:39:29 +000031
Suchitra Vemurif4461652020-09-03 21:47:19 -070032pipeline {
33 /* no label, executor is determined by JJB */
34 agent {
35 label "${params.buildNode}"
36 }
37 options {
Hardik Windlassd0f01662021-09-03 08:07:15 +000038 timeout(time: "${timeout}", unit: 'MINUTES')
Suchitra Vemurif4461652020-09-03 21:47:19 -070039 }
40
41 environment {
42 KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf"
43 VOLTCONFIG="$HOME/.volt/config-minimal"
Matteo Scandolo35ac7822021-10-28 18:08:54 -070044 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Suchitra Vemurif4461652020-09-03 21:47:19 -070045 }
46
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080047
Suchitra Vemurif4461652020-09-03 21:47:19 -070048 stages {
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080049 stage('Clone voltha-system-tests') {
50 steps {
Hardik Windlass13d8e952021-07-20 09:16:46 +000051 step([$class: 'WsCleanup'])
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080052 checkout([
53 $class: 'GitSCM',
54 userRemoteConfigs: [[
55 url: "https://gerrit.opencord.org/voltha-system-tests",
56 refspec: "${volthaSystemTestsChange}"
57 ]],
58 branches: [[ name: "${branch}", ]],
59 extensions: [
60 [$class: 'WipeWorkspace'],
61 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
62 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
63 ],
64 ])
Suchitra Vemurif4461652020-09-03 21:47:19 -070065 script {
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080066 sh(script:"""
67 if [ '${volthaSystemTestsChange}' != '' ] ; then
68 cd $WORKSPACE/voltha-system-tests;
69 git fetch https://gerrit.opencord.org/voltha-system-tests ${volthaSystemTestsChange} && git checkout FETCH_HEAD
70 fi
71 """)
Suchitra Vemurif4461652020-09-03 21:47:19 -070072 }
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080073 }
74 }
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080075 // This checkout allows us to show changes in Jenkins
76 // we only do this on master as we don't branch all the repos for all the releases
77 // (we should compute the difference by tracking the container version, not the code)
78 stage('Download All the VOLTHA repos') {
79 when {
80 expression {
81 return "${branch}" == 'master';
82 }
83 }
84 steps {
85 checkout(changelog: true,
86 poll: false,
87 scm: [$class: 'RepoScm',
88 manifestRepositoryUrl: "${params.manifestUrl}",
89 manifestBranch: "${params.branch}",
90 currentBranch: true,
91 destinationDir: 'voltha',
92 forceSync: true,
93 resetFirst: true,
94 quiet: true,
95 jobs: 4,
96 showAllChanges: true]
97 )
98 }
99 }
100 stage ('Initialize') {
101 steps {
Hardik Windlass6f854a12021-07-12 13:20:21 +0000102 sh returnStdout: false, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
Suchitra Vemurief0a6e92021-02-23 21:14:07 -0800103 script {
104 deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
105 }
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700106 installVoltctl("${branch}")
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500107
108 sh(returnStdout: false, script: """
109 mkdir -p "$WORKSPACE/bin"
110
111 # install kail
112 make -C "$WORKSPACE/voltha-system-tests" KAIL_PATH="$WORKSPACE/bin" kail
Suchitra Vemurif4461652020-09-03 21:47:19 -0700113
114 if [ "${params.branch}" == "master" ]; then
115 # Default kind-voltha config doesn't work on ONF demo pod for accessing kvstore.
116 # The issue is that the mgmt node is also one of the k8s nodes and so port forwarding doesn't work.
117 # We should change this. In the meantime here is a workaround.
118 set +e
119
120 # Remove noise from voltha-core logs
121 voltctl log level set WARN read-write-core#github.com/opencord/voltha-go/db/model
122 voltctl log level set WARN read-write-core#github.com/opencord/voltha-lib-go/v3/pkg/kafka
123 # Remove noise from openolt logs
124 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/db
125 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/probe
126 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/kafka
127 fi
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500128 """)
Suchitra Vemurif4461652020-09-03 21:47:19 -0700129 }
130 }
131
132 stage('Functional Tests') {
133 environment {
134 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700135 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700136 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FunctionalTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700137 }
138 steps {
139 sh """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000140 JENKINS_NODE_COOKIE="dontKillMe" _TAG="prometheus" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n cattle-prometheus svc/access-prometheus 31301:80; done"&
141 ps aux | grep port-forward
Suchitra Vemurif4461652020-09-03 21:47:19 -0700142 mkdir -p $ROBOT_LOGS_DIR
143 if [ "${params.testType}" == "Functional" ]; then
144 if ( ${powerSwitch} ); then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000145 export ROBOT_MISC_ARGS="--removekeywords wuks -i PowerSwitch -i soak -e dataplaneDt -e bbsim -e notready -d $ROBOT_LOGS_DIR -v SOAK_TEST:True -v logging:False -v teardown_device:False -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700146 else
Hardik Windlassc6eae662021-05-19 11:58:23 +0000147 export ROBOT_MISC_ARGS="--removekeywords wuks -e PowerSwitch -i soak -e dataplaneDt -e bbsim -e notready -d $ROBOT_LOGS_DIR -v SOAK_TEST:True -v logging:False -v teardown_device:False -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700148 fi
Hardik Windlass806505d2021-10-27 08:15:48 +0000149 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800150 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700151 fi
152 """
153 }
154 }
155
156 stage('Failure/Recovery Tests') {
157 environment {
158 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700159 ROBOT_FILE="Voltha_DT_FailureScenarios.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700160 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FailureScenarios"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700161 }
162 steps {
163 sh """
164 mkdir -p $ROBOT_LOGS_DIR
165 if [ "${params.testType}" == "Failure" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000166 export ROBOT_MISC_ARGS="--removekeywords wuks -L TRACE -i soak -e PowerSwitch -e bbsim -e notready -d $ROBOT_LOGS_DIR -v SOAK_TEST:True -v logging:False -v teardown_device:False -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE"
Hardik Windlass806505d2021-10-27 08:15:48 +0000167 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800168 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700169 fi
170 """
171 }
172 }
173
174 stage('Dataplane Tests') {
175 environment {
176 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700177 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700178 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/DataplaneTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700179 }
180 steps {
181 sh """
182 mkdir -p $ROBOT_LOGS_DIR
Suchitra Vemuri60603032020-09-10 17:13:37 -0700183 if [ "${params.testType}" == "Dataplane" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000184 export ROBOT_MISC_ARGS="--removekeywords wuks -i soakDataplane -e bbsim -e notready -d $ROBOT_LOGS_DIR -v SOAK_TEST:True -v logging:False -v teardown_device:False -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE"
Hardik Windlass806505d2021-10-27 08:15:48 +0000185 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800186 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700187 fi
188 """
189 }
190 }
191
192 }
193 post {
194 always {
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700195 getPodsInfo("$WORKSPACE/pods")
Suchitra Vemurif4461652020-09-03 21:47:19 -0700196 sh returnStdout: false, script: '''
197 set +e
Suchitra Vemurif4461652020-09-03 21:47:19 -0700198
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700199 # collect logs collected in the Robot Framework StartLogging keyword
Suchitra Vemurif4461652020-09-03 21:47:19 -0700200 cd $WORKSPACE
201 gzip *-combined.log || true
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700202 rm *-combined.log || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700203
204 # collect ETCD cluster logs
205 mkdir -p $WORKSPACE/etcd
Girish Gowdra3eb96f62020-10-15 12:48:34 -0700206 printf '%s\n' $(kubectl get pods -l app=etcd -o=jsonpath="{.items[*]['metadata.name']}") | xargs -I% bash -c "kubectl logs % > $WORKSPACE/etcd/%.log"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700207 '''
208 script {
209 deployment_config.olts.each { olt ->
210 sh returnStdout: false, script: """
211 sshpass -p ${olt.pass} scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${olt.user}@${olt.sship}:/var/log/openolt.log $WORKSPACE/openolt-${olt.sship}.log || true
212 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt-${olt.sship}.log # Remove escape sequences
213 sshpass -p ${olt.pass} scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${olt.user}@${olt.sship}:/var/log/dev_mgmt_daemon.log $WORKSPACE/dev_mgmt_daemon-${olt.sship}.log || true
214 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/dev_mgmt_daemon-${olt.sship}.log # Remove escape sequences
215 sshpass -p ${olt.pass} scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${olt.user}@${olt.sship}:/var/log/startup.log $WORKSPACE/startup-${olt.sship}.log || true
216 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/startup-${olt.sship}.log || true # Remove escape sequences
217 sshpass -p ${olt.pass} scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${olt.user}@${olt.sship}:/var/log/openolt_process_watchdog.log $WORKSPACE/openolt_process_watchdog-${olt.sship}.log || true
218 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt_process_watchdog-${olt.sship}.log || true # Remove escape sequences
219 """
220 }
221 }
222 step([$class: 'RobotPublisher',
223 disableArchiveOutput: false,
224 logFileName: '**/log*.html',
225 otherFiles: '',
226 outputFileName: '**/output*.xml',
227 outputPath: 'RobotLogs',
228 passThreshold: 100,
229 reportFileName: '**/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200230 unstableThreshold: 0,
231 onlyCritical: true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700232 ]);
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000233 // get cpu usage by container
Hardik Windlass48e75f92021-08-11 22:11:33 +0530234 sh """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000235 mkdir -p $WORKSPACE/plots || true
236 cd $WORKSPACE/voltha-system-tests
237 source ./vst_venv/bin/activate || true
238 sleep 60 # we have to wait for prometheus to collect all the information
Hardik Windlassb9dfd082021-08-19 04:41:14 +0000239 python scripts/sizing.py -o $WORKSPACE/plots -a 0.0.0.0:31301 -n ${volthaNamespace} -s 3600 || true
Hardik Windlass48e75f92021-08-11 22:11:33 +0530240 """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000241 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.tgz,*.txt,pods/*.txt,plots/*'
Suchitra Vemurif4461652020-09-03 21:47:19 -0700242 }
Suchitra Vemurif4461652020-09-03 21:47:19 -0700243 }
244}
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500245
246// [EOF]