blob: 5918e4d70a6f030167f13b13c5f1dcbf8c5beb11 [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
26pipeline {
27 /* no label, executor is determined by JJB */
28 agent {
29 label "${params.buildNode}"
30 }
31 options {
32 timeout(time: 280, unit: 'MINUTES')
33 }
34
35 environment {
36 KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf"
37 VOLTCONFIG="$HOME/.volt/config-minimal"
38 PATH="$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
39 }
40
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080041
Suchitra Vemurif4461652020-09-03 21:47:19 -070042 stages {
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080043 stage('Clone voltha-system-tests') {
44 steps {
Hardik Windlass13d8e952021-07-20 09:16:46 +000045 step([$class: 'WsCleanup'])
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080046 checkout([
47 $class: 'GitSCM',
48 userRemoteConfigs: [[
49 url: "https://gerrit.opencord.org/voltha-system-tests",
50 refspec: "${volthaSystemTestsChange}"
51 ]],
52 branches: [[ name: "${branch}", ]],
53 extensions: [
54 [$class: 'WipeWorkspace'],
55 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
56 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
57 ],
58 ])
Suchitra Vemurif4461652020-09-03 21:47:19 -070059 script {
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080060 sh(script:"""
61 if [ '${volthaSystemTestsChange}' != '' ] ; then
62 cd $WORKSPACE/voltha-system-tests;
63 git fetch https://gerrit.opencord.org/voltha-system-tests ${volthaSystemTestsChange} && git checkout FETCH_HEAD
64 fi
65 """)
Suchitra Vemurif4461652020-09-03 21:47:19 -070066 }
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080067 }
68 }
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080069 // This checkout allows us to show changes in Jenkins
70 // we only do this on master as we don't branch all the repos for all the releases
71 // (we should compute the difference by tracking the container version, not the code)
72 stage('Download All the VOLTHA repos') {
73 when {
74 expression {
75 return "${branch}" == 'master';
76 }
77 }
78 steps {
79 checkout(changelog: true,
80 poll: false,
81 scm: [$class: 'RepoScm',
82 manifestRepositoryUrl: "${params.manifestUrl}",
83 manifestBranch: "${params.branch}",
84 currentBranch: true,
85 destinationDir: 'voltha',
86 forceSync: true,
87 resetFirst: true,
88 quiet: true,
89 jobs: 4,
90 showAllChanges: true]
91 )
92 }
93 }
94 stage ('Initialize') {
95 steps {
Hardik Windlass6f854a12021-07-12 13:20:21 +000096 sh returnStdout: false, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
Suchitra Vemurief0a6e92021-02-23 21:14:07 -080097 script {
98 deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
99 }
Suchitra Vemurif4461652020-09-03 21:47:19 -0700100 sh returnStdout: false, script: """
Suchitra Vemurif4461652020-09-03 21:47:19 -0700101 mkdir -p $WORKSPACE/bin
102 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
103 cd $WORKSPACE
Hardik Windlass6f854a12021-07-12 13:20:21 +0000104 if [ "${params.branch}" == "voltha-2.8" ]; then
Hardik Windlasse2175102021-07-23 08:34:32 +0000105 VC_VERSION=1.6.11
Suchitra Vemurif4461652020-09-03 21:47:19 -0700106 else
107 VC_VERSION=\$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
108 fi
109
110 HOSTOS=\$(uname -s | tr "[:upper:]" "[:lower:"])
111 HOSTARCH=\$(uname -m | tr "[:upper:]" "[:lower:"])
112 if [ \$HOSTARCH == "x86_64" ]; then
113 HOSTARCH="amd64"
114 fi
115 curl -o $WORKSPACE/bin/voltctl -sSL https://github.com/opencord/voltctl/releases/download/v\${VC_VERSION}/voltctl-\${VC_VERSION}-\${HOSTOS}-\${HOSTARCH}
116 chmod 755 $WORKSPACE/bin/voltctl
117 voltctl version --clientonly
118
119 if [ "${params.branch}" == "master" ]; then
120 # Default kind-voltha config doesn't work on ONF demo pod for accessing kvstore.
121 # The issue is that the mgmt node is also one of the k8s nodes and so port forwarding doesn't work.
122 # We should change this. In the meantime here is a workaround.
123 set +e
124
125 # Remove noise from voltha-core logs
126 voltctl log level set WARN read-write-core#github.com/opencord/voltha-go/db/model
127 voltctl log level set WARN read-write-core#github.com/opencord/voltha-lib-go/v3/pkg/kafka
128 # Remove noise from openolt logs
129 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/db
130 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/probe
131 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/kafka
132 fi
133 """
134 }
135 }
136
137 stage('Functional Tests') {
138 environment {
139 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700140 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700141 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FunctionalTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700142 }
143 steps {
144 sh """
Suchitra Vemurif4461652020-09-03 21:47:19 -0700145 mkdir -p $ROBOT_LOGS_DIR
146 if [ "${params.testType}" == "Functional" ]; then
147 if ( ${powerSwitch} ); then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000148 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 -0700149 else
Hardik Windlassc6eae662021-05-19 11:58:23 +0000150 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 -0700151 fi
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800152 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700153 fi
154 """
155 }
156 }
157
158 stage('Failure/Recovery Tests') {
159 environment {
160 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700161 ROBOT_FILE="Voltha_DT_FailureScenarios.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700162 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FailureScenarios"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700163 }
164 steps {
165 sh """
166 mkdir -p $ROBOT_LOGS_DIR
167 if [ "${params.testType}" == "Failure" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000168 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"
Suchitra Vemuri0287e9b2021-02-25 11:17:32 -0800169 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
Suchitra Vemurif4461652020-09-03 21:47:19 -0700170 fi
171 """
172 }
173 }
174
175 stage('Dataplane Tests') {
176 environment {
177 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
Suchitra Vemuri4d944e92020-09-03 22:50:44 -0700178 ROBOT_FILE="Voltha_DT_PODTests.robot"
Suchitra Vemuri07ceef32020-09-03 23:19:09 -0700179 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/DataplaneTests"
Suchitra Vemurif4461652020-09-03 21:47:19 -0700180 }
181 steps {
182 sh """
183 mkdir -p $ROBOT_LOGS_DIR
Suchitra Vemuri60603032020-09-10 17:13:37 -0700184 if [ "${params.testType}" == "Dataplane" ]; then
Hardik Windlassc6eae662021-05-19 11:58:23 +0000185 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"
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 ]);
Matteo Scandolo5e7bd1d2021-07-16 13:29:42 -0700233 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.tgz,*.txt,pods/*.txt'
Suchitra Vemurif4461652020-09-03 21:47:19 -0700234 }
Suchitra Vemurif4461652020-09-03 21:47:19 -0700235 }
236}