Files
rustfs/scripts/compat_matrix_report.py
T

172 lines
8.3 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2026 RustFS Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Summarize and judge the gateway client matrix run against the RustFS candidate.
Usage:
compat_matrix_report.py check --run-dir <dir>
compat_matrix_report.py --self-test
<dir> holds what the lane observed: the server record acceptance_lane.py reads,
`skipped-clients.txt` (`<client>: <reason>` per client that could not be
installed), `matrix-exit.txt` (the exit code of the gateway's
ci/compat/run_matrix.sh) and `compat/matrix.json` (its manifest).
`check` is clean only when the server served, the matrix
finished, every client ran, and no cell is `fail` or `sut-unregistered`
(rustfs/backlog#2776). A `client-unsupported` cell is the client's gap, never a
pass, and is counted. The gateway's own scripts/check_compat_matrix.sh at the
pinned rev is not a substitute: it does not fail a `fail` cell (it only checks
the cell's known-fail label) or a client that never ran, and it also judges that
repository's own files (known-fail ratchet from git history, drivers, workflow).
Exit codes: 0 clean; 1 otherwise; 2 malformed input.
"""
import argparse
import json
from pathlib import Path
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parent))
from acceptance_lane import InputError, read_exit, read_text, served, write_served # noqa: E402 (sibling script)
STATUSES = ("pass", "fail", "client-unsupported", "sut-unregistered")
def read_cells(run_dir):
"""Return {(client, scenario): cell} from the run's manifest, or None when it wrote none."""
manifest = Path(run_dir) / "compat/matrix.json"
cells = None
if manifest.is_file():
try:
cells = {(client["name"], scenario["id"]): scenario
for client in json.loads(manifest.read_text(encoding="utf-8"))["clients"]
for scenario in client["scenarios"]}
except (json.JSONDecodeError, KeyError, TypeError) as error:
raise InputError(f"{manifest}: not a client matrix manifest: {error}") from error
if any(cell.get("status") not in STATUSES for cell in cells.values()):
raise InputError(f"{manifest}: unknown cell status")
return cells
def check(run_dir):
"""Return (summary lines, problems)."""
server, problem = served(run_dir)
lines = ["### Client matrix", "", server]
if problem:
return lines, [f"matrix: {problem}; no client ran"]
skipped = [line for line in read_text(Path(run_dir) / "skipped-clients.txt").splitlines() if line.strip()]
matrix_exit, cells = read_exit(Path(run_dir) / "matrix-exit.txt"), read_cells(run_dir)
lines.append(f"- run_matrix exit: {matrix_exit if matrix_exit is not None else 'not recorded'}")
lines += [f"- {line}" if ": skipped: " in line else f"- {line}: skipped" for line in skipped]
problems = [f"matrix: client {line.split(':', 1)[0]} did not run" for line in skipped]
if cells is None or matrix_exit not in (0, 1) or not cells:
lines.append("- manifest: none" if cells is None else "- manifest: written by a run that did not finish")
return lines, problems + [f"matrix: the matrix did not complete (exit {matrix_exit})"]
counts = {status: sorted(cell for cell, value in cells.items() if value["status"] == status) for status in STATUSES}
clients = {client for client, _ in cells}
lines.append(f"- {len(clients)} clients x {len({scenario for _, scenario in cells})} scenarios: "
+ ", ".join(f"{status} {len(counts[status])}" for status in STATUSES))
for status in ("fail", "sut-unregistered"):
for client, scenario in counts[status]:
lines.append(f"- {status}: `{client}` / `{scenario}`: {cells[(client, scenario)].get('detail') or ''}")
problems.append(f"matrix: {client}/{scenario} is {status}")
return lines, problems
def main(argv=None):
argv = sys.argv[1:] if argv is None else argv
if argv == ["--self-test"]:
suite = unittest.defaultTestLoader.loadTestsFromTestCase(SelfTest)
return 0 if unittest.TextTestRunner(verbosity=1).run(suite).wasSuccessful() else 1
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
commands = parser.add_subparsers(dest="command", required=True)
one = commands.add_parser("check")
one.add_argument("--run-dir", required=True)
args = parser.parse_args(argv)
try:
lines, problems = check(args.run_dir)
except InputError as error:
print(f"error: {error}", file=sys.stderr)
return 2
print("\n".join(lines))
for problem in problems:
print(f"::error::{problem}", file=sys.stderr)
return 1 if problems else 0
class SelfTest(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory()
self.addCleanup(temporary.cleanup)
self.dir = Path(temporary.name)
def write_run(self, directory, cells, startup="ready", matrix_exit="0", skipped=""):
write_served(directory, startup)
(directory / "skipped-clients.txt").write_text(skipped)
if matrix_exit is not None:
(directory / "matrix-exit.txt").write_text(matrix_exit + "\n")
if cells is not None:
clients = {}
for (client, scenario), status in cells.items():
clients.setdefault(client, []).append({"id": scenario, "status": status, "detail": "d"})
(directory / "compat").mkdir(exist_ok=True)
(directory / "compat/matrix.json").write_text(json.dumps(
{"clients": [{"name": name, "scenarios": scenarios} for name, scenarios in clients.items()]}))
return directory
def checked(self, **kwargs):
return check(self.write_run(self.dir, **kwargs))
def test_pass_and_client_unsupported_cells_are_clean(self):
lines, problems = self.checked(cells={("boto3", "a"): "pass", ("restic", "a"): "client-unsupported"})
self.assertEqual(problems, [])
self.assertIn("- 2 clients x 1 scenarios: pass 1, fail 0, client-unsupported 1, sut-unregistered 0", lines)
def test_a_failed_cell_is_red(self):
self.assertEqual(self.checked(cells={("boto3", "a"): "fail"}, matrix_exit="1")[1], ["matrix: boto3/a is fail"])
def test_an_unregistered_cell_is_red(self):
self.assertEqual(self.checked(cells={("mc", "a"): "sut-unregistered"})[1], ["matrix: mc/a is sut-unregistered"])
def test_a_client_that_could_not_be_installed_is_skipped_never_passed(self):
lines, problems = self.checked(cells={("boto3", "a"): "pass"}, skipped="restic: skipped: go is not on PATH\n")
self.assertIn("- restic: skipped: go is not on PATH", lines)
self.assertEqual(problems, ["matrix: client restic did not run"])
def test_a_server_that_did_not_start_is_red_and_says_why(self):
lines, problems = self.checked(cells=None, matrix_exit=None, startup="did not start: refused")
self.assertIn("- server: did not start: refused", lines)
self.assertEqual(problems, ["matrix: the server did not serve; no client ran"])
def test_an_environment_exit_is_red_even_with_a_manifest(self):
self.assertEqual(self.checked(cells={("boto3", "a"): "pass"}, matrix_exit="3")[1],
["matrix: the matrix did not complete (exit 3)"])
def test_a_missing_manifest_is_red_even_when_the_exit_was_swallowed(self):
self.assertEqual(self.checked(cells=None)[1], ["matrix: the matrix did not complete (exit 0)"])
def test_a_swallowed_exit_cannot_hide_a_failed_cell(self):
self.assertEqual(self.checked(cells={("boto3", "a"): "fail"}, matrix_exit="0")[1], ["matrix: boto3/a is fail"])
def test_an_unknown_status_is_refused(self):
with self.assertRaises(InputError):
self.checked(cells={("boto3", "a"): "passed"})
if __name__ == "__main__":
sys.exit(main())