#449 Do not use latest MBS module if compose.source is not defined.
Merged 3 years ago by lsedlar. Opened 3 years ago by jkaluza.
jkaluza/odcs empty-source-modules  into  master

@@ -57,6 +57,10 @@ 

          :raises ModuleLookupError: if the module couldn't be found

          :return: the latest version of the module.

          """

+         if not nsvc:

+             # Return an empty list of no NSVC is defined.

+             return []

+ 

          params = {

              "nsvc": nsvc,

              "state": [3, 5] if include_done else [5],  # 5 is "ready", 3 is "done".

file modified
+2 -1
@@ -355,7 +355,8 @@ 

              tmp_variant.add_arch(comps.Arch(arch))

          if self.source_type == PungiSourceType.MODULE:

              for module in self.source.split(" "):

-                 tmp_variant.add_module(comps.Module(module))

+                 if module:

+                     tmp_variant.add_module(comps.Module(module))

          elif self.source_type == PungiSourceType.KOJI_TAG:

              if self.packages:

                  tmp_variant.add_group(

file modified
+12 -6
@@ -120,12 +120,18 @@ 

              def handle_module_builds(request):

                  query = parse_qs(urlparse(request.url).query)

                  states = [int(s) for s in query["state"]]

-                 nsvc = query["nsvc"][0]

-                 nsvc_parts = nsvc.split(":")

-                 nsvc_keys = ["name", "stream", "version", "context"]

-                 nsvc_dict = {}

-                 for key, part in zip(nsvc_keys, nsvc_parts):

-                     nsvc_dict[key] = part

+                 if "nsvc" in query:

+                     nsvc = query["nsvc"][0]

+                     nsvc_parts = nsvc.split(":")

+                     nsvc_keys = ["name", "stream", "version", "context"]

+                     nsvc_dict = {}

+                     for key, part in zip(nsvc_keys, nsvc_parts):

+                         nsvc_dict[key] = part

+                 else:

+                     # Empty keys and dict in case nsvc is not specitified.

+                     # This means no filtering based on the nsvc will be done.

+                     nsvc_keys = []

+                     nsvc_dict = {}

  

                  if mdversion == 1:

                      modules = TEST_MBS_MODULES_MMDv1

@@ -98,6 +98,24 @@ 

          )

  

      @mock_mbs()

+     def test_resolve_compose_module_empty_source(self):

+         c = Compose.create(

+             db.session,

+             "me",

+             PungiSourceType.MODULE,

+             "",

+             COMPOSE_RESULTS["repository"],

+             3600,

+         )

+         db.session.commit()

+ 

+         resolve_compose(c)

+         db.session.commit()

+ 

+         c = db.session.query(Compose).filter(Compose.id == 1).one()

+         self.assertEqual(c.source, "")

+ 

+     @mock_mbs()

      def test_resolve_compose_module_include_done_modules(self):

          c = Compose.create(

              db.session,

@@ -78,6 +78,20 @@ 

              },

          )

  

+     def test_pungi_config_module_empty_source(self):

+         pungi_cfg = PungiConfig(

+             "MBS-512",

+             "1",

+             PungiSourceType.MODULE,

+             "",

+         )

+         cfg = pungi_cfg.get_pungi_config()

+         variants = pungi_cfg.get_variants_config()

+         comps = pungi_cfg.get_comps_config()

+         # No "module" in variants case the source is empty.

+         self.assertTrue(variants.find("<module>") == -1)

+         self.assertEqual(comps, "")

+ 

      def test_pungi_config_tag(self):

          pungi_cfg = PungiConfig(

              "MBS-512",

The compose.source can be set to an emptry string in case we
want to generate compose only from scratch module builds.

The MBS.get_latest_modules does not count with that and in case
the nsvc is an empty string, it simply does not send nsvc
in the request to MBS which means all the modules are returned and
MBS class chooses the latest one and adds it to "source" later.

This commit handles this situation and returns early with an empty
list in this case.

Signed-off-by: Jan Kaluza jkaluza@redhat.com

Hm, this would explain why the random modules appeared there. Looks good!

Pull-Request has been merged by lsedlar

3 years ago