|
|
@@ -18,7 +18,7 @@ from ..devices.base import DeviceError
|
|
|
import uuid
|
|
|
from ..domain.amt import normalize_amt_settings
|
|
|
from ..domain.stage_intents import STAGE_ORDER, apply_stage_intent_overwrite, default_stage_intents, stage_target_for_action
|
|
|
-from ..domain.firmware import build_mt_command, build_uip_commands
|
|
|
+from ..domain.firmware import build_mt86_cfg_lines, build_mt_command, build_uip_commands
|
|
|
from ..errors import BenchError, require
|
|
|
from ..store import now_ms
|
|
|
from .qt_projection import project_event, _safe_message, _ANSI
|
|
|
@@ -63,9 +63,15 @@ def memory_overrides(values, *, run_rmt=None):
|
|
|
return result
|
|
|
|
|
|
|
|
|
+_MT_ALLOWED_KEYS = frozenset({
|
|
|
+ "efi_path", "config_path", "arguments", "command_template",
|
|
|
+ "skip_tests", "only_tests", "memory_range", "addr_lim_lo", "addr_lim_hi", "exit_mode",
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
def normalize_qt_mt_selection(mt):
|
|
|
require(isinstance(mt, dict), "阶段配置必须是对象")
|
|
|
- require(not set(mt) - {"efi_path", "config_path", "arguments", "command_template", "skip_tests", "only_tests"}, "MT 包含未知字段")
|
|
|
+ require(not set(mt) - _MT_ALLOWED_KEYS, "MT 包含未知字段")
|
|
|
normalized = dict(mt)
|
|
|
efi_path = str(normalized.get("efi_path") or "").strip()
|
|
|
if not efi_path:
|
|
|
@@ -82,6 +88,7 @@ def normalize_qt_mt_selection(mt):
|
|
|
else:
|
|
|
normalized["config_path"] = cfg_name if ":" in config_path else config_path
|
|
|
normalized["command_template"] = "{efi_path} cfg={config_path} {arguments}"
|
|
|
+ build_mt86_cfg_lines(normalized)
|
|
|
cmd_part = {k: v for k, v in normalized.items() if k in ("efi_path", "config_path", "arguments", "command_template")}
|
|
|
build_mt_command(cmd_part)
|
|
|
return cmd_part
|
|
|
@@ -205,6 +212,11 @@ class QtCleanService:
|
|
|
}
|
|
|
fw = rt.diagnostic.firmware.snapshot(live=True, include_steps=True)
|
|
|
if fw.get("boot_id"):
|
|
|
+ live_parser = IncrementalSolParser(allow_simulated=False)
|
|
|
+ live_parser.line_no = getattr(parser, "line_no", 0)
|
|
|
+ rt.diagnostic.parser = live_parser
|
|
|
+ rt.diagnostic._restored_from_disk = True
|
|
|
+ self.pending_starts[sid] = True
|
|
|
self.records[sid] = {
|
|
|
"state": "running",
|
|
|
"started_unix_ms": int(fw.get("boot_started_unix_ms") or stamp),
|
|
|
@@ -304,7 +316,13 @@ class QtCleanService:
|
|
|
if available["skip_amt"]["available"]:
|
|
|
actions = ["skip_amt", "start_amt"]
|
|
|
elif ready and kind == "uefi" and not record.get("mt_skipped"):
|
|
|
- actions = ["start_mt", "skip_mt", "list_uefi_files"]
|
|
|
+ mt = firmware.get("mt_result", {})
|
|
|
+ mt_done = (
|
|
|
+ mt.get("status") in ("pass", "fail")
|
|
|
+ and mt.get("complete") is True
|
|
|
+ and (mt.get("observed_unix_ms") or 0) >= record.get("started_unix_ms", 0)
|
|
|
+ )
|
|
|
+ actions = ["list_uefi_files"] if mt_done else ["start_mt", "skip_mt", "list_uefi_files"]
|
|
|
actions = [action for action in actions if (node, action) not in self.consumed]
|
|
|
test_complete = bool(kind == "amt" and not firmware.get("boot_pending") and any(
|
|
|
row.get("cpu") == p.get("cpu") and row.get("status") == "pass" and row.get("verdict_supported")
|
|
|
@@ -595,6 +613,11 @@ class QtCleanService:
|
|
|
async def state(self, *, ws=None):
|
|
|
stations = []
|
|
|
for sid, rt in self.bench.runtimes.items():
|
|
|
+ if getattr(rt.diagnostic, "_restored_from_disk", False) and rt.diagnostic.state["state"] != "online":
|
|
|
+ try:
|
|
|
+ await rt.diagnostic.open()
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
fw, live = self._firmware(rt)
|
|
|
record = self.records.get(sid, {})
|
|
|
input_point, _ = self._input(rt, fw, live)
|
|
|
@@ -702,7 +725,7 @@ class QtCleanService:
|
|
|
require(isinstance(args.get("amt", {}), dict) and isinstance(args.get("mt", {}), dict), "阶段配置必须是对象")
|
|
|
require(not set(args.get("amt", {})) - {"overrides", "raw_commands", "test_command", "skip_tests", "only_tests", "fast_debug"},
|
|
|
"AMT 动作由 action 决定;amt 只包含配置覆盖和测试命令")
|
|
|
- require(not set(args.get("mt", {})) - {"efi_path", "config_path", "arguments", "command_template", "skip_tests", "only_tests"}, "MT 包含未知字段")
|
|
|
+ require(not set(args.get("mt", {})) - _MT_ALLOWED_KEYS, "MT 包含未知字段")
|
|
|
require(not args.get("amt") or args["action"] in ("start_amt", "skip_amt") or args.get("run_amt") is not None,
|
|
|
"AMT 配置只属于 start_amt/skip_amt")
|
|
|
require(not args.get("mt") or args["action"] in ("start_mt", "skip_mt") or args.get("run_mt") is not None,
|
|
|
@@ -784,7 +807,7 @@ class QtCleanService:
|
|
|
async with rt.io_lock:
|
|
|
previous = await asyncio.wait_for(rt.device.bmc_read(), 15)
|
|
|
require(previous in ("on", "off"), "无法确定服务器开关机状态,未发送电源操作", "FAILED_PRECONDITION")
|
|
|
- if rt.diagnostic.state["state"] != "online":
|
|
|
+ if not rt.diagnostic.active:
|
|
|
await rt.diagnostic.open()
|
|
|
old_boot = rt.diagnostic.firmware.boot_id
|
|
|
action = "host_on" if previous == "off" else "host_reset"
|
|
|
@@ -872,6 +895,21 @@ class QtCleanService:
|
|
|
steps.append({"command": cd_cmd, "output": out_cd[-4096:], "prompt_observed": ok_cd})
|
|
|
require(ok_cd and not _COMMAND_ERROR.search(out_cd),
|
|
|
"EFI 程序启动返回错误:" + out_cd[-600:], "FAILED_PRECONDITION")
|
|
|
+ saved_mt = self.bench.control_settings.load(context["station_id"]).get("firmware_settings", {}).get("mt_selection", {})
|
|
|
+ merged_cfg = {**saved_mt, **(mt or {})}
|
|
|
+ explicit_cfg = any(
|
|
|
+ k in merged_cfg and merged_cfg[k] not in (None, "", [])
|
|
|
+ for k in ("memory_range", "addr_lim_lo", "addr_lim_hi", "exit_mode", "only_tests", "skip_tests")
|
|
|
+ )
|
|
|
+ if filename.lower() == "118.efi" and (not rt.device.simulated or explicit_cfg):
|
|
|
+ cfg_lines = build_mt86_cfg_lines(merged_cfg)
|
|
|
+ for idx, cfg_line in enumerate(cfg_lines):
|
|
|
+ redir = ">a" if idx == 0 else ">>a"
|
|
|
+ echo_cmd = f"echo {cfg_line} {redir} mt86.cfg"
|
|
|
+ offset = console.offset()
|
|
|
+ await console.send(echo_cmd)
|
|
|
+ out_cfg, ok_cfg = await console.wait_output(offset, prompt=_UEFI_PROMPT, timeout=4)
|
|
|
+ steps.append({"command": echo_cmd, "output": out_cfg[-4096:], "prompt_observed": ok_cfg})
|
|
|
offset = console.offset()
|
|
|
await console.send(command)
|
|
|
output, received = await console.wait_output(offset, timeout=2)
|
|
|
@@ -889,7 +927,6 @@ class QtCleanService:
|
|
|
if _COMMAND_ERROR.search(output):
|
|
|
result["confirmation"] = "rejected"
|
|
|
raise BenchError("FAILED_PRECONDITION", "EFI 程序启动返回错误:" + output[-600:])
|
|
|
- saved_mt = self.bench.control_settings.load(context["station_id"]).get("firmware_settings", {}).get("mt_selection", {})
|
|
|
only_mt = (mt or {}).get("only_tests") if (mt and "only_tests" in mt) else (saved_mt.get("only_tests") or [])
|
|
|
skip_mt = (mt or {}).get("skip_tests") if (mt and "skip_tests" in mt) else (saved_mt.get("skip_tests") or [])
|
|
|
if only_mt or skip_mt:
|