Skip to content

Commit

Permalink
Fix IndexError with unexpected xml (#71)
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
* try request overall result if xml unavailable

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway authored Mar 25, 2024
1 parent a5cdfbe commit bbe3c1a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tesar/dispatch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_logging():
if not logger.hasHandlers():
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(logging.Formatter("%(levelname)s | %(message)s"))
console_handler.setFormatter(logging.Formatter("%(levelname)-8s | %(message)s"))
logger.addHandler(console_handler)
return logger

Expand Down
36 changes: 34 additions & 2 deletions src/tesar/report/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def parse_request_xunit(request_url_list=None, tasks_source=None, skip_pass=Fals
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"]
request_result_overall = request.json()["result"]["overall"]

log_dir = f"{request_uuid}_logs"

Expand Down Expand Up @@ -175,7 +177,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 @@ -193,19 +195,49 @@ def parse_request_xunit(request_url_list=None, tasks_source=None, skip_pass=Fals
if results_xml_response:
xunit = results_xml_response.text
else:
LOGGER.critical("Unable to find the xml to parse.")
LOGGER.critical("Trying to fall back to the request results.")
if request_result_overall and request_summary:
LOGGER.info(
f"Result: {FormatText.bold}{request_result_overall}{FormatText.end}"
)
LOGGER.info(
f"Summary: {FormatText.bold}{request_summary}{FormatText.end}"
)
else:
LOGGER.info("Couldn't find any valuable information.")
LOGGER.info(f"Please consult with {url}")
update_retval(ERROR_HERE)
continue

xml = lxml.etree.fromstring(xunit.encode())

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 Down Expand Up @@ -513,5 +545,5 @@ def main(result_table=None):
if result_table.rowcount > 0:
print(result_table)
else:
print("Nothing to report!")
LOGGER.info("Nothing to report!")
return RETURN_VALUE

0 comments on commit bbe3c1a

Please sign in to comment.