Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 1 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 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 | |
| 15 | // voltha-2.x e2e tests for openonu-go |
| 16 | // uses bbsim to simulate OLT/ONUs |
| 17 | |
| 18 | library identifier: 'cord-jenkins-libraries@master', |
| 19 | retriever: modernSCM([ |
| 20 | $class: 'GitSCMSource', |
| 21 | remote: 'https://gerrit.opencord.org/ci-management.git' |
| 22 | ]) |
| 23 | |
| 24 | def clusterName = "kind-ci" |
| 25 | |
Joey Armstrong | 0eb8bd8 | 2023-07-10 13:26:25 -0400 | [diff] [blame] | 26 | def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "") |
| 27 | { |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 28 | def infraNamespace = "default" |
| 29 | def volthaNamespace = "voltha" |
| 30 | def logsDir = "$WORKSPACE/${testTarget}" |
| 31 | |
| 32 | stage('IAM') |
| 33 | { |
| 34 | script |
| 35 | { |
| 36 | String iam = [ |
| 37 | 'ci-management', |
| 38 | 'jjb', |
| 39 | 'pipeline', |
| 40 | 'voltha', |
Joey Armstrong | 6baeaae | 2023-02-07 01:35:55 -0500 | [diff] [blame] | 41 | 'voltha-2.11', // release-delta |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 42 | 'bbsim-tests.groovy' |
| 43 | ].join('/') |
| 44 | println("** ${iam}: ENTER") |
| 45 | |
| 46 | String cmd = "which pkill" |
| 47 | def stream = sh( |
| 48 | returnStatus:false, |
| 49 | returnStdout: true, |
| 50 | script: cmd) |
| 51 | println(" ** ${cmd}:\n${stream}") |
Joey Armstrong | 0eb8bd8 | 2023-07-10 13:26:25 -0400 | [diff] [blame] | 52 | |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 53 | println("** ${iam}: LEAVE") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | stage('Cleanup') { |
| 58 | if (teardown) { |
| 59 | timeout(15) { |
| 60 | script { |
| 61 | helmTeardown(["default", infraNamespace, volthaNamespace]) |
| 62 | } |
| 63 | timeout(1) { |
| 64 | sh returnStdout: false, script: ''' |
| 65 | # remove orphaned port-forward from different namespaces |
| 66 | ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true |
| 67 | ''' |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | stage ('Initialize') |
| 74 | { |
| 75 | // VOL-4926 - Is voltha-system-tests available ? |
| 76 | String cmd = [ |
| 77 | 'make', |
| 78 | '-C', "$WORKSPACE/voltha-system-tests", |
| 79 | "KAIL_PATH=\"$WORKSPACE/bin\"", |
| 80 | 'kail', |
| 81 | ].join(' ') |
| 82 | println(" ** Running: ${cmd}:\n") |
| 83 | sh("${cmd}") |
| 84 | } |
| 85 | |
| 86 | stage('Deploy common infrastructure') { |
| 87 | sh ''' |
| 88 | helm repo add onf https://charts.opencord.org |
| 89 | helm repo update |
| 90 | if [ ${withMonitoring} = true ] ; then |
| 91 | helm install nem-monitoring onf/nem-monitoring \ |
| 92 | --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \ |
| 93 | --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false |
| 94 | fi |
| 95 | ''' |
| 96 | } |
| 97 | |
| 98 | stage('Deploy Voltha') { |
| 99 | if (teardown) { |
| 100 | timeout(10) { |
| 101 | script { |
| 102 | |
| 103 | sh """ |
| 104 | mkdir -p ${logsDir} |
| 105 | _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log & |
| 106 | """ |
| 107 | |
| 108 | // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts |
| 109 | def localCharts = false |
| 110 | if (volthaHelmChartsChange != "" |
| 111 | || gerritProject == "voltha-helm-charts" |
| 112 | || branch != 'master' |
| 113 | ) { |
| 114 | localCharts = true |
| 115 | } |
| 116 | |
| 117 | // NOTE temporary workaround expose ONOS node ports |
| 118 | def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " + |
| 119 | " --set onos-classic.onosSshPort=30115 " + |
| 120 | " --set onos-classic.onosApiPort=30120 " + |
| 121 | " --set onos-classic.onosOfPort=31653 " + |
| 122 | " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags |
| 123 | |
| 124 | if (gerritProject != "") { |
| 125 | localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}") |
| 126 | } |
| 127 | |
| 128 | volthaDeploy([ |
| 129 | infraNamespace: infraNamespace, |
| 130 | volthaNamespace: volthaNamespace, |
| 131 | workflow: workflow.toLowerCase(), |
| 132 | withMacLearning: enableMacLearning.toBoolean(), |
| 133 | extraHelmFlags: localHelmFlags, |
| 134 | localCharts: localCharts, |
| 135 | bbsimReplica: olts.toInteger(), |
| 136 | dockerRegistry: registry, |
| 137 | ]) |
| 138 | } |
| 139 | |
| 140 | // stop logging |
| 141 | sh """ |
| 142 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')" |
| 143 | if [ -n "\$P_IDS" ]; then |
| 144 | echo \$P_IDS |
| 145 | for P_ID in \$P_IDS; do |
| 146 | kill -9 \$P_ID |
| 147 | done |
| 148 | fi |
| 149 | cd ${logsDir} |
| 150 | gzip -k onos-voltha-startup-combined.log |
| 151 | rm onos-voltha-startup-combined.log |
| 152 | """ |
| 153 | } |
| 154 | sh """ |
| 155 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/voltha-voltha-api 55555:55555; done"& |
| 156 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-etcd" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-etcd 2379:2379; done"& |
| 157 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-kafka" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-kafka 9092:9092; done"& |
| 158 | bbsimDmiPortFwd=50075 |
| 159 | for i in {0..${olts.toInteger() - 1}}; do |
| 160 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="bbsim\${i}" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/bbsim\${i} \${bbsimDmiPortFwd}:50075; done"& |
| 161 | ((bbsimDmiPortFwd++)) |
| 162 | done |
| 163 | if [ ${withMonitoring} = true ] ; then |
| 164 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="nem-monitoring-prometheus-server" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n default svc/nem-monitoring-prometheus-server 31301:80; done"& |
| 165 | fi |
| 166 | ps aux | grep port-forward |
| 167 | """ |
| 168 | // setting ONOS log level |
| 169 | script { |
| 170 | setOnosLogLevels([ |
| 171 | onosNamespace: infraNamespace, |
| 172 | apps: [ |
| 173 | 'org.opencord.dhcpl2relay', |
| 174 | 'org.opencord.olt', |
| 175 | 'org.opencord.aaa', |
| 176 | 'org.opencord.maclearner', |
| 177 | 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager', |
| 178 | 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager' |
| 179 | ], |
| 180 | logLevel: logLevel |
| 181 | ]) |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') { |
| 187 | sh """ |
| 188 | if [ ${withMonitoring} = true ] ; then |
| 189 | mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}" |
| 190 | cd "$WORKSPACE/voltha-system-tests" |
| 191 | make vst_venv |
| 192 | source ./vst_venv/bin/activate || true |
| 193 | # Collect initial memory consumption |
| 194 | python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true |
| 195 | fi |
| 196 | """ |
| 197 | sh """ |
| 198 | mkdir -p ${logsDir} |
| 199 | export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} " |
| 200 | ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:${logsDir} -v logging:${testLogging}" |
| 201 | export KVSTOREPREFIX=voltha/voltha_voltha |
| 202 | |
| 203 | make -C "$WORKSPACE/voltha-system-tests" ${testTarget} || true |
| 204 | """ |
| 205 | getPodsInfo("${logsDir}") |
| 206 | sh """ |
| 207 | set +e |
| 208 | # collect logs collected in the Robot Framework StartLogging keyword |
| 209 | cd ${logsDir} |
| 210 | gzip *-combined.log || true |
| 211 | rm *-combined.log || true |
| 212 | """ |
| 213 | sh """ |
| 214 | if [ ${withMonitoring} = true ] ; then |
| 215 | cd "$WORKSPACE/voltha-system-tests" |
| 216 | source ./vst_venv/bin/activate || true |
| 217 | # Collect memory consumption of voltha pods once all the tests are complete |
| 218 | python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true |
| 219 | fi |
| 220 | """ |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | def collectArtifacts(exitStatus) { |
| 225 | getPodsInfo("$WORKSPACE/${exitStatus}") |
| 226 | sh """ |
| 227 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true |
| 228 | """ |
| 229 | archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*' |
| 230 | sh ''' |
| 231 | sync |
| 232 | pkill kail || true |
| 233 | which voltctl |
| 234 | md5sum $(which voltctl) |
| 235 | ''' |
| 236 | step([$class: 'RobotPublisher', |
| 237 | disableArchiveOutput: false, |
| 238 | logFileName: "**/*/log*.html", |
| 239 | otherFiles: '', |
| 240 | outputFileName: "**/*/output*.xml", |
| 241 | outputPath: '.', |
| 242 | passThreshold: 100, |
| 243 | reportFileName: "**/*/report*.html", |
| 244 | unstableThreshold: 0, |
| 245 | onlyCritical: true]); |
| 246 | } |
| 247 | |
| 248 | pipeline { |
| 249 | |
| 250 | /* no label, executor is determined by JJB */ |
| 251 | agent { |
| 252 | label "${params.buildNode}" |
| 253 | } |
| 254 | options { |
| 255 | timeout(time: "${timeout}", unit: 'MINUTES') |
| 256 | } |
| 257 | environment { |
| 258 | KUBECONFIG="$HOME/.kube/kind-${clusterName}" |
| 259 | VOLTCONFIG="$HOME/.volt/config" |
| 260 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" |
| 261 | DIAGS_PROFILE="VOLTHA_PROFILE" |
| 262 | SSHPASS="karaf" |
| 263 | } |
| 264 | |
| 265 | stages { |
| 266 | stage('Download Code') { |
| 267 | steps { |
| 268 | getVolthaCode([ |
| 269 | branch: "${branch}", |
| 270 | gerritProject: "${gerritProject}", |
| 271 | gerritRefspec: "${gerritRefspec}", |
| 272 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 273 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 274 | ]) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | stage('Build patch') { |
| 279 | // build the patch only if gerritProject is specified |
| 280 | when { |
| 281 | expression { |
| 282 | return !gerritProject.isEmpty() |
| 283 | } |
| 284 | } |
| 285 | steps { |
| 286 | // NOTE that the correct patch has already been checked out |
| 287 | // during the getVolthaCode step |
| 288 | buildVolthaComponent("${gerritProject}") |
| 289 | } |
| 290 | } |
| 291 | stage('Create K8s Cluster') { |
| 292 | steps { |
| 293 | script { |
| 294 | def clusterExists = sh returnStdout: true, script: """ |
| 295 | kind get clusters | grep ${clusterName} | wc -l |
| 296 | """ |
| 297 | if (clusterExists.trim() == "0") { |
| 298 | createKubernetesCluster([nodes: 3, name: clusterName]) |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | stage('Replace voltctl') { |
| 304 | // if the project is voltctl override the downloaded one with the built one |
| 305 | when { |
| 306 | expression { |
| 307 | return gerritProject == "voltctl" |
| 308 | } |
| 309 | } |
| 310 | steps{ |
| 311 | sh """ |
| 312 | # [TODO] - why is this platform specific (?) |
Joey Armstrong | 93c8273 | 2023-02-07 03:01:25 -0500 | [diff] [blame] | 313 | # [TODO] - revisit, command alteration has masked an error (see: voltha-2.11). |
| 314 | # find will fail when no filsystem matches are found. |
| 315 | # mv(ls) succeded simply by accident/invoked at a different time. |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 316 | # find "$WORKSPACE/voltctl/release" -name 'voltctl-*-linux-amd*' \ |
Joey Armstrong | 93c8273 | 2023-02-07 03:01:25 -0500 | [diff] [blame] | 317 | # -exec mv {} $WORKSPACE/bin/voltctl ; |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 318 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 319 | chmod +x $WORKSPACE/bin/voltctl |
| 320 | """ |
| 321 | } |
| 322 | } |
| 323 | stage('Load image in kind nodes') { |
| 324 | when { |
| 325 | expression { |
| 326 | return !gerritProject.isEmpty() |
| 327 | } |
| 328 | } |
| 329 | steps { |
| 330 | loadToKind() |
| 331 | } |
| 332 | } |
| 333 | stage('Parse and execute tests') { |
| 334 | steps { |
| 335 | script { |
| 336 | def tests = readYaml text: testTargets |
| 337 | |
| 338 | for(int i = 0;i<tests.size();i++) { |
| 339 | def test = tests[i] |
| 340 | def target = test["target"] |
| 341 | def workflow = test["workflow"] |
| 342 | def flags = test["flags"] |
| 343 | def teardown = test["teardown"].toBoolean() |
| 344 | def logging = test["logging"].toBoolean() |
| 345 | def testLogging = 'False' |
| 346 | if (logging) { |
| 347 | testLogging = 'True' |
| 348 | } |
| 349 | println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}" |
| 350 | execute_test(target, workflow, testLogging, teardown, flags) |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | post { |
| 357 | aborted { |
| 358 | collectArtifacts("aborted") |
| 359 | } |
| 360 | failure { |
| 361 | collectArtifacts("failed") |
| 362 | } |
| 363 | always { |
| 364 | collectArtifacts("always") |
| 365 | } |
| 366 | } |
| 367 | } |