#1005 Optionally, block building modules with EOL streams.
Merged 5 years ago by mprahl. Opened 5 years ago by ralph.

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

      KOJI_REPOSITORY_URL = 'https://kojipkgs.fedoraproject.org/repos'

      KOJI_TAG_PREFIXES = ['module']

      KOJI_ENABLE_CONTENT_GENERATOR = True

+     CHECK_FOR_EOL = False

      PDC_URL = 'https://pdc.fedoraproject.org/rest_api/v1'

      PDC_INSECURE = False

      PDC_DEVELOP = True

@@ -159,6 +159,14 @@ 

              'type': str,

              'default': 'https://mbs.fedoraproject.org/module-build-service/1/module-builds/',

              'desc': 'MBS instance url for MBSResolver'},

+         'check_for_eol': {

+             'type': bool,

+             'default': False,

+             'desc': 'Flag to determine whether or not MBS should block EOL modules from building.'},

+         'pdc_url': {

+             'type': str,

+             'default': 'https://pdc.fedoraproject.org/rest_api/v1',

+             'desc': 'PDC URL, used for checking stream EOL.'},

          'koji_config': {

              'type': str,

              'default': None,

@@ -29,7 +29,9 @@ 

  import os

  from multiprocessing.dummy import Pool as ThreadPool

  from datetime import datetime

+ 

  import kobo.rpmlib

+ import requests

  

  from module_build_service import conf, db, log, models, Modulemd

  from module_build_service.errors import (
@@ -440,6 +442,26 @@ 

      return modules

  

  

+ def _is_eol_in_pdc(name, stream):

+     """ Check PDC if the module name:stream is no longer active. """

+ 

+     params = {'type': 'module', 'global_component': name, 'name': stream}

+     url = conf.pdc_url + '/component-branches/'

+ 

+     response = requests.get(url, params=params)

+     if not response:

+         raise ValidationError("Failed to talk to PDC {}{}".format(response, response.text))

+ 

+     data = response.json()

+     results = data['results']

+     if not results:

+         raise ValidationError("No such module {}:{} found at {}".format(

+             name, stream, response.request.url))

+ 

+     # If the module is active, then it is not EOL and vice versa.

+     return not results[0]['active']

+ 

+ 

  def _fetch_mmd(url, branch=None, allow_local_url=False, whitelist_url=False):

      # Import it here, because SCM uses utils methods

      # and fails to import them because of dep-chain.
@@ -467,6 +489,11 @@ 

                  "Failed to remove temporary directory {!r}: {}".format(

                      td, str(e)))

  

+     if conf.check_for_eol:

+         if _is_eol_in_pdc(scm.name, scm.branch):

+             raise ValidationError(

+                 'Module {}:{} is marked as EOL in PDC.'.format(scm.name, scm.branch))

+ 

      # If the name was set in the modulemd, make sure it matches what the scmurl

      # says it should be

      if mmd.get_name() and mmd.get_name() != scm.name:

@@ -414,6 +414,25 @@ 

          # Make sure the build is done

          assert module_build.state == models.BUILD_STATES['ready']

  

+     @patch('module_build_service.config.Config.check_for_eol',

+            new_callable=PropertyMock, return_value=True)

+     @patch('module_build_service.utils.submit._is_eol_in_pdc', return_value=True)

+     @patch('module_build_service.auth.get_user', return_value=user)

+     @patch('module_build_service.scm.SCM')

+     def test_submit_build_eol_module(self, mocked_scm, mocked_get_user, is_eol, check,

+                                      conf_system, dbg):

+         """ Tests the build of a module with an eol stream.  """

+         FakeSCM(mocked_scm, 'python3', 'python3-no-components.yaml',

+                 '620ec77321b2ea7b0d67d82992dda3e1d67055b4')

+         rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps(

+             {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/'

+                 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'}))

+ 

+         assert rv.status_code == 400

+         data = json.loads(rv.data)

+         assert data['status'] == 400

+         assert data['message'] == u'Module python3:master is marked as EOL in PDC.'

+ 

      @patch('module_build_service.auth.get_user', return_value=user)

      @patch('module_build_service.scm.SCM')

      def test_submit_build_from_yaml_not_allowed(

@@ -551,6 +551,34 @@ 

          expected_tag = 'module-1cf457d452e54dda'

          assert tag == expected_tag

  

+     @patch("module_build_service.utils.submit.requests")

+     def test_pdc_eol_check(self, requests):

+         """ Push mock pdc responses through the eol check function. """

+ 

+         response = mock.Mock()

+         response.json.return_value = {"results": [{

+             "id": 347907,

+             "global_component": "mariadb",

+             "name": "10.1",

+             "slas": [{

+                 "id": 694207,

+                 "sla": "security_fixes",

+                 "eol": "2019-12-01",

+             }],

+             "type": "module",

+             "active": True,

+             "critical_path": False,

+         }]}

+         requests.get.return_value = response

+ 

+         is_eol = module_build_service.utils.submit._is_eol_in_pdc('mariadb', '10.1')

+         assert not is_eol

+ 

+         response.json.return_value["results"][0]["active"] = False

+ 

+         is_eol = module_build_service.utils.submit._is_eol_in_pdc('mariadb', '10.1')

+         assert is_eol

+ 

  

  class DummyModuleBuilder(GenericBuilder):

      """

How about making this check_for_eol without the pdc prefix? That way if we need to implement this against another system, we don't have to use another config option.

@ralph looks good to me after renaming one of the config names. Is it an issue if a module buildrequires or requires an EOL module? Is that issue handled by another system?

@mprahl, eventually... pungi will kick out modules that are EOL which covers the transitive requires part.

1 new commit added

  • Rename this to be PDC-agnostic.
5 years ago

Pull-Request has been merged by mprahl

5 years ago