From d037d61521e7315f973f0a85034946a4bddd1bc8 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: May 04 2017 19:12:30 +0000 Subject: Store RPM artifacts in resulting repository in modulemd metadata. Signed-off-by: Jan Kaluza --- diff --git a/pungi/phases/createrepo.py b/pungi/phases/createrepo.py index 74087eb..ee6e320 100644 --- a/pungi/phases/createrepo.py +++ b/pungi/phases/createrepo.py @@ -23,6 +23,7 @@ import os import glob import shutil import threading +import copy from kobo.threads import ThreadPool, WorkerThread from kobo.shortcuts import run, relative_path @@ -119,6 +120,7 @@ def create_variant_repo(compose, arch, variant, pkg_type): compose.log_info("[BEGIN] %s" % msg) rpms = set() + rpm_nevras = set() # read rpms from metadata rather than guessing it by scanning filesystem manifest_file = compose.paths.compose.metadata("rpms.json") @@ -129,12 +131,13 @@ def create_variant_repo(compose, arch, variant, pkg_type): if arch is not None and arch != rpms_arch: continue for srpm_data in data.itervalues(): - for rpm_data in srpm_data.itervalues(): + for rpm_nevra, rpm_data in srpm_data.iteritems(): if types[pkg_type][0] != rpm_data['category']: continue path = os.path.join(compose.topdir, "compose", rpm_data["path"]) rel_path = relative_path(path, repo_dir.rstrip("/") + "/") rpms.add(rel_path) + rpm_nevras.add(str(rpm_nevra)) file_list = compose.paths.work.repo_package_list(arch, variant, pkg_type) with open(file_list, 'w') as f: @@ -182,15 +185,22 @@ def create_variant_repo(compose, arch, variant, pkg_type): shutil.copy2(product_id_path, os.path.join(repo_dir, "repodata", "productid")) # call modifyrepo to inject modulemd if needed - if variant.mmds: + if arch in variant.arch_mmds: import yaml - modules = {"modules": []} - for mmd in variant.mmds: - modules["modules"].append(yaml.safe_load(mmd.dumps())) + modules = [] + for mmd in variant.arch_mmds[arch].itervalues(): + # Create copy of architecture specific mmd to filter out packages + # which are not part of this particular repo. + repo_mmd = copy.deepcopy(mmd) + repo_mmd["data"]["artifacts"]["rpms"] = [ + rpm_nevra for rpm_nevra in repo_mmd["data"]["artifacts"]["rpms"] + if rpm_nevra in rpm_nevras] + modules.append(repo_mmd) + with temp_dir() as tmp_dir: modules_path = os.path.join(tmp_dir, "modules.yaml") with open(modules_path, "w") as outfile: - outfile.write(yaml.safe_dump(modules)) + outfile.write(yaml.dump_all(modules, explicit_start=True)) cmd = repo.get_modifyrepo_cmd(os.path.join(repo_dir, "repodata"), modules_path, mdtype="modules", compress_type="gz") diff --git a/pungi/phases/gather/sources/source_module.py b/pungi/phases/gather/sources/source_module.py index 93c7169..3fcb7dd 100644 --- a/pungi/phases/gather/sources/source_module.py +++ b/pungi/phases/gather/sources/source_module.py @@ -28,21 +28,36 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase): enabled = True def __call__(self, arch, variant): + import yaml + groups = set() packages = set() compatible_arches = pungi.arch.get_compatible_arches(arch) if variant is not None and variant.modules: + variant.arch_mmds.setdefault(arch, {}) + rpms = sum([ variant.pkgset.rpms_by_arch.get(a, []) for a in compatible_arches ], []) for rpm_obj in rpms: for mmd in variant.mmds: + # Generate architecture specific modulemd metadata + # with list of artifacts only for this architecture. + if mmd.name not in variant.arch_mmds[arch]: + arch_mmd = yaml.safe_load(mmd.dumps()) + arch_mmd["data"]["artifacts"] = {"rpms": []} + variant.arch_mmds[arch][mmd.name] = arch_mmd + else: + arch_mmd = variant.arch_mmds[arch][mmd.name] + srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"] if (srpm in mmd.components.rpms.keys() and rpm_obj.name not in mmd.filter.rpms): packages.add((rpm_obj.name, None)) + arch_mmd["data"]["artifacts"]["rpms"].append( + str(rpm_obj.nevra)) return packages, groups diff --git a/pungi/wrappers/variants.py b/pungi/wrappers/variants.py index 4f9938f..9ecada4 100755 --- a/pungi/wrappers/variants.py +++ b/pungi/wrappers/variants.py @@ -227,6 +227,7 @@ class Variant(object): self.pkgset = None self.mmds = [] + self.arch_mmds = {} def __getitem__(self, name): return self.variants[name] diff --git a/tests/helpers.py b/tests/helpers.py index 39abcf4..401175e 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -34,6 +34,7 @@ class MockVariant(mock.Mock): super(MockVariant, self).__init__(*args, is_empty=is_empty, **kwargs) self.parent = kwargs.get('parent', None) self.mmds = [] + self.arch_mmds = {} self.variants = {} def __str__(self):