From 5a5ac149ff472dea784a3a2304a58b9d89a36f1a Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Oct 14 2020 06:27:30 +0000 Subject: Do not use latest MBS module if compose.source is not defined. 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 --- diff --git a/server/odcs/server/mbs.py b/server/odcs/server/mbs.py index 95fdf1d..2e2e7ac 100644 --- a/server/odcs/server/mbs.py +++ b/server/odcs/server/mbs.py @@ -57,6 +57,10 @@ class MBS(object): :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". diff --git a/server/odcs/server/pungi.py b/server/odcs/server/pungi.py index ce54b41..9217137 100644 --- a/server/odcs/server/pungi.py +++ b/server/odcs/server/pungi.py @@ -355,7 +355,8 @@ class PungiConfig(BasePungiConfig): 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( diff --git a/server/tests/mbs.py b/server/tests/mbs.py index b5dd0bf..03c03b5 100644 --- a/server/tests/mbs.py +++ b/server/tests/mbs.py @@ -120,12 +120,18 @@ def mock_mbs(mdversion=2): 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 diff --git a/server/tests/test_backend.py b/server/tests/test_backend.py index 3bf96d3..781a4d7 100644 --- a/server/tests/test_backend.py +++ b/server/tests/test_backend.py @@ -98,6 +98,24 @@ class TestBackend(ModelsBaseTest): ) @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, diff --git a/server/tests/test_pungi.py b/server/tests/test_pungi.py index a271afb..5169a95 100644 --- a/server/tests/test_pungi.py +++ b/server/tests/test_pungi.py @@ -78,6 +78,20 @@ class TestPungiConfig(unittest.TestCase): }, ) + 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("") == -1) + self.assertEqual(comps, "") + def test_pungi_config_tag(self): pungi_cfg = PungiConfig( "MBS-512",