vdi-cloud/docs/evidence/ubuntu-deep-latency-20261105/run-response.py

40 lines
1.9 KiB
Python

"""Run the controlled GTK response or native-cursor check via existing SSH credentials."""
import json
from pathlib import Path
import sys
import tempfile
import time
sys.path.insert(0, tempfile.gettempdir())
from vdi_ubuntu_remote import ROOT, box, guest, run
kind, name = sys.argv[1:3]
assert kind in ('response', 'cursor')
folder = ROOT / 'docs/evidence' / ('native-cursor-20261105' if kind == 'cursor' else 'ubuntu-deep-latency-20261105')
source = folder / ('source.py' if kind == 'cursor' else 'response-source.py')
probe = folder / ('probe.py' if kind == 'cursor' else 'response-probe.py')
g, b = guest(), box()
env = 'DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus '
unit = 'vdi-deep-response'
invocation = ''
try:
for client, local, remote in [(g, source, '/tmp/vdi-response-source.py'),
(b, probe, '/tmp/vdi-response-probe.py')]:
with client.open_sftp() as s:
s.put(str(local), remote)
started = run(g, env + 'systemd-run --user --unit=' + unit + ' --collect /usr/bin/python3 /tmp/vdi-response-source.py')
assert started['rc'] == 0, started
invocation = run(g, 'systemctl --user show ' + unit + ' -p InvocationID --value')['out'].strip()
time.sleep(4)
result = run(b, 'python3 /tmp/vdi-response-probe.py' + (' 192.168.1.72' if kind == 'cursor' else ''), 100)
if result['rc']:
raise RuntimeError(result)
data = json.loads(result['out'])
(Path(__file__).parent / (name + '.json')).write_text(json.dumps(data, indent=2), encoding='utf-8')
print(json.dumps(data, ensure_ascii=False))
finally:
print(run(g, env + 'systemctl --user stop ' + unit))
log = run(g, 'journalctl --user _SYSTEMD_INVOCATION_ID=' + invocation + ' --no-pager') if invocation else {'out': ''}
(Path(__file__).parent / (name + '-source.log')).write_text(log['out'], encoding='utf-8')
g.close()
b.close()