blob: afb5edf23dded430a14aac5752a8117ba9739e99 [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) {
30 String buffer [
31 "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 }
48 catch (Exception err)
49 {
50 // Note the exception w/o failing
51 buffer += [
52 '',
53 "${iam}: EXCEPTION ${err}",
54 ].join('\n')
55 }
56 finally
57 {
58 println("** ${iam}: $buffer")
59 println("** ${iam}: Running ${command} LEAVE")
60 }
Joey Armstrong379660e2022-12-14 19:21:00 -050061 return
62}
63
64// -----------------------------------------------------------------------
65// -----------------------------------------------------------------------
Joey Armstrongff0bd592023-07-31 17:37:14 -040066void process(Map config) {
67 String iam = getIam('process')
68
69 println("${iam} config=${config}")
70
71 // list.each{ } could be used here but keep it simple for now.
72 println("** ${iam}: voltctl command path")
73 run_cmd('which -a voltctl 2>&1')
74
75 println("** ${iam}: voltctl command version")
76 run_cmd('voltctl version')
77 return
78}
79
80// -----------------------------------------------------------------------
81// -----------------------------------------------------------------------
82Boolean call(Map config) {
Joey Armstrong379660e2022-12-14 19:21:00 -050083 String iam = getIam('main')
Joey Armstrongff0bd592023-07-31 17:37:14 -040084
Joey Armstrong379660e2022-12-14 19:21:00 -050085 println("** ${iam}: ENTER")
86
Joey Armstrongff0bd592023-07-31 17:37:14 -040087 config = config ?: [:]
88
89 try {
90 process(config)
Joey Armstrong379660e2022-12-14 19:21:00 -050091 }
Joey Armstrongff0bd592023-07-31 17:37:14 -040092 /*
Joey Armstrong379660e2022-12-14 19:21:00 -050093 catch (Exception err)
94 {
Joey Armstrongff0bd592023-07-31 17:37:14 -040095 println("** ${iam}: EXCEPTION ${err}")
96 throw err
Joey Armstrong379660e2022-12-14 19:21:00 -050097 }
Joey Armstrongff0bd592023-07-31 17:37:14 -040098*/
Joey Armstrong379660e2022-12-14 19:21:00 -050099 finally
100 {
Joey Armstrongff0bd592023-07-31 17:37:14 -0400101 println("** ${iam}: LEAVE")
Joey Armstrong379660e2022-12-14 19:21:00 -0500102 }
Joey Armstrongff0bd592023-07-31 17:37:14 -0400103 return(true)
Joey Armstrong379660e2022-12-14 19:21:00 -0500104}
105
Joey Armstrongaf679da2023-01-31 14:22:41 -0500106// [EOF]