fix(smoke): explicitly select known guest filesystems when mounting

This commit is contained in:
Codex
2026-10-13 22:29:17 +03:00
parent ec40a5a305
commit a77006a05f
2 changed files with 34 additions and 10 deletions
+10 -10
View File
@@ -138,10 +138,10 @@ def tree(path):
return {str(p.relative_to(path)): sha(p) for p in sorted(path.rglob('*')) if p.is_file()}
@contextlib.contextmanager
def mounted(device, options=''):
def mounted(device, filesystem, options=''):
import tempfile
with tempfile.TemporaryDirectory(prefix='hydra-acceptance-') as directory:
args = ['mount'] + (['-o', options] if options else []) + [device, directory]
args = ['mount', '-t', filesystem] + (['-o', options] if options else []) + [device, directory]
run(*args)
try: yield Path(directory)
finally: run('umount', directory)
@@ -149,7 +149,7 @@ def mounted(device, options=''):
def preserved():
table = json.loads(run('sfdisk', '--json', '/dev/vda'))['partitiontable']
# No filesystem UUIDs: selected root UUID must change on formatting.
with mounted('/dev/vda1', 'ro') as esp:
with mounted('/dev/vda1', 'vfat', 'ro') as esp:
foreign = {k: v for k, v in tree(esp / 'EFI').items() if not k.startswith('HydraOS/')}
order = re.search(r'^BootOrder:\s*(.*)$', run('efibootmgr'), re.M)
assert order, 'UEFI BootOrder was not observable'
@@ -213,7 +213,7 @@ run('udevadm', 'settle')
run('mkfs.vfat', '-F', '32', '/dev/vda1')
with open('/dev/vda2', 'r+b', buffering=0) as foreign:
foreign.write((context['sentinel'] * 1024).encode()); os.fsync(foreign.fileno())
with mounted('/dev/vda1') as esp:
with mounted('/dev/vda1', 'vfat') as esp:
for name in ('EFI/ForeignOS/loader.efi', 'EFI/BOOT/BOOTX64.EFI'):
path = esp / name; path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(context['sentinel'] + ':' + name)
@@ -242,16 +242,16 @@ with Path('/var/lib/portage/world').open('a') as world: world.write('# acceptanc
result = {'fixture_emerge': output, 'home': Path('/home/hydratest/acceptance-home').read_text()}
''',
'base-state': r'''
with mounted('/dev/vda3', 'ro,subvol=@root') as root:
with mounted('/dev/vda1', 'ro') as esp:
with mounted('/dev/vda3', 'btrfs', 'ro,subvol=@root') as root:
with mounted('/dev/vda1', 'vfat', 'ro') as esp:
result = base_state(root, esp)
''',
'damage': r'''
with mounted('/dev/vda3', 'subvol=@root') as root:
with mounted('/dev/vda3', 'btrfs', 'subvol=@root') as root:
kernels = list((root / 'boot').glob('vmlinuz*'))
assert kernels, 'No actual installed kernel to damage'
for kernel in kernels: kernel.write_bytes(b'DELIBERATE ACCEPTANCE KERNEL DAMAGE\n')
with mounted('/dev/vda1') as esp:
with mounted('/dev/vda1', 'vfat') as esp:
loader = esp / 'EFI/HydraOS/grubx64.efi'
assert loader.is_file(); loader.write_bytes(b'DELIBERATE ACCEPTANCE EFI DAMAGE\n')
run('sync')
@@ -263,7 +263,7 @@ assert marker['root_subvolume'] == '@root'
assert Path('/home/hydratest/acceptance-home').read_text() == 'current-' + context['sentinel']
assert not Path('/var/db/pkg/app-misc/hydra-acceptance-2.0').exists()
assert Path('/usr/share/hydra/base-fixture.txt').read_text().strip() == '1.0'
with mounted('/dev/vda1', 'ro') as esp: result = base_state(Path('/'), esp)
with mounted('/dev/vda1', 'vfat', 'ro') as esp: result = base_state(Path('/'), esp)
result['home'] = Path('/home/hydratest/acceptance-home').read_text()
result['vm_data'] = tree(Path('/home/hydratest/.local/share/hydra/acceptance-guest'))
result['root_mount'] = run('findmnt', '-n', '-o', 'SOURCE,OPTIONS', '/')
@@ -339,7 +339,7 @@ recovery.RecoverySession.save_journal = pause
raise SystemExit(recovery.main(ARGUMENTS))
""".replace('ARGUMENTS', repr(['restore', '--root-uuid', context['root_uuid'], '--checkpoint', context['checkpoint'], '--execute', '--confirm-root-uuid', context['root_uuid']]))
stop_child(source)
with mounted('/dev/vda3', 'ro,subvolid=5') as top:
with mounted('/dev/vda3', 'btrfs', 'ro,subvolid=5') as top:
journal = json.loads((top / '@snapshots/restore.json').read_text())
assert journal['phase'] == 'root-retained'
assert not (top / '@root').exists() and (top / journal['failed_root']).exists()