Include module defaults in the repodata

If the compose configuration includes the module_defaults_dir (an
scm_dict), clone the directory, read the module defaults contained
therein and include relevant defaults in the combined modulemd file.

Only defaults for modules present in the variant are included.

This requires libmodulemd 1.2.0+.

Merges: https://pagure.io/pungi/pull-request/891
Signed-off-by: Petr Šabata <contyk@redhat.com>
This commit is contained in:
Petr Šabata 2018-04-04 12:59:52 +02:00 committed by Lubomír Sedlář
parent 506ac99f62
commit 0e7f770fb7
4 changed files with 30 additions and 2 deletions

View File

@ -193,6 +193,10 @@ class Compose(kobo.log.LoggingBase):
def has_comps(self):
return bool(self.conf.get("comps_file", False))
@property
def has_module_defaults(self):
return bool(self.conf.get("module_defaults_dir", False))
@property
def config_dir(self):
return os.path.dirname(self.conf._open_file or "")

View File

@ -218,9 +218,15 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None)
raise AttributeError("module_metadata parameter was not passed and it is needed for module processing")
modules.append(repo_mmd)
module_names = set([x.get_name() for x in modules])
for mmddeffile in glob.glob(os.path.join(compose.config_dir, "module_defaults", "*.yaml")):
for mmddef in Modulemd.objects_from_file(mmddeffile):
if isinstance(mmddef, Modulemd.Defaults) and mmddef.peek_module_name() in module_names:
modules.append(mmddef)
with temp_dir() as tmp_dir:
modules_path = os.path.join(tmp_dir, "modules.yaml")
Modulemd.Module.dump_all(modules, modules_path)
Modulemd.dump(modules, modules_path)
cmd = repo.get_modifyrepo_cmd(os.path.join(repo_dir, "repodata"),
modules_path, mdtype="modules",

View File

@ -23,7 +23,8 @@ from pungi.phases.base import PhaseBase
from pungi.phases.gather import write_prepopulate_file
from pungi.wrappers.createrepo import CreaterepoWrapper
from pungi.wrappers.comps import CompsWrapper
from pungi.wrappers.scm import get_file_from_scm
from pungi.wrappers.scm import get_file_from_scm, get_dir_from_scm
from pungi.util import temp_dir
class InitPhase(PhaseBase):
@ -50,6 +51,10 @@ class InitPhase(PhaseBase):
# download variants.xml / product.xml?
# download module defaults
if self.compose.has_module_defaults:
write_module_defaults(self.compose)
# write prepopulate file
write_prepopulate_file(self.compose)
@ -142,3 +147,13 @@ def create_comps_repo(compose, arch):
checksum=createrepo_checksum)
run(cmd, logfile=compose.paths.log.log_file(arch, "comps_repo"), show_cmd=True)
compose.log_info("[DONE ] %s" % msg)
def write_module_defaults(compose):
scm_dict = compose.conf["module_defaults_dir"]
with temp_dir(prefix="moduledefaults_") as tmp_dir:
get_dir_from_scm(scm_dict, tmp_dir, logger=compose._logger)
compose.log_debug("Writing module defaults")
shutil.rmtree(os.path.join(compose.config_dir, "module_defaults"), ignore_errors=True)
shutil.copytree(tmp_dir, os.path.join(compose.config_dir, "module_defaults"))

View File

@ -24,6 +24,7 @@ class TestInitPhase(PungiTestCase):
def test_run(self, write_prepopulate, write_variant, create_comps, write_arch, write_global):
compose = DummyCompose(self.topdir, {})
compose.has_comps = True
compose.has_module_defaults = False
compose.setup_optional()
phase = init.InitPhase(compose)
phase.run()
@ -51,6 +52,7 @@ class TestInitPhase(PungiTestCase):
write_arch, write_global):
compose = DummyCompose(self.topdir, {})
compose.has_comps = True
compose.has_module_defaults = False
compose.variants['Everything'].groups = []
compose.variants['Everything'].modules = []
phase = init.InitPhase(compose)
@ -78,6 +80,7 @@ class TestInitPhase(PungiTestCase):
write_arch, write_global):
compose = DummyCompose(self.topdir, {})
compose.has_comps = False
compose.has_module_defaults = False
phase = init.InitPhase(compose)
phase.run()