mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-27 10:59:04 +00:00
250 lines
13 KiB
Python
Executable File
250 lines
13 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> [--gateway-dir <checkout>] [--server-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). The pinned
|
|
gateway checkout defaults to the lane's sibling `gateway` directory.
|
|
|
|
`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 tomllib
|
|
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"
|
|
if not manifest.is_file():
|
|
return None
|
|
cells = {}
|
|
clients = set()
|
|
try:
|
|
rows = json.loads(manifest.read_text(encoding="utf-8"))["clients"]
|
|
if not isinstance(rows, list):
|
|
raise InputError(f"{manifest}: expected a list of clients")
|
|
for client in rows:
|
|
name = client["name"]
|
|
if not isinstance(name, str) or not name or not isinstance(client["scenarios"], list) or not client["scenarios"]:
|
|
raise InputError(f"{manifest}: expected a named client with scenario rows")
|
|
if name in clients:
|
|
raise InputError(f"{manifest}: duplicate client {name}")
|
|
clients.add(name)
|
|
for scenario in client["scenarios"]:
|
|
case = scenario["id"]
|
|
if not isinstance(case, str) or not case or scenario.get("status") not in STATUSES:
|
|
raise InputError(f"{manifest}: invalid scenario id or status for {name}")
|
|
if (name, case) in cells:
|
|
raise InputError(f"{manifest}: duplicate cell {name}/{case}")
|
|
cells[name, case] = scenario
|
|
except (OSError, ValueError, KeyError, TypeError) as error:
|
|
raise InputError(f"{manifest}: not a client matrix manifest: {error}") from error
|
|
return cells
|
|
|
|
|
|
def expected_cells(gateway_dir):
|
|
compat = Path(gateway_dir) / "compat"
|
|
try:
|
|
with (compat / "versions.toml").open("rb") as versions:
|
|
clients = tomllib.load(versions)["clients"]
|
|
scenarios = {path.stem for path in (compat / "scenarios").glob("*.yaml") if path.is_file()}
|
|
except (OSError, KeyError, tomllib.TOMLDecodeError) as error:
|
|
raise InputError(f"{compat}: cannot read gateway matrix inventory: {error}") from error
|
|
if not isinstance(clients, dict) or not clients or not scenarios:
|
|
raise InputError(f"{compat}: empty or invalid gateway matrix inventory")
|
|
return {(client, scenario) for client in clients for scenario in scenarios}
|
|
|
|
|
|
def check(run_dir, gateway_dir=None, server_dir=None):
|
|
"""Return (summary lines, problems)."""
|
|
server, problem = served(run_dir if server_dir is None else server_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})"]
|
|
expected = expected_cells(gateway_dir if gateway_dir is not None else Path(run_dir).resolve().parent / "gateway")
|
|
skipped_clients = {line.split(":", 1)[0] for line in skipped}
|
|
problems.extend(f"matrix: missing cell {client}/{case}" for client, case in sorted(expected - cells.keys())
|
|
if client not in skipped_clients)
|
|
problems.extend(f"matrix: unexpected cell {client}/{case}" for client, case in sorted(cells.keys() - expected))
|
|
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)
|
|
one.add_argument("--server-dir", help="directory with a separate matrix server startup record")
|
|
one.add_argument("--gateway-dir", help="gateway checkout used to run this matrix")
|
|
args = parser.parse_args(argv)
|
|
try:
|
|
lines, problems = check(args.run_dir, args.gateway_dir, args.server_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) / "lane"
|
|
self.compat = self.dir.parent / "gateway/compat"
|
|
(self.compat / "scenarios").mkdir(parents=True)
|
|
(self.compat / "scenarios/a.yaml").touch()
|
|
(self.compat / "versions.toml").write_text("[clients.boto3]\n[clients.restic]\n")
|
|
|
|
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_missing_client_and_missing_scenario_are_red(self):
|
|
(self.compat / "scenarios/b.yaml").touch()
|
|
self.assertEqual(self.checked(cells={("boto3", "a"): "pass"})[1],
|
|
["matrix: missing cell boto3/b", "matrix: missing cell restic/a", "matrix: missing cell restic/b"])
|
|
|
|
def test_an_extra_cell_cannot_replace_a_missing_cell(self):
|
|
self.assertEqual(self.checked(cells={("boto3", "a"): "pass", ("restic", "other"): "pass"})[1],
|
|
["matrix: missing cell restic/a", "matrix: unexpected cell restic/other"])
|
|
|
|
def test_a_duplicate_cannot_overwrite_a_failure(self):
|
|
self.write_run(self.dir, {("boto3", "a"): "fail", ("restic", "a"): "pass"})
|
|
manifest = self.dir / "compat/matrix.json"
|
|
original = manifest.read_text()
|
|
row = {"id": "a", "status": "pass"}
|
|
for duplicate_client in (False, True):
|
|
with self.subTest(duplicate_client=duplicate_client):
|
|
data = json.loads(original)
|
|
if duplicate_client:
|
|
data["clients"].append({"name": "boto3", "scenarios": [row]})
|
|
else:
|
|
data["clients"][0]["scenarios"].append(row)
|
|
manifest.write_text(json.dumps(data))
|
|
with self.assertRaisesRegex(InputError, "duplicate"):
|
|
check(self.dir)
|
|
|
|
def test_a_missing_inventory_is_refused(self):
|
|
(self.compat / "versions.toml").unlink()
|
|
with self.assertRaisesRegex(InputError, "matrix inventory"):
|
|
self.checked(cells={("boto3", "a"): "pass"})
|
|
|
|
def test_a_failed_cell_is_red(self):
|
|
self.assertEqual(self.checked(cells={("boto3", "a"): "fail", ("restic", "a"): "pass"}, matrix_exit="1")[1], ["matrix: boto3/a is fail"])
|
|
|
|
def test_an_unregistered_cell_is_red(self):
|
|
self.assertEqual(self.checked(cells={("boto3", "a"): "pass", ("restic", "a"): "sut-unregistered"})[1],
|
|
["matrix: restic/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_separate_server_requires_its_own_ready_record(self):
|
|
run = self.write_run(self.dir, cells={("boto3", "a"): "pass", ("restic", "a"): "pass"})
|
|
server = run / "matrix-host"
|
|
self.assertEqual(check(run, server_dir=server)[1], ["matrix: the server did not serve; no client ran"])
|
|
write_served(server)
|
|
self.assertEqual(check(run, server_dir=server)[1], [])
|
|
|
|
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", ("restic", "a"): "pass"}, 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())
|