blob: 17cb701de6d2c69c446dce0c80375b7de28170f3 [file] [log] [blame]
Suchitra Vemurif4461652020-09-03 21:47:19 -07001// 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
Hardik Windlass5e7230e2021-07-22 04:08:42 +000015library identifier: 'cord-jenkins-libraries@master',
16 retriever: modernSCM([
17 $class: 'GitSCMSource',
18 remote: 'https://gerrit.opencord.org/ci-management.git'
19])
20
Suchitra Vemurif4461652020-09-03 21:47:19 -070021node {
22 // Need this so that deployment_config has global scope when it's read later
23 deployment_config = null
24}
25
Hardik Windlass5cfb29a2021-08-10 09:39:29 +000026def volthaNamespace = "voltha"
Hardik Windlass806505d2021-10-27 08:15:48 +000027def infraNamespace = "infra"
Hardik Windlass5cfb29a2021-08-10 09:39:29 +000028
Suchitra Vemurif4461652020-09-03 21:47:19 -070029pipeline {
30 /* no label, executor is determined by JJB */
31 agent {
32 label "${params.buildNode}"
33 }
34 options {
Hardik Windlassd0f01662021-09-03 08:07:15 +000035 timeout(time: "${timeout}", unit: 'MINUTES')
Suchitra Vemurif4461652020-09-03 21:47:19 -070036 }
37
38 environment {
39 KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf"
40 VOLTCONFIG="$HOME/.volt/config-minimal"
Matteo Scandolo35ac7822021-10-28 18:08:54 -070041 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Suchitra Vemurif4461652020-09-03 21:47:19 -070042 }
43
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080044
Suchitra Vemurif4461652020-09-03 21:47:19 -070045 stages {
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080046 stage('Clone voltha-system-tests') {
47 steps {
Hardik Windlass13d8e952021-07-20 09:16:46 +000048 step([$class: 'WsCleanup'])
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080049 checkout([
50 $class: 'GitSCM',
51 userRemoteConfigs: [[
52 url: "https://gerrit.opencord.org/voltha-system-tests",
53 refspec: "${volthaSystemTestsChange}"
54 ]],
55 branches: [[ name: "${branch}", ]],
56 extensions: [
57 [$class: 'WipeWorkspace'],
58 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
59 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
60 ],
61 ])
Suchitra Vemurif4461652020-09-03 21:47:19 -070062 script {
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080063 sh(script:"""
64 if [ '${volthaSystemTestsChange}' != '' ] ; then
65 cd $WORKSPACE/voltha-system-tests;
66 git fetch https://gerrit.opencord.org/voltha-system-tests ${volthaSystemTestsChange} && git checkout FETCH_HEAD
67 fi
68 """)
Suchitra Vemurif4461652020-09-03 21:47:19 -070069 }
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080070 }
71 }
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080072 // This checkout allows us to show changes in Jenkins
73 // we only do this on master as we don't branch all the repos for all the releases
74 // (we should compute the difference by tracking the container version, not the code)
75 stage('Download All the VOLTHA repos') {
76 when {
77 expression {
78 return "${branch}" == 'master';
79 }
80 }
81 steps {
82 checkout(changelog: true,
83 poll: false,
84 scm: [$class: 'RepoScm',
85 manifestRepositoryUrl: "${params.manifestUrl}",
86 manifestBranch: "${params.branch}",
87 currentBranch: true,
88 destinationDir: 'voltha',
89 forceSync: true,
90 resetFirst: true,
91 quiet: true,
92 jobs: 4,
93 showAllChanges: true]
94 )
95 }
96 }
97 stage ('Initialize') {
98 steps {
Hardik Windlass6f854a12021-07-12 13:20:21 +000099 sh returnStdout: false, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
Suchitra Vemurief0a6e92021-02-23 21:14:07 -0800100 script {
101 deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
102 }
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700103 installVoltctl("${branch}")
Suchitra Vemurif4461652020-09-03 21:47:19 -0700104 sh returnStdout: false, script: """
Suchitra Vemurif4461652020-09-03 21:47:19 -0700105 mkdir -p $WORKSPACE/bin
Hardik Windlass9658cd22021-10-25 11:13:25 +0000106 # download kail
Suchitra Vemurif4461652020-09-03 21:47:19 -0700107 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700108
109 if [ "${params.branch}" == "master" ]; then
110 # Default kind-voltha config doesn't work on ONF demo pod for accessing kvstore.
111 # The issue is that the mgmt node is also one of the k8s nodes and so port forwarding doesn't work.
112 # We should change this. In the meantime here is a workaround.
113 set +e
114
115 # Remove noise from voltha-core logs
116 voltctl log level set WARN read-write-core#github.com/opencord/voltha-go/db/model
117 voltctl log level set WARN read-write-core#github.com/opencord/voltha-lib-go/v3/pkg/kafka
118 # Remove noise from openolt logs
119 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/db
120 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/probe
121 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/kafka
122 fi
123 """
124 }
125 }
126
127 stage('Functional Tests') {
128 environment {
129 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700130 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700131 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FunctionalTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700132 }
133 steps {
134 sh """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000135 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"&
136 ps aux | grep port-forward
Suchitra Vemurif4461652020-09-03 21:47:19 -0700137 mkdir -p $ROBOT_LOGS_DIR
138 if [ "${params.testType}" == "Functional" ]; then
139 if ( ${powerSwitch} ); then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000140 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 -0700141 else
Hardik Windlassc6eae662021-05-19 11:58:23 +0000142 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 -0700143 fi
Hardik Windlass806505d2021-10-27 08:15:48 +0000144 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800145 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700146 fi
147 """
148 }
149 }
150
151 stage('Failure/Recovery Tests') {
152 environment {
153 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700154 ROBOT_FILE="Voltha_DT_FailureScenarios.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700155 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FailureScenarios"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700156 }
157 steps {
158 sh """
159 mkdir -p $ROBOT_LOGS_DIR
160 if [ "${params.testType}" == "Failure" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000161 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 +0000162 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800163 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700164 fi
165 """
166 }
167 }
168
169 stage('Dataplane Tests') {
170 environment {
171 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700172 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700173 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/DataplaneTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700174 }
175 steps {
176 sh """
177 mkdir -p $ROBOT_LOGS_DIR
Suchitra Vemuri60603032020-09-10 17:13:37 -0700178 if [ "${params.testType}" == "Dataplane" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000179 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 +0000180 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800181 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700182 fi
183 """
184 }
185 }
186
187 }
188 post {
189 always {
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700190 getPodsInfo("$WORKSPACE/pods")
Suchitra Vemurif4461652020-09-03 21:47:19 -0700191 sh returnStdout: false, script: '''
192 set +e
Suchitra Vemurif4461652020-09-03 21:47:19 -0700193
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700194 # collect logs collected in the Robot Framework StartLogging keyword
Suchitra Vemurif4461652020-09-03 21:47:19 -0700195 cd $WORKSPACE
196 gzip *-combined.log || true
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700197 rm *-combined.log || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700198
199 # collect ETCD cluster logs
200 mkdir -p $WORKSPACE/etcd
Girish Gowdra3eb96f62020-10-15 12:48:34 -0700201 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 -0700202 '''
203 script {
204 deployment_config.olts.each { olt ->
205 sh returnStdout: false, script: """
206 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
207 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt-${olt.sship}.log # Remove escape sequences
208 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
209 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/dev_mgmt_daemon-${olt.sship}.log # Remove escape sequences
210 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
211 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/startup-${olt.sship}.log || true # Remove escape sequences
212 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
213 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt_process_watchdog-${olt.sship}.log || true # Remove escape sequences
214 """
215 }
216 }
217 step([$class: 'RobotPublisher',
218 disableArchiveOutput: false,
219 logFileName: '**/log*.html',
220 otherFiles: '',
221 outputFileName: '**/output*.xml',
222 outputPath: 'RobotLogs',
223 passThreshold: 100,
224 reportFileName: '**/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200225 unstableThreshold: 0,
226 onlyCritical: true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700227 ]);
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000228 // get cpu usage by container
Hardik Windlass48e75f92021-08-11 22:11:33 +0530229 sh """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000230 mkdir -p $WORKSPACE/plots || true
231 cd $WORKSPACE/voltha-system-tests
232 source ./vst_venv/bin/activate || true
233 sleep 60 # we have to wait for prometheus to collect all the information
Hardik Windlassb9dfd082021-08-19 04:41:14 +0000234 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 +0530235 """
Hardik Windlass5cfb29a2021-08-10 09:39:29 +0000236 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.tgz,*.txt,pods/*.txt,plots/*'
Suchitra Vemurif4461652020-09-03 21:47:19 -0700237 }
Suchitra Vemurif4461652020-09-03 21:47:19 -0700238 }
239}