From 30ec03a3011501ebb4ddafbc87f45a22fc3f68b3 Mon Sep 17 00:00:00 2001 From: Katerina Koukiou Date: Mon, 20 Jan 2025 13:33:50 +0100 Subject: [PATCH] WIP: generate a report for Wiki for the latest compose This was inspired by openQA Wiki report script [1]. TODO: Remove 'Fedora 42' hardcoded values. [1] https://pagure.io/fedora-qa/fedora_openqa/blob/main/f/src/fedora_openqa/report.py --- test/run | 4 ++ test/wiki-report.py | 123 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100755 test/wiki-report.py diff --git a/test/run b/test/run index 6fcb9a558..874fcc181 100755 --- a/test/run +++ b/test/run @@ -56,3 +56,7 @@ if [ -z "${TEST_OS-}" ]; then fi export TEST_JOBS TEST_OS J=$(($TEST_JOBS/4)); [ $J -ge 1 ] || J=1; TEST_AUDIT_NO_SELINUX=1 test/common/run-tests --test-dir test/ --jobs $J $RUN_OPTS + +if [ -n "${TEST_COMPOSE-}" ]; then + test/wiki-report "test/report.json" +fi diff --git a/test/wiki-report.py b/test/wiki-report.py new file mode 100755 index 000000000..fe883df22 --- /dev/null +++ b/test/wiki-report.py @@ -0,0 +1,123 @@ +#!/usr/bin/python3 + +# Copyright (C) 2025 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; If not, see . + +import json +import logging +import sys +from operator import attrgetter + +import mwclient.errors +from wikitcms.wiki import ResTuple, Wiki + +logger = logging.getLogger(__name__) +logging.basicConfig(stream=sys.stdout, level=logging.INFO) + +class LoginError(Exception): + """Raised when cannot log in to wiki to submit results.""" + pass + + +class WikiReport: + def __init__(self, report_path): + self.report_path = report_path + self.report = self.parse_json_report() + self.compose_id = self.report["metadata"]["compose"] + self.wiki_hostname = "stg.fedoraproject.org" + + def get_test_result_page(compose_id): + # FIXME: Hardcode Fedora 42 temporarily + # Compose ID example: Fedora-Rawhide-20250119.n.0 + # Page URL example: https://fedoraproject.org/wiki/Test_Results:Fedora_42_Rawhide_20250119.n.0_Installation + compose_date = compose_id.split("-")[2] + return f"https://fedoraproject.org/wiki/Test_Results:Fedora_42_Rawhide{compose_date}_Installation" + + def get_passed_testcases(self): + passed_testcases = set() + + for testcase in self.report["tests"]: + if testcase["status"] == "pass": + passed_testcases.add( + ResTuple( + bot=True, + cid=self.compose_id, + compose=self.compose_id.split("-")[-1], + dist="Fedora", + # FIXME: Hardcode x86_64 temporarily till we support other arches + env="x86_64 BIOS" if testcase["firmware"] == "bios" else "x86_64 UEFI", + milestone="Rawhide", + release="42", + user="anaconda-bot", + section=testcase["wikictms_section"], + status="pass", + testcase=testcase["openqa_test"], + testname=testcase["test_name"], + testtype="Installation", + ) + ) + + return sorted(passed_testcases, key=attrgetter('testcase')) + + def parse_json_report(self): + with open(self.report_path, "r") as f: + return json.load(f) + + def login(self, wiki): + if not wiki.logged_in: + # This seems to occasionally throw bogus WrongPass errors + try: + wiki.login() + except mwclient.errors.LoginError: + wiki.login() + + if not wiki.logged_in: + logger.error("could not log in to wiki") + raise LoginError + + def upload_report(self, wiki, passed_testcases): + # Submit the results + (insuffs, dupes) = wiki.report_validation_results(passed_testcases) + + for dupe in dupes: + tmpl = "already reported result for test %s, env %s! Will not report dupe." + logger.info(tmpl, dupe.testcase, dupe.env) + logger.debug("full ResTuple: %s", dupe) + + for insuff in insuffs: + tmpl = "insufficient data for test %s, env %s! Will not report." + logger.info(tmpl, insuff.testcase, insuff.env) + logger.debug("full ResTuple: %s", insuff) + + return [] + + def run(self): + wiki = Wiki(self.wiki_hostname) + + passed_testcases = self.get_passed_testcases() + logger.info("passed testcases: %s", passed_testcases) + + self.login(wiki) + + self.upload_report(wiki, passed_testcases) + + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: compose-report.py ") + sys.exit(1) + + WikiReport(sys.argv[1]).run()