test_firmware_settings_inheritance.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. """Effective run settings include saved UI choices unless a recipe overrides them.
  2. The workflow is held at its boundary: these tests exercise real configuration
  3. persistence and run snapshots without booting a simulated or physical server.
  4. """
  5. from __future__ import annotations
  6. import copy
  7. from pathlib import Path
  8. from unittest.mock import AsyncMock
  9. import uuid
  10. import pytest
  11. import pytest_asyncio
  12. from stl_backend.config import load_settings
  13. from stl_backend.engine import Bench
  14. ROOT = Path(__file__).resolve().parents[1]
  15. SAVED_FIRMWARE = {
  16. "uip_overrides": [
  17. {"id": "errhandle", "mode": "override", "value": "disable"},
  18. {"id": "rmt", "mode": "override", "value": "disable"},
  19. ],
  20. "mt_selection": {
  21. "efi_path": r"FS0:\EFI\118.efi",
  22. "config_path": r"FS0:\EFI\default.cfg",
  23. "arguments": "--pass 1",
  24. "command_template": "{efi_path} {config_path} {arguments}",
  25. },
  26. }
  27. @pytest_asyncio.fixture
  28. async def bench(tmp_path):
  29. settings = load_settings(ROOT / "config/simulated.json")
  30. settings["data_dir"] = str(tmp_path)
  31. settings["stations"] = settings["stations"][:1]
  32. value = Bench(settings)
  33. await value.initialize()
  34. value.workflow.run = AsyncMock()
  35. try:
  36. yield value
  37. finally:
  38. await value.close()
  39. async def save_station_choices(bench):
  40. result = await bench.controls.save_firmware_settings({
  41. "station_id": "S1", **copy.deepcopy(SAVED_FIRMWARE)})
  42. assert result["hardware_written"] is False
  43. return result["firmware_settings"]
  44. async def start_with_firmware(bench, firmware):
  45. recipe = await bench.store.get_recipe("DEMO-80")
  46. recipe["firmware_settings"] = copy.deepcopy(firmware)
  47. await bench.store.put_recipe(recipe, recipe["revision"])
  48. command = await bench.start_run({
  49. "command_id": "inheritance-" + uuid.uuid4().hex,
  50. "station_id": "S1", "operator": "test", "recipe_id": "DEMO-80",
  51. "work_order": "WO-test", "batch_no": "B-test",
  52. "dimms": [{"sn": "fixture-SN", "slot": "A1", "cpu": 0, "channel": "A"}],
  53. })
  54. run = await bench.store.get_run(command["run_id"])
  55. # Resolving effective run settings must not rewrite the reusable recipe.
  56. assert (await bench.store.get_recipe("DEMO-80"))["firmware_settings"] == firmware
  57. return run["recipe"]
  58. @pytest.mark.parametrize("firmware", [
  59. {},
  60. {"uip_overrides": [], "mt_selection": {}},
  61. {"uip_overrides": [{"id": "rmt", "mode": "default"}], "mt_selection": {}},
  62. ])
  63. async def test_empty_or_default_recipe_inherits_saved_uip_and_mt(bench, firmware):
  64. saved = await save_station_choices(bench)
  65. recipe = await start_with_firmware(bench, firmware)
  66. assert recipe["firmware_settings"] == saved
  67. assert recipe["stage1_commands"] == ["errhandle disable", "rmt disable"]
  68. assert recipe["run_rmt"] is False
  69. assert recipe["mt_command"] == r"FS0:\EFI\118.efi FS0:\EFI\default.cfg --pass 1"
  70. @pytest.mark.parametrize(("firmware", "commands", "mt_command"), [
  71. ({"uip_overrides": [{"id": "rmt", "mode": "override", "value": "enable"}],
  72. "mt_selection": {}}, ["rmt enable"], "memtest.efi {run_id}"),
  73. ({"uip_overrides": [], "mt_selection": {"efi_path": r"FS0:\EFI\memtest86site.efi"}},
  74. [], r"FS0:\EFI\memtest86site.efi"),
  75. ])
  76. async def test_explicit_recipe_settings_win_as_a_whole(bench, firmware, commands, mt_command):
  77. saved = await save_station_choices(bench)
  78. recipe = await start_with_firmware(bench, firmware)
  79. assert recipe["firmware_settings"] == firmware
  80. assert recipe["stage1_commands"] == commands
  81. assert recipe["run_rmt"] is True
  82. assert recipe["mt_command"] == mt_command
  83. assert bench.control_settings.load("S1")["firmware_settings"] == saved
  84. async def test_no_station_or_recipe_override_keeps_bios_defaults(bench):
  85. recipe = await start_with_firmware(bench, {"uip_overrides": [], "mt_selection": {}})
  86. assert recipe["firmware_settings"] == {"uip_overrides": [], "uip_raw_commands": [], "mt_selection": {}}
  87. assert recipe["stage1_commands"] == []
  88. assert recipe["mt_command"] == "memtest.efi {run_id}"