Skip to content

Commit 2e1587f

Browse files
committed
further improvements
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 1baa82c commit 2e1587f

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Tests/kaas/sonobuoy_handler/sonobuoy_handler.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ def __init__(
3030
self.check_name = check_name
3131
logger.debug(f"kubeconfig: {kubeconfig} ")
3232
if kubeconfig is None:
33-
raise Exception("No kubeconfig provided")
34-
else:
35-
self.kubeconfig_path = kubeconfig
33+
raise RuntimeError("No kubeconfig provided")
34+
self.kubeconfig_path = kubeconfig
3635
self.working_directory = os.getcwd()
3736
self.result_dir_name = result_dir_name
3837
self.sonobuoy = shutil.which('sonobuoy')
@@ -63,14 +62,14 @@ def _sonobuoy_status_result(self):
6362
return counter
6463

6564
def _eval_result(self, counter):
65+
"""evaluate test results and return return code"""
6666
result_str = ', '.join(f"{counter[key]} {key}" for key in ('passed', 'failed', 'skipped'))
6767
result_message = f"sonobuoy reports {result_str}"
6868
if counter['failed']:
6969
logger.error(result_message)
70-
self.return_code = 3
71-
else:
72-
logger.info(result_message)
73-
self.return_code = 0
70+
return 3
71+
logger.info(result_message)
72+
return 0
7473

7574
def _preflight_check(self):
7675
"""
@@ -117,15 +116,18 @@ def run(self):
117116
This method is to be called to run the plugin
118117
"""
119118
logger.info(f"running sonobuoy for testcase {self.check_name}")
120-
self.return_code = 11
121119
self._preflight_check()
122-
self._sonobuoy_run()
123-
self._eval_result(self._sonobuoy_status_result())
124-
125-
# ERROR: currently disabled do to: "error retrieving results: unexpected EOF"
126-
# might be related to following bug: https://github.com/vmware-tanzu/sonobuoy/issues/1633
127-
# self._sonobuoy_retrieve_result(self)
128-
129-
self._sonobuoy_delete()
130-
print(self.check_name + ": " + ("PASS", "FAIL")[min(1, self.return_code)])
131-
return self.return_code
120+
try:
121+
self._sonobuoy_run()
122+
return_code = self._eval_result(self._sonobuoy_status_result())
123+
print(self.check_name + ": " + ("PASS", "FAIL")[min(1, return_code)])
124+
return return_code
125+
126+
# ERROR: currently disabled due to: "error retrieving results: unexpected EOF"
127+
# might be related to following bug: https://github.com/vmware-tanzu/sonobuoy/issues/1633
128+
# self._sonobuoy_retrieve_result(self)
129+
except BaseException:
130+
logger.exception("something went wrong")
131+
return 112
132+
finally:
133+
self._sonobuoy_delete()

0 commit comments

Comments
 (0)