Files
fds-os/tests/integration/arch-package.py
T

38 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""Install the actual Arch package into a disposable pacman root, without host writes."""
from pathlib import Path
import json
import os
import subprocess
import tempfile
project=Path(__file__).resolve().parents[2]
package=Path((project/'out/workstation/package-path.txt').read_text().strip())
work=Path(tempfile.mkdtemp(prefix='arch-package-test.',dir=project/'out'))
root=work/'root';root.mkdir()
(root/'var/lib/pacman').mkdir(parents=True)
(root/'var/cache/pacman/pkg').mkdir(parents=True)
config=work/'pacman.conf'
config.write_text('[options]\nArchitecture = auto\nSigLevel = Never\nDownloadUser = root\n')
wrapper=work/'bin';wrapper.mkdir()
# Run the actual installer. In this private namespace it is already uid 0;
# redirect only pacman's installation root and disable dependency resolution.
(wrapper/'pacman').write_text('#!/bin/bash\nexec /usr/bin/pacman --config '+str(config)+' --root '+str(root)+' --dbpath '+str(root/'var/lib/pacman')+' --cachedir '+str(root/'var/cache/pacman/pkg')+' --logfile '+str(work/'pacman.log')+' --nodeps --nodeps --noconfirm "$@"\n')
(wrapper/'pacman').chmod(0o755)
command=['bwrap','--unshare-user','--uid','0','--gid','0','--ro-bind','/','/','--bind',str(work),str(work),'--dev','/dev','--proc','/proc','--setenv','PATH',str(wrapper)+':'+os.environ['PATH'],str(project/'tools/install-workstation')]
result=subprocess.run(command,capture_output=True,text=True)
(work/'install.log').write_text(result.stdout+result.stderr)
assert result.returncode==0,(result.stdout,result.stderr)
version=subprocess.check_output([str(project/'tools/version')],text=True).strip()
for tool in ['fds-cartridge','fds-emulator']:
output=subprocess.check_output([str(root/'usr/bin'/tool),'--version'],text=True).strip()
assert output==f'{tool} {version}',output
subprocess.run([str(root/'usr/bin'/tool),'--help'],check=True,stdout=subprocess.DEVNULL)
assert (root/'usr/share/doc/fds-tools/docs/workstation.md').is_file()
assert (root/'usr/share/licenses/fds-tools/RUST-NOTICES.txt').stat().st_size>0
installed=subprocess.check_output(['pacman','--config',str(config),'--root',str(root),'--dbpath',str(root/'var/lib/pacman'),'-Q','fds-tools'],text=True).strip()
assert installed==f'fds-tools {version}-1',installed
(work/'acceptance.json').write_text(json.dumps(dict(status='passed',package=str(package),installed=installed,installer='tools/install-workstation',host_install=False),indent=2)+'\n')
(project/'out/arch-package-current.txt').write_text(str(work)+'\n')
print('PASS: real pacman installation and both installed commands:',work)