Skip to content

Commit

Permalink
WIP: generate a report for Wiki for the latest compose
Browse files Browse the repository at this point in the history
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
  • Loading branch information
KKoukiou committed Jan 22, 2025
1 parent 40cd850 commit 30ec03a
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
123 changes: 123 additions & 0 deletions test/wiki-report.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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 <report_path>")
sys.exit(1)

WikiReport(sys.argv[1]).run()

0 comments on commit 30ec03a

Please sign in to comment.