blob: 3b1b460f99ef9507b8eae7195cd60102d217a28d [file] [log] [blame]
Joey Armstrong5353d312024-02-09 19:03:03 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrong2a9f0162024-04-18 16:22:18 -04003// Copyright 2024 Open Networking Foundation Contributors
Joey Armstrong5353d312024-02-09 19:03:03 -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// -----------------------------------------------------------------------
Joey Armstrong2a9f0162024-04-18 16:22:18 -040017// 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 Armstrong5353d312024-02-09 19:03:03 -050023
24// -----------------------------------------------------------------------
25// -----------------------------------------------------------------------
26String 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// -----------------------------------------------------------------------
35void 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// -----------------------------------------------------------------------
45void leave(String name) {
46 // Announce ourselves for log usability
47 String iam = getIam(name)
48 println("${iam}: LEAVE")
49 return
50}
51
52// -----------------------------------------------------------------------
Joey Armstrong2a9f0162024-04-18 16:22:18 -040053// 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// -----------------------------------------------------------------------
60Boolean 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 : """
71echo -e "\n** /bin/ls -ld ~/.kube"
72/bin/ls -ld ~/.kube
73
74echo -e "\n** /bin/ls -ld: recursive"
75find ~/.kube/. -print0 | xargs -0 /bin/ls -ld
76""")
77
78 return(ans)
79}
80
81// -----------------------------------------------------------------------
Joey Armstrong5353d312024-02-09 19:03:03 -050082// Intent: Display debug info about .kube/*
83// -----------------------------------------------------------------------
Joey Armstrong2a9f0162024-04-18 16:22:18 -040084// Usage: dotkube([debug:False])
85// -----------------------------------------------------------------------
86Boolean call\
87(
88 Map config=[:] // Args passed to callback function
89) {
Joey Armstrong5353d312024-02-09 19:03:03 -050090 // Boolean debug = config.debug ?: false
91
92 String iam = getIam('main')
Joey Armstrong2a9f0162024-04-18 16:22:18 -040093 Boolean ans = true
Joey Armstrong5353d312024-02-09 19:03:03 -050094
95 try {
96 enter(iam)
Joey Armstrong2a9f0162024-04-18 16:22:18 -040097 process()
98 }
Joey Armstrong5353d312024-02-09 19:03:03 -050099
Joey Armstrong2a9f0162024-04-18 16:22:18 -0400100 // [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 Armstrong5353d312024-02-09 19:03:03 -0500106 }
Joey Armstrong2a9f0162024-04-18 16:22:18 -0400107
Joey Armstrong5353d312024-02-09 19:03:03 -0500108 finally {
109 leave(iam)
110 }
111
Joey Armstrong2a9f0162024-04-18 16:22:18 -0400112 return(ans)
Joey Armstrong5353d312024-02-09 19:03:03 -0500113}
114
115// [EOF]