util.py 639 B

12345678910111213141516171819202122232425
  1. import pytest
  2. import subprocess
  3. import time
  4. def run_qemu(request, run_args=[]):
  5. subprocess.check_call('rm -f ./state/empty-hd.img', shell=True)
  6. print('\nrm ./state/*')
  7. print('\nStarting QEMU')
  8. p = subprocess.Popen(['./scripts/run'] + run_args,
  9. stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
  10. def fin():
  11. print('\nTerminating QEMU')
  12. p.terminate()
  13. request.addfinalizer(fin)
  14. return p
  15. @pytest.mark.timeout(10)
  16. def wait_for_ssh(ssh_command=['./scripts/ssh']):
  17. while subprocess.call(ssh_command + ['/bin/true']) != 0:
  18. time.sleep(1)