Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 3 | // Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 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 | // Intent: |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 18 | // check if kail is installed, if not installs it |
| 19 | // and then uses it to collect logs on specified containers |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 20 | // |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 21 | // appsToLog is a list of kubernetes labels used by kail to get the logs |
| 22 | // the generated log file is named with the string after = |
| 23 | // for example app=bbsim will generate a file called bbsim.log |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 24 | // |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 25 | // to archive the logs use: archiveArtifacts artifacts: '${logsDir}/*.log' |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 26 | // ----------------------------------------------------------------------- |
| 27 | |
| 28 | // ----------------------------------------------------------------------- |
| 29 | // ----------------------------------------------------------------------- |
| 30 | def getIam(String func) |
| 31 | { |
| 32 | // Cannot rely on a stack trace due to jenkins manipulation |
| 33 | String src = 'vars/startComponentLogs.groovy' |
| 34 | String iam = [src, func].join('::') |
| 35 | return iam |
| 36 | } |
| 37 | |
| 38 | // ----------------------------------------------------------------------- |
| 39 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 40 | def call(Map config) { |
| 41 | |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 42 | String iam = getIam('main') |
| 43 | println("** ${iam}: ENTER") |
| 44 | |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 45 | def tagPrefix = "jenkins" |
| 46 | |
| 47 | def defaultConfig = [ |
| 48 | appsToLog: [ |
| 49 | 'app=onos-classic', |
| 50 | 'app=adapter-open-onu', |
| 51 | 'app=adapter-open-olt', |
| 52 | 'app=rw-core', |
| 53 | 'app=ofagent', |
| 54 | 'app=bbsim', |
| 55 | 'app=radius', |
| 56 | 'app=bbsim-sadis-server', |
| 57 | 'app=onos-config-loader', |
| 58 | ], |
| 59 | logsDir: "$WORKSPACE/logs" |
| 60 | ] |
| 61 | |
| 62 | if (!config) { |
| 63 | config = [:] |
| 64 | } |
| 65 | |
| 66 | def cfg = defaultConfig + config |
| 67 | |
| 68 | // check if kail is installed and if not installs it |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 69 | sh("""make -C "$WORKSPACE/voltha-system-tests" KAIL_PATH="$WORKSPACE/bin" kail""") |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 70 | |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 71 | // if logsDir does not exists dir() will create it |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 72 | dir(cfg.logsDir) { |
| 73 | for(int i = 0;i<cfg.appsToLog.size();i++) { |
| 74 | def label = cfg.appsToLog[i] |
| 75 | def logFile = label.split('=')[1] |
| 76 | def tag = "${tagPrefix}-kail-${logFile}" |
| 77 | println "Starting logging process for label: ${label}" |
| 78 | sh """ |
Matteo Scandolo | 6253af6 | 2021-07-16 12:19:07 -0700 | [diff] [blame] | 79 | _TAG=${tag} kail -l ${label} > ${cfg.logsDir}/${logFile}.log& |
Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 80 | """ |
| 81 | } |
| 82 | } |
Joey Armstrong | 16bd8e8 | 2023-01-12 15:20:06 -0500 | [diff] [blame] | 83 | |
| 84 | println("** ${iam}: LEAVE") |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | // [EOF] |