Commit 82631c71 authored by Daniel Stone's avatar Daniel Stone Committed by Marge Bot
Browse files

ci/lava: Add explicit fatal-error handler

Truth is relative in 2021, and Python's duck-typing means truthiness
isn't what you think it is. Use an explicit fatal-error handler to make
sure we crash out hard on failure, rather than hoping sys.exit() behaves
like you think it does, because it doesn't.
Signed-off-by: Daniel Stone's avatarDaniel Stone <>
Part-of: <mesa/mesa!11309>
parent 4082fe7c
......@@ -39,13 +39,12 @@ from datetime import datetime
from lavacli.utils import loader
def log_msg(msg):
return "{}: {}".format(, msg)
def print_log(msg):
print("{}: {}".format(, msg))
def fatal_err(msg):
def generate_lava_yaml(args):
env = jinja2.Environment(loader = jinja2.FileSystemLoader(os.path.dirname(args.template)), trim_blocks=True, lstrip_blocks=True)
......@@ -101,13 +100,13 @@ def _call_proxy(fn, *args):
except xmlrpc.client.ProtocolError as err:
if n == retries:
sys.exit(log_msg("A protocol error occurred (Err {} {})".format(err.errcode, err.errmsg)))
fatal_err("A protocol error occurred (Err {} {})".format(err.errcode, err.errmsg))
except xmlrpc.client.Fault as err:
sys.exit(log_msg("FATAL: Fault: {} (code: {})".format(err.faultString, err.faultCode)))
fatal_err("FATAL: Fault: {} (code: {})".format(err.faultString, err.faultCode))
def get_job_results(proxy, job_id, test_suite, test_case):
......@@ -128,11 +127,11 @@ def get_job_results(proxy, job_id, test_suite, test_case):
results_yaml = _call_proxy(proxy.results.get_testcase_results_yaml, job_id, test_suite, test_case)
results = yaml.load(results_yaml, Loader=loader(False))
if not results:
sys.exit(log_msg("LAVA: no result for test_suite '{}', test_case '{}'".format(test_suite, test_case)))
fatal_err("LAVA: no result for test_suite '{}', test_case '{}'".format(test_suite, test_case))
print_log("LAVA: result for test_suite '{}', test_case '{}': {}".format(test_suite, test_case, results[0]['result']))
if results[0]['result'] != 'pass':
return True
......@@ -174,7 +173,7 @@ def main(args):
if args.validate_only:
ret = validate_job(proxy, yaml_file)
if not ret:
sys.exit(log_msg("Error in LAVA job definition"))
fatal_err("Error in LAVA job definition")
print("LAVA job definition validated successfully")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment