Skip to content

Commit

Permalink
Fix IndexError with unexpected xml
Browse files Browse the repository at this point in the history
* fixes #70
* bail out when the xml yields just one entry with name pipeline and
  overall result error

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway committed Mar 20, 2024
1 parent e121f68 commit 7424bb7
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/report/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def parse_request_xunit(request_url_list=None, tasks_source=None, skip_pass=Fals
request_state = request.json()["state"].upper()
request_uuid = request.json()["id"]
request_target = request.json()["environments_requested"][0]["os"]["compose"]
request_arch = request.json()["environments_requested"][0]['arch']
request_arch = request.json()["environments_requested"][0]["arch"]
request_datetime_created = request.json()["created"]
request_datetime_parsed = request_datetime_created.split(".")[0]
request_summary = request.json()["result"]["summary"]

log_dir = f"{request_uuid}_logs"

Expand Down Expand Up @@ -175,7 +176,7 @@ def parse_request_xunit(request_url_list=None, tasks_source=None, skip_pass=Fals

if request.json()["state"] == "error":
error_formatted = FormatText.bg_red + "ERROR" + FormatText.bg_default
error_reason = request.json()["result"]["summary"]
error_reason = request_summary
message = (
f"Request ended up in {error_formatted} state, because {error_reason}.\n"
f"See more details on the result page {url.replace(TESTING_FARM_ENDPOINT, ARTIFACT_BASE_URL)}"
Expand All @@ -200,12 +201,30 @@ def parse_request_xunit(request_url_list=None, tasks_source=None, skip_pass=Fals

job_result_overall = xml.xpath("/testsuites/@overall-result")[0]
job_test_suite = xml.xpath("//testsuite")

# If there is just a single test suite returned and the name of the test suite
# is pipeline, we can assume that the response contains only information about the pipeline.
# Set the potential_pipeline_error to True and hand over to the overall job result evaluation
potential_pipeline_error = False
if (
len(job_test_suite) == 1
and job_test_suite[0].xpath("./@name")[0] == "pipeline"
):
potential_pipeline_error = True

if job_result_overall == "passed":
update_retval(ALL_PASS)
elif job_result_overall == "failed":
update_retval(FAIL_HERE)
elif job_result_overall == "error":
update_retval(ERROR_HERE)
# Bail out, when the potential pipeline error assessment returns True
if potential_pipeline_error:
LOGGER.critical(
f"Potential pipeline ERROR, please verify the accuracy of the assessment at {url}"
)
LOGGER.critical(f"Result summary: {request_summary}")
continue
else:
update_retval(99)

Expand All @@ -231,7 +250,9 @@ def parse_request_xunit(request_url_list=None, tasks_source=None, skip_pass=Fals
# it consist of only the plan name
testsuite_name = elem.xpath("./@name")[0].split(":")[-1]
try:
testsuite_arch = elem.xpath("./testing-environment/property[@name='arch']/@value")[0]
testsuite_arch = elem.xpath(
"./testing-environment/property[@name='arch']/@value"
)[0]
except IndexError:
testsuite_arch = elem.xpath("./@name")[0].split(":")[1]
testsuite_result = elem.xpath("./@result")[0].upper()
Expand Down Expand Up @@ -433,7 +454,6 @@ def build_table():
if ARGS.split_planname:
planname_split_index = ARGS.split_planname


def _gen_row(uuid="", target="", arch="", testplan="", testcase="", result=""):
if "UUID" in fields:
yield uuid
Expand Down

0 comments on commit 7424bb7

Please sign in to comment.