Skip to content

Commit 75001de

Browse files
svtebmartin-mat
authored andcommitted
Fix: Invalid sonobuoy result parsing
Refs: #2314 - The k8s_conformance task in platform tests was failing under some circumstances, this was caused by a grep that was catching all results in the format "Failed: *", the * was sometimes not a numeric value which would crash the original *.to_s.to_i chain, it is still unknown what value would be there (maybe "NA/Error"). - The "fix" adds more robust handling of erroneous values, namely they will get printed through a log.warn and not cause an exception, further changes will be done if more precise errors are reported. - Also added missing namespace in task call. Signed-off-by: svteb <slavo.valko@tietoevry.com>
1 parent 6f59650 commit 75001de

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/tasks/platform/platform.cr

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,26 @@ task "k8s_conformance" do |t, args|
6565
results = results_stdout.to_s
6666
Log.debug { results }
6767

68-
# Grab the failed line from the results
68+
failed_count = nil
69+
if failed_match_data = results.match(/Failed:\s+(\S+)/)
70+
failed_raw_value = failed_match_data[1]
71+
if failed_integer = failed_raw_value.to_i?
72+
Log.debug { "Sonobuoy summary: Failed=#{failed_raw_value}" }
73+
failed_count = failed_integer
74+
else
75+
Log.warn {
76+
"Matched non-numeric 'Failed:' value #{failed_raw_value.inspect} — cannot determine result.\nRaw results:\n#{results}"
77+
}
78+
end
79+
else
80+
Log.warn {
81+
"No 'Failed:' line found in Sonobuoy results — cannot determine result.\nRaw results:\n#{results}"
82+
}
83+
end
6984

70-
failed_count = ((results.match(/Failed: (.*)/)).try &.[1])
71-
if failed_count.to_s.to_i > 0
85+
if failed_count.nil?
86+
CNFManager::TestCaseResult.new(CNFManager::ResultStatus::Error, "Unable to determine failure count from Sonobuoy results")
87+
elsif failed_count > 0
7288
CNFManager::TestCaseResult.new(CNFManager::ResultStatus::Failed, "K8s conformance test has #{failed_count} failure(s)!")
7389
else
7490
CNFManager::TestCaseResult.new(CNFManager::ResultStatus::Passed, "K8s conformance test has no failures")

0 commit comments

Comments
 (0)