Skip to content

Commit f8a482c

Browse files
committed
compile regex first.
1 parent dbbe8d0 commit f8a482c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Tests/kaas/sonobuoy_handler/sonobuoy_handler.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ def _sonobuoy_retrieve_result(self, plugin='e2e'):
103103
self._invoke_sonobuoy("retrieve", "-x", result_dir)
104104
yaml_path = os.path.join(result_dir, 'plugins', plugin, 'sonobuoy_results.yaml')
105105
logger.debug(f"parsing results from {yaml_path}")
106+
ok_to_fail_regex_list = _load_ok_to_fail_regex_list(self.scs_sonobuoy_config_yaml)
106107

107-
return sonobuoy_parse_result(plugin, yaml_path, self.scs_sonobuoy_config_yaml)
108+
return sonobuoy_parse_result(plugin, yaml_path, ok_to_fail_regex_list)
108109

109110
def run(self):
110111
"""
@@ -125,8 +126,7 @@ def run(self):
125126
self._sonobuoy_delete()
126127

127128

128-
def sonobuoy_parse_result(plugin, sonobuoy_results_yaml_path, scs_sonobuoy_config_yaml):
129-
ok_to_fail_regex_list = _load_ok_to_fail_regex_list(scs_sonobuoy_config_yaml)
129+
def sonobuoy_parse_result(plugin, sonobuoy_results_yaml_path, ok_to_fail_regex_list):
130130
with open(sonobuoy_results_yaml_path, "r") as fileobj:
131131
result_obj = yaml.load(fileobj.read(), yaml.SafeLoader)
132132

@@ -186,7 +186,7 @@ def _load_ok_to_fail_regex_list(scs_sonobuoy_config_yaml):
186186
raise ValueError(
187187
f"Invalid sonobuoy config format in {scs_sonobuoy_config_yaml}: okToFail[{idx}].reason must be a non-empty string"
188188
)
189-
ok_to_fail_regex_list.append((regex, reason))
189+
ok_to_fail_regex_list.append((re.compile(regex), reason))
190190
return ok_to_fail_regex_list
191191

192192

@@ -199,6 +199,7 @@ def ok_to_fail(ok_to_fail_regex_list, test_name):
199199

200200

201201
def check_sonobuoy_result(scs_sonobuoy_config_yaml, result_yaml):
202-
counter = sonobuoy_parse_result("", result_yaml, scs_sonobuoy_config_yaml)
202+
ok_to_fail_regex_list = _load_ok_to_fail_regex_list(scs_sonobuoy_config_yaml)
203+
counter = sonobuoy_parse_result("", result_yaml, ok_to_fail_regex_list)
203204
for key, value in counter.items():
204205
print(f"{key}: {value}")

0 commit comments

Comments
 (0)