blob: 1eb875d57a043504d5c5edaed38b9c8d30049551 [file] [log] [blame]
Joey Armstrong16bd8e82023-01-12 15:20:06 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrong518f3572024-02-11 07:56:25 -05003// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong16bd8e82023-01-12 15:20:06 -05004//
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 Scandolo67842812021-07-13 16:52:13 -070018// check if kail is installed, if not installs it
19// and then uses it to collect logs on specified containers
Joey Armstrong16bd8e82023-01-12 15:20:06 -050020//
Matteo Scandolo67842812021-07-13 16:52:13 -070021// 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 Armstrong16bd8e82023-01-12 15:20:06 -050024//
Matteo Scandolo67842812021-07-13 16:52:13 -070025// to archive the logs use: archiveArtifacts artifacts: '${logsDir}/*.log'
Joey Armstrong16bd8e82023-01-12 15:20:06 -050026// -----------------------------------------------------------------------
27
28// -----------------------------------------------------------------------
29// -----------------------------------------------------------------------
30def 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 Scandolo67842812021-07-13 16:52:13 -070040def call(Map config) {
41
Joey Armstrong16bd8e82023-01-12 15:20:06 -050042 String iam = getIam('main')
43 println("** ${iam}: ENTER")
44
Matteo Scandolo67842812021-07-13 16:52:13 -070045 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 Armstrong16bd8e82023-01-12 15:20:06 -050069 sh("""make -C "$WORKSPACE/voltha-system-tests" KAIL_PATH="$WORKSPACE/bin" kail""")
Matteo Scandolo67842812021-07-13 16:52:13 -070070
Joey Armstrong16bd8e82023-01-12 15:20:06 -050071 // if logsDir does not exists dir() will create it
Matteo Scandolo67842812021-07-13 16:52:13 -070072 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 Scandolo6253af62021-07-16 12:19:07 -070079 _TAG=${tag} kail -l ${label} > ${cfg.logsDir}/${logFile}.log&
Matteo Scandolo67842812021-07-13 16:52:13 -070080 """
81 }
82 }
Joey Armstrong16bd8e82023-01-12 15:20:06 -050083
84 println("** ${iam}: LEAVE")
85 return
86}
87
88// [EOF]