#856 Add modulemd metadata to resulting repository even if the module has no components.
Merged 6 years ago by lsedlar. Opened 6 years ago by jkaluza.

@@ -47,6 +47,14 @@ 

          if variant is not None and variant.modules:

              variant.arch_mmds.setdefault(arch, {})

  

+             # Generate architecture specific modulemd metadata, so we can

+             # store per-architecture artifacts there later.

+             for mmd in variant.mmds:

+                 mmd_id = "%s-%s" % (mmd.name, mmd.stream)

+                 if mmd_id not in variant.arch_mmds[arch]:

+                     arch_mmd = yaml.safe_load(mmd.dumps())

+                     variant.arch_mmds[arch][mmd_id] = arch_mmd

+ 

              # Contains per-module RPMs added to variant.

              added_rpms = {}

  
@@ -64,13 +72,7 @@ 

  

                  for mmd in variant.mmds:

                      mmd_id = "%s-%s" % (mmd.name, mmd.stream)

-                     # Generate architecture specific modulemd metadata

-                     # with list of artifacts only for this architecture.

-                     if mmd_id not in variant.arch_mmds[arch]:

-                         arch_mmd = yaml.safe_load(mmd.dumps())

-                         variant.arch_mmds[arch][mmd_id] = arch_mmd

-                     else:

-                         arch_mmd = variant.arch_mmds[arch][mmd_id]

+                     arch_mmd = variant.arch_mmds[arch][mmd_id]

  

                      srpm = kobo.rpmlib.parse_nvr(rpm_obj.sourcerpm)["name"]

                      if (srpm in mmd.components.rpms.keys() and
@@ -92,6 +94,10 @@ 

              # list is later used in createrepo phase to generated modules.yaml.

              for mmd_id, rpm_nevras in added_rpms.items():

                  arch_mmd = variant.arch_mmds[arch][mmd_id]

+                 # Modules without artifacts are also valid.

+                 if ("artifacts" not in arch_mmd["data"] or

+                         "rpms" not in arch_mmd["data"]["artifacts"]):

+                     continue

                  arch_mmd["data"]["artifacts"]["rpms"] = [

                      rpm_nevra for rpm_nevra in rpm_nevras

                      if rpm_nevra in arch_mmd["data"]["artifacts"]["rpms"]]

This moves code adding modulemd to variant.arch_mmds outside of for rpm_obj in rpms:, so we have the mmd in variant.arch_mmds even when variant does not contain any RPM.

It also handles the case when module does not contain any artifact when iterating over the list of added RPMs.

I've tested this on staging composer with empty testmodule-master build and some older version of testmodule-master with some RPM components and it seems OK.

I can't see any problems with this change.

Commit 18d005e fixes this pull-request

Pull-Request has been merged by lsedlar

6 years ago