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

51 lines
2.1 KiB
Python

"""Ubuntu-only recovery checks, using the existing kiosk entry and SSH identities."""
import json
from pathlib import Path
import sys
import tempfile
import time
sys.path.insert(0, tempfile.gettempdir())
from vdi_ubuntu_remote import box, guest, run
b, g = box(), guest()
benv = 'DISPLAY=:0 XAUTHORITY=/home/armbian/.Xauthority '
genv = 'DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority '
results = {}
def state():
r = run(g, 'systemctl --user show vdi-sunshine.service -p MainPID -p ExecStart -p ActiveState; '
'systemctl --user show vdi-native-cursor-guard.service -p ActiveState; '
'test ! -e /run/user/1000/systemd/user/vdi-sunshine.service.d/90-native-cursor.conf && echo no-dropin || true')
return r['out']
def connect():
assert run(b, benv+'xdotool mousemove 2390 320 click 1')['rc'] == 0
time.sleep(12)
s = state()
assert 'capture=kms' in s and s.count('ActiveState=active') == 2, s
client = run(b, 'pgrep -x moonlight')['out'].strip()
assert client.isdigit(), client
return dict(host=s, client_pid=int(client))
try:
assert run(b, benv+'xdotool key ctrl+alt+shift+q')['rc'] == 0
time.sleep(4)
results['normal_exit'] = state()
assert 'capture=kms' not in results['normal_exit'] and 'no-dropin' in results['normal_exit']
assert run(g, genv+'xset dpms force off')['rc'] == 0
time.sleep(1)
results['reconnect_from_idle'] = connect()
assert run(g, 'systemctl --user kill --kill-whom=main --signal=SIGKILL vdi-native-cursor-guard.service')['rc'] == 0
time.sleep(6)
results['guard_kill'] = state()
results['client_after_guard_kill'] = run(b, 'pgrep -x moonlight')['out'].strip()
assert 'capture=kms' not in results['guard_kill'] and 'no-dropin' in results['guard_kill']
assert results['client_after_guard_kill'] == ''
run(g, 'systemctl --user reset-failed vdi-native-cursor-guard.service')
results['final_reconnect'] = connect()
finally:
(Path(__file__).parent/'kms-lifecycle.json').write_text(json.dumps(results, indent=2), encoding='utf-8')
g.close()
b.close()
print(json.dumps(results))