blob: 6320cfb4b615ea8e3634c813c684c7738ef59cc5 [file] [log] [blame]
Joey Armstrong7adbfb02023-01-24 17:02:37 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
3// Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
4//
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.
16// -----------------------------------------------------------------------
17
18library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
24node {
25 // Need this so that deployment_config has global scope when it's read later
26 deployment_config = null
27}
28
29def volthaNamespace = "voltha"
30def infraNamespace = "infra"
31
32pipeline {
33 /* no label, executor is determined by JJB */
34 agent {
35 label "${params.buildNode}"
36 }
37 options {
38 timeout(time: "${timeout}", unit: 'MINUTES')
39 }
40
41 environment {
42 KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf"
43 VOLTCONFIG="$HOME/.volt/config-minimal"
44 PATH="$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
45 }
46
47
48 stages {
49 stage('Clone voltha-system-tests') {
50 steps {
51 step([$class: 'WsCleanup'])
52 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 ])
65 script {
66 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 """)
72 }
73 }
74 }
75 // 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 {
102 sh returnStdout: false, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
103 script {
104 deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
105 }
106 installVoltctl("${branch}")
107
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
114
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
129 """)
130
131 sh("""
132 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
138 """)
139 }
140 }
141
142 stage('Functional Tests') {
143 environment {
144 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
145 ROBOT_FILE="Voltha_DT_PODTests.robot"
146 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FunctionalTests"
147 }
148 steps {
149 sh """
150 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
152 mkdir -p $ROBOT_LOGS_DIR
153 if [ "${params.testType}" == "Functional" ]; then
154 if ( ${powerSwitch} ); then
155 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"
156 else
157 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"
158 fi
159 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
160 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
161 fi
162 """
163 }
164 }
165
166 stage('Failure/Recovery Tests') {
167 environment {
168 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
169 ROBOT_FILE="Voltha_DT_FailureScenarios.robot"
170 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/FailureScenarios"
171 }
172 steps {
173 sh """
174 mkdir -p $ROBOT_LOGS_DIR
175 if [ "${params.testType}" == "Failure" ]; then
176 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"
177 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
178 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
179 fi
180 """
181 }
182 }
183
184 stage('Dataplane Tests') {
185 environment {
186 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}-DT.yaml"
187 ROBOT_FILE="Voltha_DT_PODTests.robot"
188 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/dt-workflow/DataplaneTests"
189 }
190 steps {
191 sh """
192 mkdir -p $ROBOT_LOGS_DIR
193 if [ "${params.testType}" == "Dataplane" ]; then
194 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"
195 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
196 make -C $WORKSPACE/voltha-system-tests voltha-dt-test || true
197 fi
198 """
199 }
200 }
201
202 }
203 post {
204 always {
205 getPodsInfo("$WORKSPACE/pods")
206 sh returnStdout: false, script: '''
207 set +e
208
209 # collect logs collected in the Robot Framework StartLogging keyword
210 cd $WORKSPACE
211 gzip *-combined.log || true
212 rm *-combined.log || true
213
214 # collect ETCD cluster logs
215 mkdir -p $WORKSPACE/etcd
216 printf '%s\n' $(kubectl get pods -l app=etcd -o=jsonpath="{.items[*]['metadata.name']}") | xargs -I% bash -c "kubectl logs % > $WORKSPACE/etcd/%.log"
217 '''
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',
240 unstableThreshold: 0,
241 onlyCritical: true
242 ]);
243 // get cpu usage by container
244 sh """
245 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
249 python scripts/sizing.py -o $WORKSPACE/plots -a 0.0.0.0:31301 -n ${volthaNamespace} -s 3600 || true
250 # 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
252 """
253 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.tgz,*.txt,pods/*.txt,plots/*,voltha-pods-mem-consumption/*'
254 }
255 }
256}
257
258// [EOF]