pungi: Run in-process for testing

Instead of spawning a separate process for each test, move the code to
run in the main process. This gives us correct coverage information and
makes the tests a lot faster.

The input is still provided in a kickstart file. The output also goes
into a log file that is later parsed.

There is some extra work needed with logging setup to make the logs go
to standard output so that nose can correctly capture them.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-11-04 09:08:11 +01:00 committed by Tester
parent ea1bcf625b
commit 0cdef2d8e3
2 changed files with 68 additions and 9 deletions

View File

@ -197,3 +197,58 @@ class PungiWrapper(object):
result.setdefault(match.group(2), set()).add(match.group(1))
return result
def run_pungi(self, ks_file, destdir, name, selfhosting=False, fulltree=False,
greedy='', cache_dir=None, arch='', multilib_methods=[],
nodeps=False, lookaside_repos=[]):
"""
This is a replacement for get_pungi_cmd that runs it in-process. Not
all arguments are supported.
"""
from .. import ks, gather, config
ksparser = ks.get_ksparser(ks_path=ks_file)
cfg = config.Config()
cfg.set('pungi', 'destdir', destdir)
cfg.set('pungi', 'family', name)
cfg.set('pungi', 'iso_basename', name)
cfg.set('pungi', 'fulltree', str(fulltree))
cfg.set('pungi', 'selfhosting', str(selfhosting))
cfg.set('pungi', 'cachedir', cache_dir)
cfg.set('pungi', 'full_archlist', "True")
cfg.set('pungi', 'workdirbase', "%s/work" % destdir)
cfg.set('pungi', 'greedy', greedy)
cfg.set('pungi', 'nosource', 'False')
cfg.set('pungi', 'nodebuginfo', 'False')
cfg.set('pungi', 'force', 'False')
cfg.set('pungi', 'resolve_deps', str(not nodeps))
if arch:
cfg.set('pungi', 'arch', arch)
if multilib_methods:
cfg.set('pungi', 'multilib', " ".join(multilib_methods))
if lookaside_repos:
cfg.set('pungi', 'lookaside_repos', " ".join(lookaside_repos))
mypungi = gather.Pungi(cfg, ksparser)
with open(os.path.join(destdir, 'out'), 'w') as f:
with mypungi.yumlock:
mypungi._inityum()
mypungi.gather()
for line in mypungi.list_packages():
flags_str = ",".join(line["flags"])
if flags_str:
flags_str = "(%s)" % flags_str
f.write("RPM%s: %s\n" % (flags_str, line["path"]))
mypungi.makeCompsFile()
mypungi.getDebuginfoList()
for line in mypungi.list_debuginfo():
flags_str = ",".join(line["flags"])
if flags_str:
flags_str = "(%s)" % flags_str
f.write("DEBUGINFO%s: %s\n" % (flags_str, line["path"]))
for line in mypungi.list_srpms():
flags_str = ",".join(line["flags"])
if flags_str:
flags_str = "(%s)" % flags_str
f.write("SRPM%s: %s\n" % (flags_str, line["path"]))

View File

@ -10,8 +10,7 @@ import os
import tempfile
import shutil
import sys
from kobo.shortcuts import run
import logging
HERE = os.path.dirname(__file__)
BINDIR = (os.path.join(HERE, '..', 'bin'))
@ -42,7 +41,13 @@ class TestPungi(unittest.TestCase):
"fixtures/repos/repo-krb5-lookaside")
self.ks = os.path.join(self.tmp_dir, "ks")
self.out = os.path.join(self.tmp_dir, "out")
self.p = PungiWrapper()
logger = logging.getLogger('Pungi')
if not logger.handlers:
formatter = logging.Formatter('%(name)s:%(levelname)s: %(message)s')
console = logging.StreamHandler(sys.stdout)
console.setFormatter(formatter)
console.setLevel(logging.INFO)
logger.addHandler(console)
def tearDown(self):
shutil.rmtree(self.tmp_dir)
@ -53,17 +58,16 @@ class TestPungi(unittest.TestCase):
Write a kickstart with given packages and groups, then run the
depsolving and parse the output.
"""
p = PungiWrapper()
repos = {"repo": repo or self.repo}
if lookaside:
repos['lookaside'] = lookaside
self.p.write_kickstart(self.ks, repos, groups, packages, prepopulate=prepopulate,
multilib_whitelist=multilib_whitelist)
kwargs.setdefault('full_archlist', True)
p.write_kickstart(self.ks, repos, groups, packages, prepopulate=prepopulate,
multilib_whitelist=multilib_whitelist)
kwargs.setdefault('cache_dir', self.tmp_dir)
cmd = self.p.get_pungi_cmd(self.ks, self.tmp_dir, "DP", **kwargs)
run(cmd, logfile=self.out, stdout=True)
p.run_pungi(self.ks, self.tmp_dir, 'DP', **kwargs)
with open(self.out, "r") as f:
pkg_map = self.p.get_packages(f.read())
pkg_map = p.get_packages(f.read())
return convert_pkg_map(pkg_map)
def test_kernel(self):