From 7c74642cf07161d507cf54b84979bb6145c1bf32 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 15 Jan 2025 09:09:41 -0700 Subject: [PATCH] allow to work with beaker job xml url/file, not just job ID --- check_logs.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/check_logs.py b/check_logs.py index 614a623..a03d09b 100755 --- a/check_logs.py +++ b/check_logs.py @@ -507,10 +507,17 @@ def parse_avc_log(args, log_url): def get_beaker_job_info(args, job): - result = subprocess.run( - ["bkr", "job-results", job], capture_output=True, text=True, check=True - ) - bs = BeautifulSoup(result.stdout, "xml") + if job.endswith(".xml"): # a URL or a local file + if job.startswith("http://") or job.startswith("https://"): + xml_data = requests.get(job).content + else: + xml_data = open(job).read() + bs = BeautifulSoup(xml_data, "xml") + else: # assume it is a job number like J:1213552 + result = subprocess.run( + ["bkr", "job-results", job], capture_output=True, text=True, check=True + ) + bs = BeautifulSoup(result.stdout, "xml") data = {} data["job"] = job data["whiteboard"] = bs.find("whiteboard").text @@ -538,15 +545,16 @@ def get_beaker_job_info(args, job): task_data["name"] = "basic-smoke-test" log_urls = [] for log in task.find("logs"): - link = log.get("href") - name = log.get("name") - if name == "taskout.log": - task_data["job_data"] = parse_beaker_job_log( - args, task_data["start_time"], link - ) - elif name.startswith("SYSTEM-ROLE-"): - task_data["errors"].extend(get_errors_from_ansible_log(args, link)) - log_urls.append(link) + if hasattr(log, "get"): + link = log.get("href") + name = log.get("name") + if name == "taskout.log": + task_data["job_data"] = parse_beaker_job_log( + args, task_data["start_time"], link + ) + elif name.startswith("SYSTEM-ROLE-"): + task_data["errors"].extend(get_errors_from_ansible_log(args, link)) + log_urls.append(link) task_data["logs"] = log_urls role = None task_data["avcs"] = {} @@ -749,8 +757,8 @@ def print_ansible_errors(args, errors): value = "\n".join(item) else: value = str(item) - if len(value) > 20000: - value = value[:20000] + ".... truncated" + if len(value) > 5000: + value = value[:5000] + ".... truncated" value_list.append(value) values.append(value_list) sh.values_update(