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:
parent
ea1bcf625b
commit
0cdef2d8e3
@ -197,3 +197,58 @@ class PungiWrapper(object):
|
|||||||
result.setdefault(match.group(2), set()).add(match.group(1))
|
result.setdefault(match.group(2), set()).add(match.group(1))
|
||||||
|
|
||||||
return result
|
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"]))
|
||||||
|
@ -10,8 +10,7 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
from kobo.shortcuts import run
|
|
||||||
|
|
||||||
HERE = os.path.dirname(__file__)
|
HERE = os.path.dirname(__file__)
|
||||||
BINDIR = (os.path.join(HERE, '..', 'bin'))
|
BINDIR = (os.path.join(HERE, '..', 'bin'))
|
||||||
@ -42,7 +41,13 @@ class TestPungi(unittest.TestCase):
|
|||||||
"fixtures/repos/repo-krb5-lookaside")
|
"fixtures/repos/repo-krb5-lookaside")
|
||||||
self.ks = os.path.join(self.tmp_dir, "ks")
|
self.ks = os.path.join(self.tmp_dir, "ks")
|
||||||
self.out = os.path.join(self.tmp_dir, "out")
|
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):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
@ -53,17 +58,16 @@ class TestPungi(unittest.TestCase):
|
|||||||
Write a kickstart with given packages and groups, then run the
|
Write a kickstart with given packages and groups, then run the
|
||||||
depsolving and parse the output.
|
depsolving and parse the output.
|
||||||
"""
|
"""
|
||||||
|
p = PungiWrapper()
|
||||||
repos = {"repo": repo or self.repo}
|
repos = {"repo": repo or self.repo}
|
||||||
if lookaside:
|
if lookaside:
|
||||||
repos['lookaside'] = lookaside
|
repos['lookaside'] = lookaside
|
||||||
self.p.write_kickstart(self.ks, repos, groups, packages, prepopulate=prepopulate,
|
p.write_kickstart(self.ks, repos, groups, packages, prepopulate=prepopulate,
|
||||||
multilib_whitelist=multilib_whitelist)
|
multilib_whitelist=multilib_whitelist)
|
||||||
kwargs.setdefault('full_archlist', True)
|
|
||||||
kwargs.setdefault('cache_dir', self.tmp_dir)
|
kwargs.setdefault('cache_dir', self.tmp_dir)
|
||||||
cmd = self.p.get_pungi_cmd(self.ks, self.tmp_dir, "DP", **kwargs)
|
p.run_pungi(self.ks, self.tmp_dir, 'DP', **kwargs)
|
||||||
run(cmd, logfile=self.out, stdout=True)
|
|
||||||
with open(self.out, "r") as f:
|
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)
|
return convert_pkg_map(pkg_map)
|
||||||
|
|
||||||
def test_kernel(self):
|
def test_kernel(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user