From 6b37fba1a9305d960a94831e0d67eab8b8cffdc3 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Oct 03 2018 08:02:53 +0000 Subject: Do not add base module into the compose and do not accept it in 'source'. --- diff --git a/server/odcs/server/backend.py b/server/odcs/server/backend.py index 1389b70..18fa859 100644 --- a/server/odcs/server/backend.py +++ b/server/odcs/server/backend.py @@ -342,7 +342,8 @@ def resolve_compose(compose): uids = sorted( "{name}:{stream}:{version}:{context}".format(**m) - for m in new_mbs_modules) + for m in new_mbs_modules + if m['name'] not in conf.base_module_names) compose.source = ' '.join(uids) diff --git a/server/odcs/server/config.py b/server/odcs/server/config.py index 54cf5cf..8415bed 100644 --- a/server/odcs/server/config.py +++ b/server/odcs/server/config.py @@ -246,6 +246,11 @@ class Config(object): 'type': list, 'default': [], 'desc': 'Required scopes for submitting request to run new compose.'}, + 'base_module_names': { + 'type': set, + 'default': set(['platform', 'bootstrap']), + 'desc': ("Set of module names which defines the product version " + "(by their stream) of modules depending on them.")}, 'messaging_backend': { 'type': str, 'default': '', diff --git a/server/odcs/server/views.py b/server/odcs/server/views.py index 33d1403..943efe5 100644 --- a/server/odcs/server/views.py +++ b/server/odcs/server/views.py @@ -243,10 +243,15 @@ class ODCSAPI(MethodView): source_name) elif source_type == PungiSourceType.MODULE: for module_str in source: - if len(module_str.split(":")) < 2: + nsvc = module_str.split(":") + if len(nsvc) < 2: raise ValueError( 'Module definition must be in "n:s", "n:s:v" or ' '"n:s:v:c" format, but got %s' % module_str) + if nsvc[0] in conf.base_module_names: + raise ValueError( + "ODCS currently cannot create compose with base " + "modules, but %s was requested." % nsvc[0]) source = ' '.join(source) diff --git a/server/tests/test_backend.py b/server/tests/test_backend.py index 627b971..b04f23d 100644 --- a/server/tests/test_backend.py +++ b/server/tests/test_backend.py @@ -576,6 +576,37 @@ gpgcheck=0 tag_changed.assert_not_called() + @patch('odcs.server.mbs.MBS.validate_module_list') + @patch('odcs.server.mbs.MBS.get_latest_modules') + def test_resolve_compose_module_filter_base_module( + self, get_latest_modules, validate_module_list): + modules = [ + {"name": "foo", "stream": "0", "version": 1, "context": "x"}, + {"name": "bar", "stream": "0", "version": 1, "context": "y"}, + ] + get_latest_modules.return_value = modules + validate_module_list.return_value = modules + [ + {"name": "platform", "stream": "0", "version": 1, "context": "z"} + ] + + c = Compose.create( + db.session, "me", PungiSourceType.MODULE, "foo:0 bar:0", + COMPOSE_RESULTS["repository"], 3600) + db.session.add(c) + db.session.commit() + + # Default conf.base_module_names includes "platform" module, so it + # should be removed from the source list. + resolve_compose(c) + self.assertEqual(c.source, "bar:0:1:y foo:0:1:x") + + # Now try removing "platform" from the conf.base_module_names, so it + # should appear in a compose source. + with patch.object(odcs.server.config.Config, 'base_module_names', + new=["random_name"]): + resolve_compose(c) + self.assertEqual(c.source, "bar:0:1:y foo:0:1:x platform:0:1:z") + class TestGeneratePungiCompose(ModelsBaseTest): diff --git a/server/tests/test_views.py b/server/tests/test_views.py index cd1082d..caf06b7 100644 --- a/server/tests/test_views.py +++ b/server/tests/test_views.py @@ -603,6 +603,20 @@ class TestViews(ViewBaseTest): data["message"], 'Module definition must be in "n:s", "n:s:v" or ' '"n:s:v:c" format, but got x') + def test_submit_module_build_base_module_in_source(self): + with self.test_request_context(user='dev2'): + flask.g.oidc_scopes = [ + '{0}{1}'.format(conf.oidc_base_namespace, 'new-compose') + ] + + rv = self.client.post('/api/1/composes/', data=json.dumps( + {'source': {'type': 'module', 'source': 'testmodule:master platform:x'}})) + data = json.loads(rv.get_data(as_text=True)) + + self.assertEqual( + data["message"], 'ODCS currently cannot create compose with base ' + 'modules, but platform was requested.') + def test_submit_build_per_user_source_type_allowed(self): with self.test_request_context(user='dev2'): flask.g.oidc_scopes = [