#233 Do not add base module into the compose and do not accept it in 'source'.
Merged 6 months ago by jkaluza. Opened 6 months ago by jkaluza.
jkaluza/odcs no-base-modules  into  master

@@ -342,7 +342,8 @@ 

  

          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)

  

  

@@ -246,6 +246,11 @@ 

              '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': '',

file modified
+6 -1

@@ -243,10 +243,15 @@ 

                      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)

  

@@ -576,6 +576,37 @@ 

  

              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):

  

@@ -603,6 +603,20 @@ 

              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 = [

Base modules like platform are special. They exist in MBS database, but they do not exist as module build in Koji. Pungi also cannot generate compose including the base module.

Currently, the ODCS fails to generate compose if user requests compose with base module and sends back confusing message back to user. This PR makes the message clear.

Currently, the ODCS also tries to include base module as a dependency for other modules, which also ends up with error message. This PR by default does not try including base modules as a dependency.

In the future, we will introduce new include_base_module flag which will tell Pungi to do so called "hybrid" compose which is based on the particular platform version, but for now, just fix the current behaviour and make it clearer.

Pull-Request has been merged by jkaluza

6 months ago