blob: 6420a8158d59c70e916d85740ce2315ca489f23e [file] [log] [blame]
Joey Armstrong16bd8e82023-01-12 15:20:06 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrong518f3572024-02-11 07:56:25 -05003// Copyright 2017-2024 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 Windlass7e4e3152021-09-29 06:42:05 +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"
Jan Klarece1bc812023-09-28 13:15:52 +020043 VOLTCONFIG="$HOME/.volt/config"
Suchitra Vemurif4461652020-09-03 21:47:19 -070044 PATH="$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
45 }
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 }
Hardik Windlass9658cd22021-10-25 11:13:25 +0000106 installVoltctl("${branch}")
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500107
108 sh(returnStdout: false, script: """
109
110 mkdir -p "$WORKSPACE/bin"
111
112 # install kail
113 make -C "$WORKSPACE/voltha-system-tests" KAIL_PATH="$WORKSPACE/bin" kail
Suchitra Vemurif4461652020-09-03 21:47:19 -0700114
115 if [ "${params.branch}" == "master" ]; then
116 # Default kind-voltha config doesn't work on ONF demo pod for accessing kvstore.
117 # The issue is that the mgmt node is also one of the k8s nodes and so port forwarding doesn't work.
118 # We should change this. In the meantime here is a workaround.
119 set +e
120
121 # Remove noise from voltha-core logs
122 voltctl log level set WARN read-write-core#github.com/opencord/voltha-go/db/model
123 voltctl log level set WARN read-write-core#github.com/opencord/voltha-lib-go/v3/pkg/kafka
124 # Remove noise from openolt logs
125 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/db
126 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/probe
127 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/kafka
128 fi
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500129 """)
130
131 sh("""
Girish Gowdra15f62dd2022-02-07 16:38:18 -0800132 mkdir -p $WORKSPACE/voltha-pods-mem-consumption
133 cd $WORKSPACE/voltha-system-tests
134 make vst_venv
135 source ./vst_venv/bin/activate || true
136 # Collect initial memory consumption
137 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption -a 0.0.0.0:31301 -n ${volthaNamespace} || true
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500138 """)
Suchitra Vemurif4461652020-09-03 21:47:19 -0700139 }
140 }
141
142 stage('Functional Tests') {
143 environment {
144 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700145 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700146 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FunctionalTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700147 }
148 steps {
149 sh """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000150 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"&
151 ps aux | grep port-forward
Suchitra Vemurif4461652020-09-03 21:47:19 -0700152 mkdir -p $ROBOT_LOGS_DIR
153 if [ "${params.testType}" == "Functional" ]; then
154 if ( ${powerSwitch} ); then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000155 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 -0700156 else
Hardik Windlassc6eae662021-05-19 11:58:23 +0000157 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 -0700158 fi
Hardik Windlass7e4e3152021-09-29 06:42:05 +0000159 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800160 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700161 fi
162 """
163 }
164 }
165
166 stage('Failure/Recovery Tests') {
167 environment {
168 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700169 ROBOT_FILE="Voltha_DT_FailureScenarios.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700170 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FailureScenarios"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700171 }
172 steps {
173 sh """
174 mkdir -p $ROBOT_LOGS_DIR
175 if [ "${params.testType}" == "Failure" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000176 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 Windlass7e4e3152021-09-29 06:42:05 +0000177 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800178 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700179 fi
180 """
181 }
182 }
183
184 stage('Dataplane Tests') {
185 environment {
186 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700187 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700188 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/DataplaneTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700189 }
190 steps {
191 sh """
192 mkdir -p $ROBOT_LOGS_DIR
Suchitra Vemuri60603032020-09-10 17:13:37 -0700193 if [ "${params.testType}" == "Dataplane" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000194 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 Windlass7e4e3152021-09-29 06:42:05 +0000195 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800196 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700197 fi
198 """
199 }
200 }
201
202 }
203 post {
204 always {
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700205 getPodsInfo("$WORKSPACE/pods")
Suchitra Vemurif4461652020-09-03 21:47:19 -0700206 sh returnStdout: false, script: '''
207 set +e
Suchitra Vemurif4461652020-09-03 21:47:19 -0700208
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700209 # collect logs collected in the Robot Framework StartLogging keyword
Suchitra Vemurif4461652020-09-03 21:47:19 -0700210 cd $WORKSPACE
211 gzip *-combined.log || true
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700212 rm *-combined.log || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700213
214 # collect ETCD cluster logs
215 mkdir -p $WORKSPACE/etcd
Girish Gowdra3eb96f62020-10-15 12:48:34 -0700216 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 -0700217 '''
218 script {
219 deployment_config.olts.each { olt ->
220 sh returnStdout: false, script: """
221 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
222 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt-${olt.sship}.log # Remove escape sequences
223 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
224 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/dev_mgmt_daemon-${olt.sship}.log # Remove escape sequences
225 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
226 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/startup-${olt.sship}.log || true # Remove escape sequences
227 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
228 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt_process_watchdog-${olt.sship}.log || true # Remove escape sequences
229 """
230 }
231 }
232 step([$class: 'RobotPublisher',
233 disableArchiveOutput: false,
234 logFileName: '**/log*.html',
235 otherFiles: '',
236 outputFileName: '**/output*.xml',
237 outputPath: 'RobotLogs',
238 passThreshold: 100,
239 reportFileName: '**/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200240 unstableThreshold: 0,
241 onlyCritical: true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700242 ]);
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000243 // get cpu usage by container
Hardik Windlass48e75f92021-08-11 22:11:33 +0530244 sh """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000245 mkdir -p $WORKSPACE/plots || true
246 cd $WORKSPACE/voltha-system-tests
247 source ./vst_venv/bin/activate || true
248 sleep 60 # we have to wait for prometheus to collect all the information
Hardik Windlassb9dfd082021-08-19 04:41:14 +0000249 python scripts/sizing.py -o $WORKSPACE/plots -a 0.0.0.0:31301 -n ${volthaNamespace} -s 3600 || true
Girish Gowdra15f62dd2022-02-07 16:38:18 -0800250 # Collect memory consumption of voltha pods once all the tests are complete
251 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption -a 0.0.0.0:31301 -n ${volthaNamespace} || true
Hardik Windlass48e75f92021-08-11 22:11:33 +0530252 """
Girish Gowdra15f62dd2022-02-07 16:38:18 -0800253 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.tgz,*.txt,pods/*.txt,plots/*,voltha-pods-mem-consumption/*'
Suchitra Vemurif4461652020-09-03 21:47:19 -0700254 }
Suchitra Vemurif4461652020-09-03 21:47:19 -0700255 }
256}
Joey Armstrong16bd8e82023-01-12 15:20:06 -0500257
258// [EOF]