1
0
mirror of https://github.com/rancher/os.git synced 2025-08-11 11:32:28 +00:00

tests cleanup

This commit is contained in:
Ivan Mikushin 2015-09-09 11:33:54 +05:00
parent 69970ed8ed
commit 94c7eca88e
2 changed files with 44 additions and 13 deletions

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import itertools as it
import pytest import pytest
import subprocess import subprocess
import rancherostest.util as u import rancherostest.util as u
@ -9,11 +11,12 @@ def qemu(request):
def rancheros_version(): def rancheros_version():
with open('./scripts/version') as f: with open('./build.conf') as f:
for ln in f: for v in it.ifilter(u.non_empty,
(k, _, v) = ln.partition('=') it.imap(u.parse_value('VERSION'),
if k == 'VERSION' and v.strip() != '': it.ifilter(u.non_empty,
return v.strip() it.imap(u.strip_comment('#'), u.iter_lines(f))))):
return v
raise RuntimeError("Could not parse RancherOS version") raise RuntimeError("Could not parse RancherOS version")
@ -21,12 +24,14 @@ def rancheros_version():
def test_system_boot(qemu): def test_system_boot(qemu):
version = rancheros_version() version = rancheros_version()
print('parsed version: ' + version) print('parsed version: ' + version)
for ln in u.iter_lines(qemu.stdout):
ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=version)) def has_ros_started_substr(s):
print(str.strip(ln)) return str.find(s, 'RancherOS {v} started'.format(v=version)) > -1
if ros_booted_substr > -1:
assert True for _ in it.ifilter(has_ros_started_substr,
return it.imap(u.with_effect(print), u.iter_lines(qemu.stdout))):
assert True
return
assert False assert False
@ -40,7 +45,7 @@ def test_run_system_container(qemu):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
for ln in u.iter_lines(ssh.stdout): for ln in u.iter_lines(ssh.stdout):
print(str.strip(ln)) print(ln)
ssh.wait() ssh.wait()
assert ssh.returncode == 0 assert ssh.returncode == 0

View File

@ -1,10 +1,36 @@
import itertools as it
import pytest import pytest
import subprocess import subprocess
import time import time
def iter_lines(s): def iter_lines(s):
return iter(s.readline, '') 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
def run_qemu(request, run_args=[]): def run_qemu(request, run_args=[]):