Skip to content

Commit 9df7536

Browse files
committed
smarter search for Sonobuoy executable
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 7cc8f3b commit 9df7536

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Tests/kaas/sonobuoy_handler/sonobuoy_handler.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import os
5+
import os.path
56
import shlex
67
import shutil
78
import subprocess
@@ -11,6 +12,16 @@
1112
logger = logging.getLogger(__name__)
1213

1314

15+
def _find_sonobuoy():
16+
"""find sonobuoy in PATH, but also in a fixed location at ~/.local/bin to simplify use with Ansible"""
17+
result = shutil.which('sonobuoy')
18+
if result:
19+
return result
20+
result = os.path.join(os.path.expanduser('~'), '.local', 'bin', 'sonobuoy')
21+
if os.path.exists(result):
22+
return result
23+
24+
1425
class SonobuoyHandler:
1526
"""
1627
A class that handles both the execution of sonobuoy and
@@ -34,7 +45,7 @@ def __init__(
3445
self.kubeconfig_path = kubeconfig
3546
self.working_directory = os.getcwd()
3647
self.result_dir_name = result_dir_name
37-
self.sonobuoy = shutil.which('sonobuoy')
48+
self.sonobuoy = _find_sonobuoy()
3849
logger.debug(f"working from {self.working_directory}")
3950
logger.debug(f"placing results at {self.result_dir_name}")
4051
logger.debug(f"sonobuoy executable at {self.sonobuoy}")

0 commit comments

Comments
 (0)