Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 3 | // Copyright 2024 Open Networking Foundation Contributors |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -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 | // ----------------------------------------------------------------------- |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 17 | // SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors |
| 18 | // SPDX-License-Identifier: Apache-2.0 |
| 19 | // ----------------------------------------------------------------------- |
| 20 | // Intent: Helper script for kubernetes debugging |
| 21 | // Called by: jjb/pipeline/voltha/bbsim-tests.groovy |
| 22 | // ----------------------------------------------------------------------- |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 23 | |
| 24 | // ----------------------------------------------------------------------- |
| 25 | // ----------------------------------------------------------------------- |
| 26 | String getIam(String func) { |
| 27 | String src = 'vars/dotkube.groovy' |
| 28 | String iam = [src, func].join('::') |
| 29 | return iam |
| 30 | } |
| 31 | |
| 32 | // ----------------------------------------------------------------------- |
| 33 | // Intent: Log progress message |
| 34 | // ----------------------------------------------------------------------- |
| 35 | void enter(String name) { |
| 36 | // Announce ourselves for log usability |
| 37 | String iam = getIam(name) |
| 38 | println("${iam}: ENTER") |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | // ----------------------------------------------------------------------- |
| 43 | // Intent: Log progress message |
| 44 | // ----------------------------------------------------------------------- |
| 45 | void leave(String name) { |
| 46 | // Announce ourselves for log usability |
| 47 | String iam = getIam(name) |
| 48 | println("${iam}: LEAVE") |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | // ----------------------------------------------------------------------- |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 53 | // Intent: Terminate a process by name. |
| 54 | // ----------------------------------------------------------------------- |
| 55 | // Note: Due to an exception casting GString to java.lang.string: |
| 56 | // - Used for parameterized construction of a command line with args |
| 57 | // - Passed to jenkins sh("${cmd}") |
| 58 | // - Command line invoked is currently hardcoded. |
| 59 | // ----------------------------------------------------------------------- |
| 60 | Boolean process(String proc, Map args) { |
| 61 | Boolean ans = true |
| 62 | String iam = getIam('process') |
| 63 | |
| 64 | // clusterName: kind-ci |
| 65 | // config=kind-{clusterName} |
| 66 | // ------------------------- |
| 67 | // loader.go:223] Config not found: /home/jenkins/.kube/kind-kind-ci |
| 68 | sh( |
| 69 | label : '[DEBUG] ls ~/.kube' |
| 70 | script : """ |
| 71 | echo -e "\n** /bin/ls -ld ~/.kube" |
| 72 | /bin/ls -ld ~/.kube |
| 73 | |
| 74 | echo -e "\n** /bin/ls -ld: recursive" |
| 75 | find ~/.kube/. -print0 | xargs -0 /bin/ls -ld |
| 76 | """) |
| 77 | |
| 78 | return(ans) |
| 79 | } |
| 80 | |
| 81 | // ----------------------------------------------------------------------- |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 82 | // Intent: Display debug info about .kube/* |
| 83 | // ----------------------------------------------------------------------- |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 84 | // Usage: dotkube([debug:False]) |
| 85 | // ----------------------------------------------------------------------- |
| 86 | Boolean call\ |
| 87 | ( |
| 88 | Map config=[:] // Args passed to callback function |
| 89 | ) { |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 90 | // Boolean debug = config.debug ?: false |
| 91 | |
| 92 | String iam = getIam('main') |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 93 | Boolean ans = true |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 94 | |
| 95 | try { |
| 96 | enter(iam) |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 97 | process() |
| 98 | } |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 99 | |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 100 | // [DEBUG] function is non-fatal |
| 101 | catch (Exception err) { // groovylint-disable-line CatchException |
| 102 | // ans = false |
| 103 | println("** ${iam}: EXCEPTION WARNING ${err}") |
| 104 | // println("** ${iam}: EXCEPTION ${err}") |
| 105 | // throw err // non-fatal, no need to croak on find/ls errs |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 106 | } |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 107 | |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 108 | finally { |
| 109 | leave(iam) |
| 110 | } |
| 111 | |
Joey Armstrong | 2a9f016 | 2024-04-18 16:22:18 -0400 | [diff] [blame^] | 112 | return(ans) |
Joey Armstrong | 5353d31 | 2024-02-09 19:03:03 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // [EOF] |