| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- """Regressions found in the first live handoff. No real device is contacted."""
- import asyncio
- import copy
- import json
- import os
- from pathlib import Path
- import sys
- import tempfile
- import unittest
- from unittest.mock import patch
- from stl_backend.config import load_settings
- from stl_backend.devices.hardware import HardwareDevice
- from stl_backend.engine import Bench
- from stl_backend.errors import BenchError
- from stl_backend.parsers import IncrementalSolParser
- ROOT = Path(__file__).resolve().parents[1]
- class HardwareReviewTests(unittest.IsolatedAsyncioTestCase):
- async def test_sdr_values_have_unknown_measurement_time_and_no_reading_is_not_empty_slot(self):
- class Device(HardwareDevice):
- async def _ipmi(self, *args):
- self.args = args
- return ('DIMM_CPU0_A_Temp | 98h | ok | 7.1 | 34 degrees C\n'
- 'DIMM_CPU0_B_Temp | 99h | ns | 7.1 | No Reading\n'
- 'CPU0_Temp | 9ah | ok | 7.1 | 52 degrees C\n')
- device = Device({"bmc": {"enabled": True, "host": "test-bmc"}})
- values = await device.read_bmc_dimms()
- self.assertEqual(device.args, ('sdr', 'type', 'Temperature'))
- self.assertEqual(len(values), 2)
- self.assertEqual(values[0]['value_c'], 34)
- self.assertEqual(values[0]['quality'], 'reported')
- self.assertGreater(values[0]['observed_unix_ms'], 0)
- self.assertEqual(values[1]['quality'], 'unavailable')
- self.assertNotIn('value_c', values[1])
- self.assertNotIn('present', values[1])
- async def test_idle_monitor_reads_only_and_start_without_thermal_is_rejected_before_run(self):
- class ReadOnlyDevice(HardwareDevice):
- async def bmc_read(self):
- return 'on'
- async def read_bmc_dimms(self):
- return [{'cpu': 0, 'channel': '0', 'slot': 'CPU0_A', 'source': 'bmc_sdr',
- 'value_c': 34, 'quality': 'unverified', 'observed_unix_ms': 0}]
- async def supply_set(self, on):
- raise AssertionError('A rejected run must not touch power')
- async def sol_start(self):
- raise AssertionError('Idle monitoring must never open SOL')
- with tempfile.TemporaryDirectory() as tmp:
- cfg = load_settings(ROOT / 'config/station0-live.json')
- cfg['data_dir'] = tmp
- with patch.dict(os.environ, {'STL_BMC_S1_PASSWORD': 'test-only'}), patch('stl_backend.engine.create_device', ReadOnlyDevice):
- bench = Bench(cfg)
- await bench.initialize()
- try:
- async with asyncio.timeout(1):
- while not bench.station('S1').snapshot['temperature']['dimms']:
- await asyncio.sleep(.01)
- snapshot = await bench.snapshot('S1')
- self.assertEqual(snapshot['bmc_state'], 'online')
- self.assertEqual(snapshot['server_power'], 'on')
- self.assertEqual(snapshot['temperature']['hood_air']['quality'], 'unknown')
- self.assertEqual(snapshot['sol_state'], 'offline')
- self.assertIn('温控板', snapshot['pending_instruction'])
- with self.assertRaisesRegex(BenchError, '温控板'):
- await bench.start_run({'command_id': 'incomplete-start', 'station_id': 'S1'})
- self.assertIsNone(bench.station('S1').run)
- self.assertEqual(await bench.store.unfinished_runs(), [])
- finally:
- await asyncio.wait_for(bench.close(), 2)
- async def test_sol_temperature_is_preserved_and_not_renewed_by_board_poll(self):
- with tempfile.TemporaryDirectory() as tmp:
- cfg = load_settings(ROOT / 'config/simulated.json')
- cfg['data_dir'] = tmp
- bench = Bench(cfg)
- await bench.initialize()
- try:
- rt = bench.station('S1')
- rt.run = {'run_id': 'R-test', 'dimms': [], 'tests': {}, 'verdict': 'pending', 'artifact_state': 'pending'}
- first = IncrementalSolParser().feed(b'[HD_RMTSensor]N0.C0.D0:42.5\r\n')[0]
- await bench._parsed_event(rt, first)
- before = copy.deepcopy(rt.snapshot['temperature']['dimms'][0])
- self.assertEqual(before['quality'], 'unavailable_in_phase')
- rt.uefi_ready = True
- bench._merge_sol_temperatures(rt)
- self.assertEqual(rt.snapshot['temperature']['dimms'][0]['quality'], 'unavailable_in_phase')
- rt.snapshot["sol_state"] = "online"
- for event in IncrementalSolParser().feed(b"UEFI Interactive Shell v2.2\nShell> \n"):
- await bench._parsed_event(rt, event)
- await bench._parsed_event(rt, first)
- valid = copy.deepcopy(rt.snapshot['temperature']['dimms'][0])
- self.assertEqual(valid['quality'], 'valid')
- rt.snapshot['temperature'].update(dimms=[], hood_air={'quality': 'read_error'})
- bench._merge_sol_temperatures(rt)
- self.assertEqual(rt.snapshot['temperature']['dimms'][0], valid)
- for item in rt.sol_temperatures.values():
- item['observed_unix_ms'] -= 60000
- bench._merge_sol_temperatures(rt)
- self.assertEqual(rt.snapshot['temperature']['dimms'][0]['quality'], 'stale')
- finally:
- rt.run = None
- await bench.close()
- async def test_live_profile_never_sends_unverified_commands(self):
- cfg = load_settings(ROOT / 'config/station0-live.json')
- profile = cfg['profiles']['cxmt-live-gnr']
- self.assertTrue(all(s.get('manual') for s in profile['steps']))
- self.assertTrue(all(not any(s.get(k) for k in ('send', 'use_stage1_commands', 'use_mt_command', 'append_enter')) for s in profile['steps']))
- self.assertEqual({s['test'] for s in profile['steps'] if 'test' in s}, {'rmt', 'amt', 'mt'})
- self.assertEqual(cfg['recipes'][0]['stage1_commands'], [])
- self.assertEqual(cfg['recipes'][0]['required_artifact_kinds'], ['memtest_html'])
- async def test_helper_requires_real_activation_and_password_is_not_in_argv(self):
- with tempfile.TemporaryDirectory() as tmp:
- stub = Path(tmp) / 'ipmitool'
- stub.write_text('#!/usr/bin/env python3\nimport os,sys,time\n'
- 'assert "-E" in sys.argv and "test-only-secret" not in sys.argv\n'
- 'assert os.environ["IPMI_PASSWORD"]=="test-only-secret"\n'
- 'time.sleep(.3)\n'
- 'os.write(1,b"[SOL Session operational. Use ~? for help]\\r\\nBIOS bytes")\n'
- 'os.write(1,os.read(0,8192))\n'
- 'time.sleep(30)\n')
- stub.chmod(0o755)
- env = dict(os.environ, PATH=tmp + os.pathsep + os.environ['PATH'],
- STL_SOL_HOST='example.invalid', STL_SOL_USER='test', STL_SOL_PASSWORD='test-only-secret')
- proc = await asyncio.create_subprocess_exec(sys.executable, str(ROOT / 'native/stl_sol_bridge.py'),
- stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, env=env)
- try:
- self.assertEqual(json.loads(await proc.stderr.readline())['event'], 'connecting')
- with self.assertRaises(asyncio.TimeoutError):
- await asyncio.wait_for(proc.stderr.readline(), .1)
- self.assertEqual(json.loads(await asyncio.wait_for(proc.stderr.readline(), 2))['event'], 'ready')
- self.assertEqual(await asyncio.wait_for(proc.stdout.readexactly(10), 2), b'BIOS bytes')
- proc.stdin.write(b'help\r')
- await proc.stdin.drain()
- self.assertEqual(await asyncio.wait_for(proc.stdout.readexactly(5), 2), b'help\r')
- finally:
- proc.terminate()
- await asyncio.wait_for(proc.wait(), 4)
- async def test_helper_reports_busy_instead_of_ready_or_takeover(self):
- with tempfile.TemporaryDirectory() as tmp:
- stub = Path(tmp) / 'ipmitool'
- stub.write_text('#!/usr/bin/env python3\nimport os,time\nos.write(1,b"SOL payload already active on another session\\n")\ntime.sleep(30)\n')
- stub.chmod(0o755)
- env = dict(os.environ, PATH=tmp + os.pathsep + os.environ['PATH'],
- STL_SOL_HOST='example.invalid', STL_SOL_USER='test', STL_SOL_PASSWORD='test-only')
- proc = await asyncio.create_subprocess_exec(sys.executable, str(ROOT / 'native/stl_sol_bridge.py'),
- stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, env=env)
- out, err = await asyncio.wait_for(proc.communicate(), 4)
- statuses = [json.loads(line) for line in err.splitlines()]
- self.assertEqual(out, b'')
- self.assertNotIn('ready', [s['event'] for s in statuses])
- self.assertEqual(statuses[-1], {'event': 'error', 'code': 1006})
- self.assertNotEqual(proc.returncode, 0)
|