test_optional_bmc_workflow.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. """Queue/workflow integration with a console and thermal device but no IPMI."""
  2. import asyncio
  3. import copy
  4. from pathlib import Path
  5. from unittest.mock import patch
  6. import uuid
  7. import pytest
  8. from stl_backend.config import load_settings
  9. from stl_backend.devices import SimulatedDevice
  10. from stl_backend.engine import Bench
  11. ROOT = Path(__file__).resolve().parents[1]
  12. class WithoutBmc(SimulatedDevice):
  13. def __init__(self, config):
  14. super().__init__(config)
  15. self.bmc_calls = []
  16. async def bmc_read(self):
  17. self.bmc_calls.append("read")
  18. raise AssertionError("No IPMI read should occur")
  19. async def bmc_power(self, action):
  20. self.bmc_calls.append(action)
  21. raise AssertionError("No IPMI power operation should occur")
  22. async def operator_boot(self):
  23. """The test operator presses the physical power button."""
  24. self._reset_boot_context()
  25. self.host = "on"
  26. self._stage_cpu = 0
  27. self._spawn(self._boot())
  28. async def until(predicate, seconds=4):
  29. async with asyncio.timeout(seconds):
  30. while not predicate():
  31. await asyncio.sleep(0.005)
  32. async def make_bench(tmp_path, hold_after_boot=False):
  33. settings = load_settings(ROOT / "config/simulated.json")
  34. settings["data_dir"] = str(tmp_path / "data")
  35. settings["telemetry_interval_s"] = 0.02
  36. settings["stations"] = settings["stations"][:1]
  37. settings["stations"][0].update(bmc={"enabled": False}, simulation={"step_delay_s": 0.005, "mt_duration_s": 0.02})
  38. recipe = settings["recipes"][0]
  39. recipe.update(preheat_air_c=20, preheat_hold_s=0, preheat_timeout_s=2,
  40. phase_timeout_s=3, finish_timeout_s=1, stage1_commands=[])
  41. profile = settings["profiles"][recipe["profile_id"]]
  42. for step in profile["steps"]:
  43. step["interval_s"] = 0
  44. if hold_after_boot:
  45. profile["steps"] = [
  46. {"id": "observe_uip", "expect": r"\[0\]\[CxmtDdrTest\]Current stage is 1",
  47. "expect_from_start": True},
  48. {"id": "hold", "manual": True, "instruction": "Wait for the test operator"},
  49. *profile["steps"],
  50. ]
  51. bench = Bench(copy.deepcopy(settings))
  52. with patch("stl_backend.engine.create_device", WithoutBmc):
  53. await bench.initialize()
  54. return bench, recipe
  55. async def enqueue(bench, method, arguments):
  56. return await bench.enqueue_command({"command_id": "test-" + uuid.uuid4().hex,
  57. "station_id": "S1", "method": method, "arguments": arguments, "operator": "test-operator"})
  58. async def start(bench, recipe):
  59. item = await enqueue(bench, "StartRun", {
  60. "recipe_id": recipe["recipe_id"], "work_order": "WO-no-bmc", "batch_no": "B-no-bmc",
  61. "dimms": [{"sn": "MANUAL-BOOT-SN", "slot": "A1", "cpu": 0, "channel": "A"}],
  62. })
  63. rt = bench.station("S1")
  64. await until(lambda: rt.snapshot["pending_step_id"] == "host_power_on")
  65. return item, rt
  66. async def queue_terminal(bench, command_id):
  67. async with asyncio.timeout(4):
  68. while True:
  69. item = await bench.command_queue.storage.get(command_id)
  70. if item["state"] in ("succeeded", "failed", "interrupted"):
  71. return item
  72. await asyncio.sleep(0.005)
  73. async def test_no_bmc_manual_start_uses_existing_confirmation_queue_and_keeps_power_unknown(tmp_path):
  74. bench, recipe = await make_bench(tmp_path, hold_after_boot=True)
  75. try:
  76. item, rt = await start(bench, recipe)
  77. run_id = rt.run["run_id"]
  78. assert rt.run["evidence"]["preheat_met"]
  79. assert rt.snapshot["sol_state"] == "online"
  80. assert rt.snapshot["bmc_state"] == "disabled"
  81. assert rt.snapshot["server_power"] == "unknown"
  82. assert (await bench.command_queue.storage.get(item["command_id"]))["state"] == "running"
  83. await rt.device.operator_boot()
  84. confirmation = await enqueue(bench, "ConfirmStage", {
  85. "run_id": run_id, "step_id": "host_power_on", "succeeded": True,
  86. "evidence": "Operator sees BIOS output after pressing the physical button",
  87. })
  88. assert (await queue_terminal(bench, confirmation["command_id"]))["state"] == "succeeded"
  89. await until(lambda: rt.snapshot["pending_step_id"] == "hold")
  90. assert (await queue_terminal(bench, item["command_id"]))["state"] == "succeeded"
  91. assert rt.snapshot["server_power"] == "unknown"
  92. assert rt.run["evidence"]["host_power_on"]["confirmation"] == "operator"
  93. assert rt.run["evidence"]["host_power_on"]["bmc_readback"] == "unavailable"
  94. stopped = await enqueue(bench, "StopRun", {"run_id": run_id, "reason": "test complete"})
  95. assert (await queue_terminal(bench, stopped["command_id"]))["state"] == "succeeded"
  96. result = await bench.store.get_run(run_id)
  97. assert result["state"] == "stopped"
  98. assert result["supply_state"] == "off"
  99. assert rt.snapshot["bmc_state"] == "disabled"
  100. assert rt.device.bmc_calls == []
  101. finally:
  102. await bench.close()
  103. async def test_no_bmc_stop_can_interrupt_wait_for_manual_host_power(tmp_path):
  104. bench, recipe = await make_bench(tmp_path)
  105. try:
  106. item, rt = await start(bench, recipe)
  107. run_id = rt.run["run_id"]
  108. stopped = await enqueue(bench, "StopRun", {"run_id": run_id, "reason": "stop before power button"})
  109. assert (await queue_terminal(bench, stopped["command_id"]))["state"] == "succeeded"
  110. assert (await queue_terminal(bench, item["command_id"]))["state"] == "failed"
  111. result = await bench.store.get_run(run_id)
  112. assert result["state"] == "stopped" and result["supply_state"] == "off"
  113. assert "host_power_on" not in result["evidence"]
  114. assert rt.device.bmc_calls == []
  115. finally:
  116. await bench.close()
  117. async def test_no_bmc_normal_run_completes_and_turns_whole_supply_off(tmp_path):
  118. bench, recipe = await make_bench(tmp_path)
  119. try:
  120. item, rt = await start(bench, recipe)
  121. run_id = rt.run["run_id"]
  122. await rt.device.operator_boot()
  123. await enqueue(bench, "ConfirmStage", {"run_id": run_id, "step_id": "host_power_on",
  124. "succeeded": True, "evidence": "Physical power button; BIOS seen"})
  125. assert (await queue_terminal(bench, item["command_id"]))["state"] == "succeeded"
  126. await asyncio.wait_for(asyncio.shield(rt.task), 4)
  127. result = await bench.store.get_run(run_id)
  128. assert result["workflow_complete"]
  129. assert result["state"] == "completed" and result["supply_state"] == "off"
  130. assert all(state == "completed" for state in result["tests"].values())
  131. assert result["evidence"]["host_power_on"]["bmc_readback"] == "unavailable"
  132. assert rt.device.bmc_calls == []
  133. finally:
  134. await bench.close()