blob: 9e83ab90b428f99f09ff5d137284229d8760daff [file] [log] [blame]
Joey Armstrong379660e2022-12-14 19:21:00 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrongaf679da2023-01-31 14:22:41 -05003// Copyright 2021-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.
Joey Armstrong379660e2022-12-14 19:21:00 -050016// -----------------------------------------------------------------------
17
18// -----------------------------------------------------------------------
19// -----------------------------------------------------------------------
Joey Armstrongff0bd592023-07-31 17:37:14 -040020String getIam(String func) {
Joey Armstrong379660e2022-12-14 19:21:00 -050021 // Cannot rely on a stack trace due to jenkins manipulation
22 String src = 'vars/showCommands'
23 String iam = [src, func].join('::')
24 return iam
25}
26
27// -----------------------------------------------------------------------
28// -----------------------------------------------------------------------
Joey Armstrongff0bd592023-07-31 17:37:14 -040029void run_cmd(String command) {
Joey Armstrong97a8b882023-08-02 16:08:52 -040030 String buffer = [
Joey Armstrongff0bd592023-07-31 17:37:14 -040031 "Running command: $command",
32 ]
Joey Armstrong379660e2022-12-14 19:21:00 -050033
Joey Armstrongff0bd592023-07-31 17:37:14 -040034 println("** ${iam}: Running ${command} LEAVE")
35 try {
36 // Run command for output
37 buffer = sh(
38 script: command,
39 returnStdout: true
40 ).trim()
Joey Armstrong379660e2022-12-14 19:21:00 -050041
Joey Armstrongff0bd592023-07-31 17:37:14 -040042 // Reached if no exceptions thrown
43 buffer += [
44 '',
45 'Ran to completion',
46 ]
47 }
Joey Armstrongf076c312023-08-01 17:17:10 -040048 /*
Joey Armstrongff0bd592023-07-31 17:37:14 -040049 catch (Exception err)
50 {
51 // Note the exception w/o failing
52 buffer += [
53 '',
54 "${iam}: EXCEPTION ${err}",
55 ].join('\n')
56 }
Joey Armstrongf076c312023-08-01 17:17:10 -040057 */
Joey Armstrongff0bd592023-07-31 17:37:14 -040058 finally
59 {
Joey Armstrongf076c312023-08-01 17:17:10 -040060 println("** ${iam}: " + buffer.join(' '))
Joey Armstrongff0bd592023-07-31 17:37:14 -040061 println("** ${iam}: Running ${command} LEAVE")
62 }
Joey Armstrong379660e2022-12-14 19:21:00 -050063 return
64}
65
66// -----------------------------------------------------------------------
67// -----------------------------------------------------------------------
Joey Armstrongff0bd592023-07-31 17:37:14 -040068void process(Map config) {
69 String iam = getIam('process')
70
71 println("${iam} config=${config}")
72
73 // list.each{ } could be used here but keep it simple for now.
74 println("** ${iam}: voltctl command path")
75 run_cmd('which -a voltctl 2>&1')
76
77 println("** ${iam}: voltctl command version")
78 run_cmd('voltctl version')
79 return
80}
81
82// -----------------------------------------------------------------------
83// -----------------------------------------------------------------------
84Boolean call(Map config) {
Joey Armstrong379660e2022-12-14 19:21:00 -050085 String iam = getIam('main')
Joey Armstrongff0bd592023-07-31 17:37:14 -040086
Joey Armstrong379660e2022-12-14 19:21:00 -050087 println("** ${iam}: ENTER")
88
Joey Armstrongff0bd592023-07-31 17:37:14 -040089 config = config ?: [:]
90
91 try {
92 process(config)
Joey Armstrong379660e2022-12-14 19:21:00 -050093 }
Joey Armstrongff0bd592023-07-31 17:37:14 -040094 /*
Joey Armstrong379660e2022-12-14 19:21:00 -050095 catch (Exception err)
96 {
Joey Armstrongff0bd592023-07-31 17:37:14 -040097 println("** ${iam}: EXCEPTION ${err}")
98 throw err
Joey Armstrong379660e2022-12-14 19:21:00 -050099 }
Joey Armstrongff0bd592023-07-31 17:37:14 -0400100*/
Joey Armstrong379660e2022-12-14 19:21:00 -0500101 finally
102 {
Joey Armstrongff0bd592023-07-31 17:37:14 -0400103 println("** ${iam}: LEAVE")
Joey Armstrong379660e2022-12-14 19:21:00 -0500104 }
Joey Armstrongff0bd592023-07-31 17:37:14 -0400105 return(true)
Joey Armstrong379660e2022-12-14 19:21:00 -0500106}
107
Joey Armstrongaf679da2023-01-31 14:22:41 -0500108// [EOF]