Store RPM artifacts in resulting repository in modulemd metadata.

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
Jan Kaluza 2017-05-04 20:46:06 +02:00
parent 6ce88630ec
commit d037d61521
4 changed files with 33 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import os
import glob import glob
import shutil import shutil
import threading import threading
import copy
from kobo.threads import ThreadPool, WorkerThread from kobo.threads import ThreadPool, WorkerThread
from kobo.shortcuts import run, relative_path 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) compose.log_info("[BEGIN] %s" % msg)
rpms = set() rpms = set()
rpm_nevras = set()
# read rpms from metadata rather than guessing it by scanning filesystem # read rpms from metadata rather than guessing it by scanning filesystem
manifest_file = compose.paths.compose.metadata("rpms.json") 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: if arch is not None and arch != rpms_arch:
continue continue
for srpm_data in data.itervalues(): 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']: if types[pkg_type][0] != rpm_data['category']:
continue continue
path = os.path.join(compose.topdir, "compose", rpm_data["path"]) path = os.path.join(compose.topdir, "compose", rpm_data["path"])
rel_path = relative_path(path, repo_dir.rstrip("/") + "/") rel_path = relative_path(path, repo_dir.rstrip("/") + "/")
rpms.add(rel_path) rpms.add(rel_path)
rpm_nevras.add(str(rpm_nevra))
file_list = compose.paths.work.repo_package_list(arch, variant, pkg_type) file_list = compose.paths.work.repo_package_list(arch, variant, pkg_type)
with open(file_list, 'w') as f: 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")) shutil.copy2(product_id_path, os.path.join(repo_dir, "repodata", "productid"))
# call modifyrepo to inject modulemd if needed # call modifyrepo to inject modulemd if needed
if variant.mmds: if arch in variant.arch_mmds:
import yaml import yaml
modules = {"modules": []} modules = []
for mmd in variant.mmds: for mmd in variant.arch_mmds[arch].itervalues():
modules["modules"].append(yaml.safe_load(mmd.dumps())) # 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: with temp_dir() as tmp_dir:
modules_path = os.path.join(tmp_dir, "modules.yaml") modules_path = os.path.join(tmp_dir, "modules.yaml")
with open(modules_path, "w") as outfile: 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"), cmd = repo.get_modifyrepo_cmd(os.path.join(repo_dir, "repodata"),
modules_path, mdtype="modules", modules_path, mdtype="modules",
compress_type="gz") compress_type="gz")

View File

@ -28,21 +28,36 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase):
enabled = True enabled = True
def __call__(self, arch, variant): def __call__(self, arch, variant):
import yaml
groups = set() groups = set()
packages = set() packages = set()
compatible_arches = pungi.arch.get_compatible_arches(arch) compatible_arches = pungi.arch.get_compatible_arches(arch)
if variant is not None and variant.modules: if variant is not None and variant.modules:
variant.arch_mmds.setdefault(arch, {})
rpms = sum([ rpms = sum([
variant.pkgset.rpms_by_arch.get(a, []) variant.pkgset.rpms_by_arch.get(a, [])
for a in compatible_arches for a in compatible_arches
], []) ], [])
for rpm_obj in rpms: for rpm_obj in rpms:
for mmd in variant.mmds: 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"] srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"]
if (srpm in mmd.components.rpms.keys() and if (srpm in mmd.components.rpms.keys() and
rpm_obj.name not in mmd.filter.rpms): rpm_obj.name not in mmd.filter.rpms):
packages.add((rpm_obj.name, None)) packages.add((rpm_obj.name, None))
arch_mmd["data"]["artifacts"]["rpms"].append(
str(rpm_obj.nevra))
return packages, groups return packages, groups

View File

@ -227,6 +227,7 @@ class Variant(object):
self.pkgset = None self.pkgset = None
self.mmds = [] self.mmds = []
self.arch_mmds = {}
def __getitem__(self, name): def __getitem__(self, name):
return self.variants[name] return self.variants[name]

View File

@ -34,6 +34,7 @@ class MockVariant(mock.Mock):
super(MockVariant, self).__init__(*args, is_empty=is_empty, **kwargs) super(MockVariant, self).__init__(*args, is_empty=is_empty, **kwargs)
self.parent = kwargs.get('parent', None) self.parent = kwargs.get('parent', None)
self.mmds = [] self.mmds = []
self.arch_mmds = {}
self.variants = {} self.variants = {}
def __str__(self): def __str__(self):