|
@@ -222,8 +222,9 @@ class QtCleanService:
|
|
|
return cid if cid else ws
|
|
return cid if cid else ws
|
|
|
|
|
|
|
|
def release_owner(self, ws):
|
|
def release_owner(self, ws):
|
|
|
|
|
+ token = self._owner_token(ws)
|
|
|
for sid, owner in list(self.owners.items()):
|
|
for sid, owner in list(self.owners.items()):
|
|
|
- if owner is ws:
|
|
|
|
|
|
|
+ if owner is ws or (token is not None and owner == token):
|
|
|
self.owners.pop(sid, None)
|
|
self.owners.pop(sid, None)
|
|
|
|
|
|
|
|
def _is_foreign_owner(self, sid, ws, *, current_state=None):
|
|
def _is_foreign_owner(self, sid, ws, *, current_state=None):
|
|
@@ -613,19 +614,21 @@ class QtCleanService:
|
|
|
if fw.get("boot_pending"):
|
|
if fw.get("boot_pending"):
|
|
|
phase = "boot"
|
|
phase = "boot"
|
|
|
if record.get("boot_id") and fw.get("boot_id") != record["boot_id"] and state != "starting":
|
|
if record.get("boot_id") and fw.get("boot_id") != record["boot_id"] and state != "starting":
|
|
|
- state, verdict = "failed", "unknown"
|
|
|
|
|
- record["state"] = "failed"
|
|
|
|
|
- input_point["ready"], input_point["actions"] = False, []
|
|
|
|
|
|
|
+ if self.bench.controls.boot_plans.active(sid):
|
|
|
|
|
+ record["boot_id"] = fw.get("boot_id", "")
|
|
|
|
|
+ record["started_unix_ms"] = int(fw.get("boot_started_unix_ms") or now_ms())
|
|
|
|
|
+ state = "running"
|
|
|
|
|
+ record["state"] = "running"
|
|
|
|
|
+ else:
|
|
|
|
|
+ state, verdict = "failed", "unknown"
|
|
|
|
|
+ record["state"] = "failed"
|
|
|
|
|
+ input_point["ready"], input_point["actions"] = False, []
|
|
|
foreign = self._is_foreign_owner(sid, ws, current_state=state)
|
|
foreign = self._is_foreign_owner(sid, ws, current_state=state)
|
|
|
if foreign:
|
|
if foreign:
|
|
|
input_point = {**input_point, "ready": False, "actions": []}
|
|
input_point = {**input_point, "ready": False, "actions": []}
|
|
|
command = {"command_id": "", "state": "", "action": "", "error": None, "result": {}}
|
|
command = {"command_id": "", "state": "", "action": "", "error": None, "result": {}}
|
|
|
if sid in self.last_commands:
|
|
if sid in self.last_commands:
|
|
|
command = clean_command(await self.bench.get_queue_item(self.last_commands[sid]))
|
|
command = clean_command(await self.bench.get_queue_item(self.last_commands[sid]))
|
|
|
- pending = False
|
|
|
|
|
- if sid in self.pending_starts:
|
|
|
|
|
- pending_item = await self.bench.get_queue_item(self.pending_starts[sid])
|
|
|
|
|
- pending = pending_item["state"] not in ("succeeded", "failed", "interrupted")
|
|
|
|
|
temperatures = self._temperatures(rt, fw, record, started, live)
|
|
temperatures = self._temperatures(rt, fw, record, started, live)
|
|
|
channels = self._channels(rt, fw, rt.firmware if rt.run else rt.diagnostic.firmware,
|
|
channels = self._channels(rt, fw, rt.firmware if rt.run else rt.diagnostic.firmware,
|
|
|
record, started, temperatures)
|
|
record, started, temperatures)
|
|
@@ -639,9 +642,7 @@ class QtCleanService:
|
|
|
"verdict": verdict, "verdict_scope": verdict_scope,
|
|
"verdict": verdict, "verdict_scope": verdict_scope,
|
|
|
"input": input_point, "command": command, "channels": channels,
|
|
"input": input_point, "command": command, "channels": channels,
|
|
|
"stage_errors": stage_errors,
|
|
"stage_errors": stage_errors,
|
|
|
- "can_start": bool(not foreign and rt.device.capabilities().get("bmc_power") and rt.device.capabilities().get("console")
|
|
|
|
|
- and not pending and not rt.run and not rt.finishing
|
|
|
|
|
- and not rt.diagnostic_operation and not self.bench.controls.boot_plans.active(sid))})
|
|
|
|
|
|
|
+ "can_start": bool(rt.device.capabilities().get("bmc_power") and rt.device.capabilities().get("console"))})
|
|
|
return {"version": __version__, "mode": self.bench.settings["mode"], "server_id": self.bench.server_id,
|
|
return {"version": __version__, "mode": self.bench.settings["mode"], "server_id": self.bench.server_id,
|
|
|
"stations": stations}
|
|
"stations": stations}
|
|
|
|
|
|
|
@@ -715,13 +716,17 @@ class QtCleanService:
|
|
|
or args["action"] in ("continue_uip", "apply_uip"), "内存参数只属于 UIP 动作")
|
|
or args["action"] in ("continue_uip", "apply_uip"), "内存参数只属于 UIP 动作")
|
|
|
sid, command_id = params["station_id"], params["command_id"]
|
|
sid, command_id = params["station_id"], params["command_id"]
|
|
|
async with self.enqueue_locks[sid]:
|
|
async with self.enqueue_locks[sid]:
|
|
|
- require(not self._is_foreign_owner(sid, ws),
|
|
|
|
|
- "当前工位正由另一客户端执行测试,请等待完成或结束后操作", "FAILED_PRECONDITION")
|
|
|
|
|
- pending_id = self.pending_starts.get(sid)
|
|
|
|
|
- if method == "StartTest" and pending_id and pending_id != command_id:
|
|
|
|
|
- pending = await self.bench.get_queue_item(pending_id)
|
|
|
|
|
- require(pending["state"] in ("succeeded", "failed", "interrupted"),
|
|
|
|
|
- "开始测试操作仍在执行,请等待新的 BIOS 启动结果", "FAILED_PRECONDITION")
|
|
|
|
|
|
|
+ if method == "StartTest":
|
|
|
|
|
+ try:
|
|
|
|
|
+ existing = await self.bench.command_queue.storage.get(command_id)
|
|
|
|
|
+ except BenchError:
|
|
|
|
|
+ existing = None
|
|
|
|
|
+ if existing is None:
|
|
|
|
|
+ await self._preempt_station_for_start(sid, self._runtime(sid))
|
|
|
|
|
+ await self.bench.command_queue.preempt_station(sid)
|
|
|
|
|
+ else:
|
|
|
|
|
+ require(not self._is_foreign_owner(sid, ws),
|
|
|
|
|
+ "当前工位正由另一客户端执行测试,请等待完成或结束后操作", "FAILED_PRECONDITION")
|
|
|
item = await self.bench.enqueue_command({"command_id": command_id, "station_id": sid,
|
|
item = await self.bench.enqueue_command({"command_id": command_id, "station_id": sid,
|
|
|
"method": "QtStartTest" if method == "StartTest" else "QtStageAction", "operator": "qt", "arguments": args})
|
|
"method": "QtStartTest" if method == "StartTest" else "QtStageAction", "operator": "qt", "arguments": args})
|
|
|
self.last_commands[sid] = command_id
|
|
self.last_commands[sid] = command_id
|
|
@@ -733,6 +738,25 @@ class QtCleanService:
|
|
|
self.owners.pop(sid, None)
|
|
self.owners.pop(sid, None)
|
|
|
return clean_command(item)
|
|
return clean_command(item)
|
|
|
|
|
|
|
|
|
|
+ async def _preempt_station_for_start(self, sid, rt):
|
|
|
|
|
+ watcher = self.intent_watchers.pop(sid, None)
|
|
|
|
|
+ if watcher and not watcher.done():
|
|
|
|
|
+ watcher.cancel()
|
|
|
|
|
+ await asyncio.gather(watcher, return_exceptions=True)
|
|
|
|
|
+ if self.bench.controls.boot_plans.active(sid):
|
|
|
|
|
+ await self.bench.controls.boot_plans.stop_station(sid)
|
|
|
|
|
+ if rt.run is not None or (rt.task and not rt.task.done()):
|
|
|
|
|
+ rt.stop_reason = "operator_restarted"
|
|
|
|
|
+ rt.stop.set()
|
|
|
|
|
+ rt.wake.set()
|
|
|
|
|
+ if rt.task and not rt.task.done():
|
|
|
|
|
+ rt.task.cancel()
|
|
|
|
|
+ await asyncio.gather(rt.task, return_exceptions=True)
|
|
|
|
|
+ rt.run = None
|
|
|
|
|
+ rt.finishing = False
|
|
|
|
|
+ rt.pending_supply = None
|
|
|
|
|
+ rt.diagnostic_operation = False
|
|
|
|
|
+
|
|
|
async def _note(self, rt, message, severity="info"):
|
|
async def _note(self, rt, message, severity="info"):
|
|
|
await self.bench.event(rt, "qt_operation", severity, message, {},
|
|
await self.bench.event(rt, "qt_operation", severity, message, {},
|
|
|
phase=self._firmware(rt)[0].get("observed_phase", ""))
|
|
phase=self._firmware(rt)[0].get("observed_phase", ""))
|
|
@@ -740,11 +764,9 @@ class QtCleanService:
|
|
|
async def start_test(self, request):
|
|
async def start_test(self, request):
|
|
|
rt = self._runtime(request["station_id"])
|
|
rt = self._runtime(request["station_id"])
|
|
|
sid = request["station_id"]
|
|
sid = request["station_id"]
|
|
|
- require(rt.run is None and not rt.finishing and not rt.diagnostic_operation and rt.pending_supply is None,
|
|
|
|
|
- "工位已有测试或设备操作,当前不能开始", "FAILED_PRECONDITION")
|
|
|
|
|
- require(not self.bench.controls.boot_plans.active(sid), "完整接口的自动计划仍在运行", "FAILED_PRECONDITION")
|
|
|
|
|
require(rt.device.capabilities().get("bmc_power") and rt.device.capabilities().get("console"),
|
|
require(rt.device.capabilities().get("bmc_power") and rt.device.capabilities().get("console"),
|
|
|
"开始测试需要可用的主机电源控制和 BIOS 控制台", "FAILED_PRECONDITION")
|
|
"开始测试需要可用的主机电源控制和 BIOS 控制台", "FAILED_PRECONDITION")
|
|
|
|
|
+ await self._preempt_station_for_start(sid, rt)
|
|
|
tail = await self.bench.read_event_queue(0, sid, 1)
|
|
tail = await self.bench.read_event_queue(0, sid, 1)
|
|
|
record = {"state": "starting", "started_unix_ms": 0, "boot_id": "", "error_cursor": tail["latest_sequence"]}
|
|
record = {"state": "starting", "started_unix_ms": 0, "boot_id": "", "error_cursor": tail["latest_sequence"]}
|
|
|
self.records[sid] = record
|
|
self.records[sid] = record
|
|
@@ -805,6 +827,8 @@ class QtCleanService:
|
|
|
except (DeviceError, asyncio.TimeoutError) as exc:
|
|
except (DeviceError, asyncio.TimeoutError) as exc:
|
|
|
record["state"] = "failed"
|
|
record["state"] = "failed"
|
|
|
raise BenchError("UNAVAILABLE", "主机电源或控制台通信失败,请检查设备连接") from exc
|
|
raise BenchError("UNAVAILABLE", "主机电源或控制台通信失败,请检查设备连接") from exc
|
|
|
|
|
+ except asyncio.CancelledError:
|
|
|
|
|
+ raise
|
|
|
except BaseException:
|
|
except BaseException:
|
|
|
record["state"] = "failed"
|
|
record["state"] = "failed"
|
|
|
raise
|
|
raise
|
|
@@ -999,14 +1023,14 @@ class QtCleanService:
|
|
|
or (point["stage"] == "uefi" and input_id in self.uefi_tokens.get(node, set()))
|
|
or (point["stage"] == "uefi" and input_id in self.uefi_tokens.get(node, set()))
|
|
|
)
|
|
)
|
|
|
at_prompt = bool(point["ready"] and valid_token and action in point["actions"])
|
|
at_prompt = bool(point["ready"] and valid_token and action in point["actions"])
|
|
|
- if not input_id and rec_state in ("completed", "failed"):
|
|
|
|
|
|
|
+ if not input_id and (rec_state in ("idle", "completed", "failed") or sid not in self.pending_starts):
|
|
|
at_prompt = False
|
|
at_prompt = False
|
|
|
if not at_prompt and target_key in ("uip1", "amt", "mt"):
|
|
if not at_prompt and target_key in ("uip1", "amt", "mt"):
|
|
|
stale_boot_token = bool(input_id and input_id != point.get("id", ""))
|
|
stale_boot_token = bool(input_id and input_id != point.get("id", ""))
|
|
|
observed_stage = point["stage"] if point["ready"] else fw.get("observed_phase", "boot")
|
|
observed_stage = point["stage"] if point["ready"] else fw.get("observed_phase", "boot")
|
|
|
observed_order = STAGE_ORDER.get(observed_stage, 0)
|
|
observed_order = STAGE_ORDER.get(observed_stage, 0)
|
|
|
target_order = {"uip1": 1, "amt": 3, "mt": 5}[target_key]
|
|
target_order = {"uip1": 1, "amt": 3, "mt": 5}[target_key]
|
|
|
- pre_start = rec_state in ("idle", "completed", "failed")
|
|
|
|
|
|
|
+ pre_start = rec_state in ("idle", "completed", "failed") or sid not in self.pending_starts
|
|
|
cur_order = 0 if pre_start else (0 if rec_state == "starting" else observed_order)
|
|
cur_order = 0 if pre_start else (0 if rec_state == "starting" else observed_order)
|
|
|
if pre_start and intents[target_key]["consumed"]:
|
|
if pre_start and intents[target_key]["consumed"]:
|
|
|
intents[target_key]["consumed"] = False
|
|
intents[target_key]["consumed"] = False
|