Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // 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 Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 16 | // ----------------------------------------------------------------------- |
| 17 | |
| 18 | // ----------------------------------------------------------------------- |
| 19 | // ----------------------------------------------------------------------- |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 20 | String getIam(String func) { |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 21 | // 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 Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 29 | void run_cmd(String command) { |
Joey Armstrong | 97a8b88 | 2023-08-02 16:08:52 -0400 | [diff] [blame] | 30 | String buffer = [ |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 31 | "Running command: $command", |
| 32 | ] |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 33 | |
Roger Luethi | ff337d8 | 2023-09-20 12:09:44 +0200 | [diff] [blame] | 34 | println("** ${iam}: Running ${command} ENTER") |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 35 | try { |
| 36 | // Run command for output |
| 37 | buffer = sh( |
| 38 | script: command, |
| 39 | returnStdout: true |
| 40 | ).trim() |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 41 | |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 42 | // Reached if no exceptions thrown |
| 43 | buffer += [ |
| 44 | '', |
| 45 | 'Ran to completion', |
| 46 | ] |
| 47 | } |
Joey Armstrong | f076c31 | 2023-08-01 17:17:10 -0400 | [diff] [blame] | 48 | /* |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 49 | catch (Exception err) |
| 50 | { |
| 51 | // Note the exception w/o failing |
| 52 | buffer += [ |
| 53 | '', |
| 54 | "${iam}: EXCEPTION ${err}", |
| 55 | ].join('\n') |
| 56 | } |
Joey Armstrong | f076c31 | 2023-08-01 17:17:10 -0400 | [diff] [blame] | 57 | */ |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 58 | finally |
| 59 | { |
Joey Armstrong | f076c31 | 2023-08-01 17:17:10 -0400 | [diff] [blame] | 60 | println("** ${iam}: " + buffer.join(' ')) |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 61 | println("** ${iam}: Running ${command} LEAVE") |
| 62 | } |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 63 | return |
| 64 | } |
| 65 | |
| 66 | // ----------------------------------------------------------------------- |
| 67 | // ----------------------------------------------------------------------- |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 68 | void 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 | // ----------------------------------------------------------------------- |
| 84 | Boolean call(Map config) { |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 85 | String iam = getIam('main') |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 86 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 87 | println("** ${iam}: ENTER") |
| 88 | |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 89 | config = config ?: [:] |
| 90 | |
| 91 | try { |
| 92 | process(config) |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 93 | } |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 94 | /* |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 95 | catch (Exception err) |
| 96 | { |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 97 | println("** ${iam}: EXCEPTION ${err}") |
| 98 | throw err |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 99 | } |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 100 | */ |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 101 | finally |
| 102 | { |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 103 | println("** ${iam}: LEAVE") |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 104 | } |
Joey Armstrong | ff0bd59 | 2023-07-31 17:37:14 -0400 | [diff] [blame] | 105 | return(true) |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 106 | } |
| 107 | |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 108 | // [EOF] |