blob: 762214b7f015f2095c199e7f4f9e14896e740c78 [file] [log] [blame]
Hardik Windlass868475f2021-12-16 16:47:39 +00001// 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
15library identifier: 'cord-jenkins-libraries@master',
16 retriever: modernSCM([
17 $class: 'GitSCMSource',
18 remote: 'https://gerrit.opencord.org/ci-management.git'
19])
20
21def infraNamespace = "infra"
22def volthaNamespace = "voltha"
23
24node {
25 // Need this so that deployment_config has global scope when it's read later
26 deployment_config = null
27}
28
29pipeline {
30 /* no label, executor is determined by JJB */
31 agent {
32 label "${params.buildNode}"
33 }
34 options {
35 timeout(time: "${timeout}", unit: 'MINUTES')
36 }
37
38 environment {
39 KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf"
40 VOLTCONFIG="$HOME/.volt/config-minimal"
41 PATH="$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
42 }
43 stages {
44 stage('Clone voltha-system-tests') {
45 steps {
46 step([$class: 'WsCleanup'])
47 checkout([
48 $class: 'GitSCM',
49 userRemoteConfigs: [[
50 url: "https://gerrit.opencord.org/voltha-system-tests",
51 refspec: "${volthaSystemTestsChange}"
52 ]],
53 branches: [[ name: "${branch}", ]],
54 extensions: [
55 [$class: 'WipeWorkspace'],
56 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
57 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
58 ],
59 ])
60 script {
61 sh(script:"""
62 if [ '${volthaSystemTestsChange}' != '' ] ; then
63 cd $WORKSPACE/voltha-system-tests;
64 git fetch https://gerrit.opencord.org/voltha-system-tests ${volthaSystemTestsChange} && git checkout FETCH_HEAD
65 fi
66 """)
67 }
68 }
69 }
70 stage('Download All the VOLTHA repos') {
71 when {
72 expression {
73 return "${branch}" == 'master';
74 }
75 }
76 steps {
77 checkout(changelog: true,
78 poll: false,
79 scm: [$class: 'RepoScm',
80 manifestRepositoryUrl: "${params.manifestUrl}",
81 manifestBranch: "${params.branch}",
82 currentBranch: true,
83 destinationDir: 'voltha',
84 forceSync: true,
85 resetFirst: true,
86 quiet: true,
87 jobs: 4,
88 showAllChanges: true]
89 )
90 }
91 }
92 stage ('Initialize') {
93 steps {
94 sh returnStdout: false, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
95 script {
96 deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
97 }
98 installVoltctl("${branch}")
99 sh returnStdout: false, script: """
100 mkdir -p $WORKSPACE/bin
101 # download kail
102 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
103
104 if [ "${params.branch}" == "voltha-2.9" ]; then
105 # Default kind-voltha config doesn't work on ONF demo pod for accessing kvstore.
106 # The issue is that the mgmt node is also one of the k8s nodes and so port forwarding doesn't work.
107 # We should change this. In the meantime here is a workaround.
108 set +e
109
110 # Remove noise from voltha-core logs
111 voltctl log level set WARN read-write-core#github.com/opencord/voltha-go/db/model
112 voltctl log level set WARN read-write-core#github.com/opencord/voltha-lib-go/v3/pkg/kafka
113 # Remove noise from openolt logs
114 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/db
115 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/probe
116 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/kafka
117 fi
118 """
119 }
120 }
121
122 stage('Functional Tests') {
123 environment {
124 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
125 ROBOT_FILE="Voltha_PODTests.robot"
126 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/FunctionalTests"
127 }
128 steps {
129 sh """
130 mkdir -p $ROBOT_LOGS_DIR
131 if ( ${powerSwitch} ); then
132 export ROBOT_MISC_ARGS="--removekeywords wuks -i PowerSwitch -i sanity -i functional -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
133 else
134 export ROBOT_MISC_ARGS="--removekeywords wuks -e PowerSwitch -i sanity -i functional -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
135 fi
136 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
137 make -C $WORKSPACE/voltha-system-tests voltha-test || true
138 """
139 }
140 }
141
142 stage('Failure/Recovery Tests') {
143 environment {
144 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
145 ROBOT_FILE="Voltha_FailureScenarios.robot"
146 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/FailureScenarios"
147 }
148 steps {
149 sh """
150 mkdir -p $ROBOT_LOGS_DIR
151 if ( ${powerSwitch} ); then
152 export ROBOT_MISC_ARGS="--removekeywords wuks -L TRACE -i functional -i PowerSwitch -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
153 else
154 export ROBOT_MISC_ARGS="--removekeywords wuks -L TRACE -i functional -e PowerSwitch -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
155 fi
156 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
157 make -C $WORKSPACE/voltha-system-tests voltha-test || true
158 """
159 }
160 }
161
162 stage('Dataplane Tests') {
163 environment {
164 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
165 ROBOT_FILE="Voltha_PODTests.robot"
166 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/DataplaneTests"
167 }
168 steps {
169 sh """
170 mkdir -p $ROBOT_LOGS_DIR
171 export ROBOT_MISC_ARGS="--removekeywords wuks -i dataplane -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
172 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
173 make -C $WORKSPACE/voltha-system-tests voltha-test || true
174 """
175 }
176 }
177 stage('HA Tests') {
178 environment {
179 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
180 ROBOT_FILE="Voltha_ONOSHATests.robot"
181 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/ONOSHAScenarios"
182 }
183 steps {
184 sh """
185 mkdir -p $ROBOT_LOGS_DIR
186 export ROBOT_MISC_ARGS="--removekeywords wuks -L TRACE -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v workflow:${params.workFlow} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
187 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
188 make -C $WORKSPACE/voltha-system-tests voltha-test || true
189 """
190 }
191 }
192
193 stage('Error Scenario Tests') {
194 environment {
195 ROBOT_CONFIG_FILE="$WORKSPACE/${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
196 ROBOT_FILE="Voltha_ErrorScenarios.robot"
197 ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/ErrorScenarios"
198 }
199 steps {
200 sh """
201 mkdir -p $ROBOT_LOGS_DIR
202 export ROBOT_MISC_ARGS="--removekeywords wuks -L TRACE -i functional -e bbsim -e notready -d $ROBOT_LOGS_DIR -v POD_NAME:${configFileName} -v KUBERNETES_CONFIGS_DIR:$WORKSPACE/${configBaseDir}/${configKubernetesDir} -v container_log_dir:$WORKSPACE -v OLT_ADAPTER_APP_LABEL:${oltAdapterAppLabel}"
203 ROBOT_MISC_ARGS+=" -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace}"
204 make -C $WORKSPACE/voltha-system-tests voltha-test || true
205 """
206 }
207 }
208 }
209 post {
210 always {
211 getPodsInfo("$WORKSPACE/pods")
212 sh returnStdout: false, script: '''
213 set +e
214
215 # collect logs collected in the Robot Framework StartLogging keyword
216 cd $WORKSPACE
217 gzip *-combined.log || true
218 rm *-combined.log || true
219
220 # store information on the running pods
221 kubectl get pods --all-namespaces -o wide > $WORKSPACE/pods.txt || true
222 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee $WORKSPACE/pod-images.txt || true
223 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee $WORKSPACE/pod-imagesId.txt || true
224
225
226 # collect ETCD cluster logs
227 mkdir -p $WORKSPACE/etcd
228 printf '%s\n' $(kubectl get pods -l app=etcd -o=jsonpath="{.items[*]['metadata.name']}") | xargs -I% bash -c "kubectl logs % > $WORKSPACE/etcd/%.log"
229 '''
230 script {
231 deployment_config.olts.each { olt ->
232 if (olt.type == null || olt.type == "" || olt.type == "openolt") {
233 sh returnStdout: false, script: """
234 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
235 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt-${olt.sship}.log # Remove escape sequences
236 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
237 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/dev_mgmt_daemon-${olt.sship}.log # Remove escape sequences
238 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
239 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/startup-${olt.sship}.log || true # Remove escape sequences
240 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
241 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt_process_watchdog-${olt.sship}.log || true # Remove escape sequences
242 """
243 }
244 }
245 }
246 step([$class: 'RobotPublisher',
247 disableArchiveOutput: false,
248 logFileName: '**/log*.html',
249 otherFiles: '',
250 outputFileName: '**/output*.xml',
251 outputPath: 'RobotLogs',
252 passThreshold: 100,
253 reportFileName: '**/report*.html',
254 unstableThreshold: 0,
255 onlyCritical: true
256 ]);
257 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.tgz,*.txt,pods/*.txt'
258 }
259 }
260}