| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- """Queue/workflow integration with a console and thermal device but no IPMI."""
- import asyncio
- import copy
- from pathlib import Path
- from unittest.mock import patch
- import uuid
- import pytest
- from stl_backend.config import load_settings
- from stl_backend.devices import SimulatedDevice
- from stl_backend.engine import Bench
- ROOT = Path(__file__).resolve().parents[1]
- class WithoutBmc(SimulatedDevice):
- def __init__(self, config):
- super().__init__(config)
- self.bmc_calls = []
- async def bmc_read(self):
- self.bmc_calls.append("read")
- raise AssertionError("No IPMI read should occur")
- async def bmc_power(self, action):
- self.bmc_calls.append(action)
- raise AssertionError("No IPMI power operation should occur")
- async def operator_boot(self):
- """The test operator presses the physical power button."""
- self._reset_boot_context()
- self.host = "on"
- self._stage_cpu = 0
- self._spawn(self._boot())
- async def until(predicate, seconds=4):
- async with asyncio.timeout(seconds):
- while not predicate():
- await asyncio.sleep(0.005)
- async def make_bench(tmp_path, hold_after_boot=False):
- settings = load_settings(ROOT / "config/simulated.json")
- settings["data_dir"] = str(tmp_path / "data")
- settings["telemetry_interval_s"] = 0.02
- settings["stations"] = settings["stations"][:1]
- settings["stations"][0].update(bmc={"enabled": False}, simulation={"step_delay_s": 0.005, "mt_duration_s": 0.02})
- recipe = settings["recipes"][0]
- recipe.update(preheat_air_c=20, preheat_hold_s=0, preheat_timeout_s=2,
- phase_timeout_s=3, finish_timeout_s=1, stage1_commands=[])
- profile = settings["profiles"][recipe["profile_id"]]
- for step in profile["steps"]:
- step["interval_s"] = 0
- if hold_after_boot:
- profile["steps"] = [
- {"id": "observe_uip", "expect": r"\[0\]\[CxmtDdrTest\]Current stage is 1",
- "expect_from_start": True},
- {"id": "hold", "manual": True, "instruction": "Wait for the test operator"},
- *profile["steps"],
- ]
- bench = Bench(copy.deepcopy(settings))
- with patch("stl_backend.engine.create_device", WithoutBmc):
- await bench.initialize()
- return bench, recipe
- async def enqueue(bench, method, arguments):
- return await bench.enqueue_command({"command_id": "test-" + uuid.uuid4().hex,
- "station_id": "S1", "method": method, "arguments": arguments, "operator": "test-operator"})
- async def start(bench, recipe):
- item = await enqueue(bench, "StartRun", {
- "recipe_id": recipe["recipe_id"], "work_order": "WO-no-bmc", "batch_no": "B-no-bmc",
- "dimms": [{"sn": "MANUAL-BOOT-SN", "slot": "A1", "cpu": 0, "channel": "A"}],
- })
- rt = bench.station("S1")
- await until(lambda: rt.snapshot["pending_step_id"] == "host_power_on")
- return item, rt
- async def queue_terminal(bench, command_id):
- async with asyncio.timeout(4):
- while True:
- item = await bench.command_queue.storage.get(command_id)
- if item["state"] in ("succeeded", "failed", "interrupted"):
- return item
- await asyncio.sleep(0.005)
- async def test_no_bmc_manual_start_uses_existing_confirmation_queue_and_keeps_power_unknown(tmp_path):
- bench, recipe = await make_bench(tmp_path, hold_after_boot=True)
- try:
- item, rt = await start(bench, recipe)
- run_id = rt.run["run_id"]
- assert rt.run["evidence"]["preheat_met"]
- assert rt.snapshot["sol_state"] == "online"
- assert rt.snapshot["bmc_state"] == "disabled"
- assert rt.snapshot["server_power"] == "unknown"
- assert (await bench.command_queue.storage.get(item["command_id"]))["state"] == "running"
- await rt.device.operator_boot()
- confirmation = await enqueue(bench, "ConfirmStage", {
- "run_id": run_id, "step_id": "host_power_on", "succeeded": True,
- "evidence": "Operator sees BIOS output after pressing the physical button",
- })
- assert (await queue_terminal(bench, confirmation["command_id"]))["state"] == "succeeded"
- await until(lambda: rt.snapshot["pending_step_id"] == "hold")
- assert (await queue_terminal(bench, item["command_id"]))["state"] == "succeeded"
- assert rt.snapshot["server_power"] == "unknown"
- assert rt.run["evidence"]["host_power_on"]["confirmation"] == "operator"
- assert rt.run["evidence"]["host_power_on"]["bmc_readback"] == "unavailable"
- stopped = await enqueue(bench, "StopRun", {"run_id": run_id, "reason": "test complete"})
- assert (await queue_terminal(bench, stopped["command_id"]))["state"] == "succeeded"
- result = await bench.store.get_run(run_id)
- assert result["state"] == "stopped"
- assert result["supply_state"] == "off"
- assert rt.snapshot["bmc_state"] == "disabled"
- assert rt.device.bmc_calls == []
- finally:
- await bench.close()
- async def test_no_bmc_stop_can_interrupt_wait_for_manual_host_power(tmp_path):
- bench, recipe = await make_bench(tmp_path)
- try:
- item, rt = await start(bench, recipe)
- run_id = rt.run["run_id"]
- stopped = await enqueue(bench, "StopRun", {"run_id": run_id, "reason": "stop before power button"})
- assert (await queue_terminal(bench, stopped["command_id"]))["state"] == "succeeded"
- assert (await queue_terminal(bench, item["command_id"]))["state"] == "failed"
- result = await bench.store.get_run(run_id)
- assert result["state"] == "stopped" and result["supply_state"] == "off"
- assert "host_power_on" not in result["evidence"]
- assert rt.device.bmc_calls == []
- finally:
- await bench.close()
- async def test_no_bmc_normal_run_completes_and_turns_whole_supply_off(tmp_path):
- bench, recipe = await make_bench(tmp_path)
- try:
- item, rt = await start(bench, recipe)
- run_id = rt.run["run_id"]
- await rt.device.operator_boot()
- await enqueue(bench, "ConfirmStage", {"run_id": run_id, "step_id": "host_power_on",
- "succeeded": True, "evidence": "Physical power button; BIOS seen"})
- assert (await queue_terminal(bench, item["command_id"]))["state"] == "succeeded"
- await asyncio.wait_for(asyncio.shield(rt.task), 4)
- result = await bench.store.get_run(run_id)
- assert result["workflow_complete"]
- assert result["state"] == "completed" and result["supply_state"] == "off"
- assert all(state == "completed" for state in result["tests"].values())
- assert result["evidence"]["host_power_on"]["bmc_readback"] == "unavailable"
- assert rt.device.bmc_calls == []
- finally:
- await bench.close()
|