1
0
mirror of https://github.com/rancher/os.git synced 2025-06-30 16:51:47 +00:00
os/tests/integration/rancherostest/util.py

66 lines
1.5 KiB
Python
Raw Normal View History

2015-09-09 06:33:54 +00:00
import itertools as it
2015-05-08 09:10:17 +00:00
import pytest
import subprocess
import time
ros_test = 'ros-test'
2015-09-01 14:11:02 +00:00
def iter_lines(s):
2015-09-09 06:33:54 +00:00
return it.imap(str.rstrip, iter(s.readline, ''))
def strip_comment(prefix):
return lambda s: s.partition(prefix)[0].strip()
def non_empty(s):
return s != ''
def parse_value(var):
def get_value(s):
(k, _, v) = s.partition('=')
(k, v) = (k.strip(), v.strip())
if k == var:
return v
return ''
return get_value
def with_effect(p):
def effect(s):
p(s)
return s
return effect
2015-09-01 14:11:02 +00:00
2015-09-03 15:07:57 +00:00
def rancheros_version(build_conf):
with open(build_conf) as f:
for v in it.ifilter(non_empty,
it.imap(parse_value('VERSION'),
it.ifilter(non_empty,
it.imap(strip_comment('#'), iter_lines(f))))):
return v
raise RuntimeError("Could not parse RancherOS version")
2015-05-08 09:10:17 +00:00
def run_qemu(request, run_args=[]):
print('\nStarting QEMU')
p = subprocess.Popen(['./scripts/run', '--qemu', '--no-rebuild', '--fresh'] + run_args,
2015-05-08 09:10:17 +00:00
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
def fin():
print('\nTerminating QEMU')
p.terminate()
request.addfinalizer(fin)
return p
@pytest.mark.timeout(10)
def wait_for_ssh(ssh_command=['./scripts/ssh', '--qemu']):
while subprocess.call(ssh_command + ['docker version >/dev/null 2>&1']) != 0:
2015-05-08 09:10:17 +00:00
time.sleep(1)