#1266 Allow loading overrides for module defaults
Merged 4 years ago by lsedlar. Opened 4 years ago by lsedlar.
lsedlar/pungi default-overrides  into  master

file modified
+1
@@ -746,6 +746,7 @@ 

                  "default": True

              },

              "module_defaults_dir": {"$ref": "#/definitions/str_or_scm_dict"},

+             "module_defaults_override_dir": {"type": "string"},

  

              "pkgset_repos": {

                  "type": "object",

file modified
+4 -1
@@ -211,7 +211,10 @@ 

  

          module_names = set(mod_index.get_module_names())

          defaults_dir = compose.paths.work.module_defaults_dir()

-         collect_module_defaults(defaults_dir, module_names, mod_index)

+         overrides_dir = compose.conf.get("module_defaults_override_dir")

+         collect_module_defaults(

+             defaults_dir, module_names, mod_index, overrides_dir=overrides_dir

+         )

  

          log_file = compose.paths.log.log_file(arch, "modifyrepo-modules-%s" % variant)

          add_modular_metadata(repo, repo_dir, mod_index, log_file)

@@ -382,7 +382,10 @@ 

  

          module_names = set(mod_index.get_module_names())

          defaults_dir = compose.paths.work.module_defaults_dir()

-         collect_module_defaults(defaults_dir, module_names, mod_index)

+         overrides_dir = compose.conf.get("module_defaults_override_dir")

+         collect_module_defaults(

+             defaults_dir, module_names, mod_index, overrides_dir=overrides_dir

+         )

  

          log_file = compose.paths.log.log_file(

              arch, "lookaside_repo_modules_%s" % (variant.uid)

@@ -155,8 +155,9 @@ 

      # Add modulemd to the repo for all modules in all variants on this architecture.

      if Modulemd and mmd:

          names = set(x.get_module_name() for x in mmd)

+         overrides_dir = compose.conf.get("module_defaults_override_dir")

          mod_index = collect_module_defaults(

-             compose.paths.work.module_defaults_dir(), names

+             compose.paths.work.module_defaults_dir(), names, overrides_dir=overrides_dir

          )

          for x in mmd:

              mod_index.add_module_stream(x)

file modified
+15 -4
@@ -934,9 +934,10 @@ 

      # and work with it. However that does not allow for detecting conflicting

      # defaults. That should not happen in practice, but better safe than sorry.

      # Once libmodulemd can report the error, this code can be simplifed by a

-     # lot. It's implemented in

+     # lot. It was implemented in

      # https://github.com/fedora-modularity/libmodulemd/commit/3087e4a5c38a331041fec9b6b8f1a372f9ffe64d

-     # and released in 2.6.0

+     # and released in 2.6.0, but 2.8.0 added the need to merge overrides and

+     # that breaks this use case again.

      for file in glob.glob(os.path.join(path, "*.yaml")):

          index = Modulemd.ModuleIndex()

          index.update_from_file(file, strict=False)
@@ -944,7 +945,9 @@ 

              yield module_name, index.get_module(module_name).get_defaults()

  

  

- def collect_module_defaults(defaults_dir, modules_to_load=None, mod_index=None):

+ def collect_module_defaults(

+     defaults_dir, modules_to_load=None, mod_index=None, overrides_dir=None

+ ):

      """Load module defaults into index.

  

      If `modules_to_load` is passed in, it should be a set of module names. Only
@@ -954,7 +957,15 @@ 

      not, a new ModuleIndex will be created and returned

      """

      mod_index = mod_index or Modulemd.ModuleIndex()

-     for module_name, defaults in iter_module_defaults(defaults_dir):

+ 

+     temp_index = Modulemd.ModuleIndex.new()

+     temp_index.update_from_defaults_directory(

+         defaults_dir, overrides_path=overrides_dir, strict=False

+     )

+ 

+     for module_name in temp_index.get_module_names():

+         defaults = temp_index.get_module(module_name).get_defaults()

+ 

          if not modules_to_load or module_name in modules_to_load:

              mod_index.add_defaults(defaults)

  

@@ -105,6 +105,7 @@ 

          cmd.assert_called_once_with(

              os.path.join(self.topdir, "work/global/module_defaults"),

              set(x.get_module_name.return_value for x in mmd["x86_64"]),

+             overrides_dir=None,

          )

          amm.assert_called_once_with(

              mock.ANY,

This patch adds a new config option. This is expected to be a name of subdirectory in the repo with module defaults. If supplied, overrides from that location are loaded every time defaults are loaded.

This raises the minimal required version of libmodulemd to 2.8.0

CC @sgallagh, @psabata

rebased onto c901b2c31f76e75bbd7e84af431f7d7e68913b7d

4 years ago

I didn't find any problem during the review.

rebased onto 2b112d5

4 years ago

Pull-Request has been merged by lsedlar

4 years ago