#44 Remove event from whitelist and blacklist
Merged 8 years ago by qwan. Opened 8 years ago by qwan.

file modified
+19 -25
@@ -80,45 +80,39 @@ 

      SSL_ENABLED = False

  

      # whitelist and blacklist for handlers to decide whether an artifact

-     # can be built on some events.

+     # can be built.

      #

      # In format of:

      #

      # { <handler_name> :

-     #     { <event_name> :

-     #         { <artifact_type>: <list_of_name_branch_dict> }

-     #     }

+     #     { <artifact_type>: <list_of_name_branch_dict> }

      # }

      #

-     # Here is an example of allowing MBS handler to build any module on

-     # "RPMSpecUpdated" event that module name matches 'base-.*' but not:

+     # Here is an example of allowing MBSModuleStateChangeHandler to build

+     # any module that module name matches 'base-.*' but not:

      #   1. module name matches 'base-test-module'

      # or:

      #   2. module from branch 'rawhide'

      #

      # HANDLER_BUILD_WHITELIST = {

-     #     "MBS": {

-     #         "RPMSpecUpdated": {

-     #             "module": [

-     #                 {

-     #                     'name': 'base-.*',

-     #                 },

-     #             ],

-     #         },

+     #     "MBSModuleStateChangeHandler": {

+     #         "module": [

+     #             {

+     #                 'name': 'base-.*',

+     #             },

+     #         ],

      #     },

      # }

      # HANDLER_BUILD_BLACKLIST = {

-     #     "MBS": {

-     #         "RPMSpecUpdated": {

-     #             "module": [

-     #                 {

-     #                     'name': 'base-test-module',

-     #                 },

-     #                 {

-     #                     'branch': 'rawhide',

-     #                 },

-     #             ],

-     #         },

+     #     "MBSModuleStateChangeHandler": {

+     #         "module": [

+     #             {

+     #                 'name': 'base-test-module',

+     #             },

+     #             {

+     #                 'branch': 'rawhide',

+     #             },

+     #         ],

      #     },

      # }

  

@@ -129,18 +129,17 @@ 

          models.ArtifactBuild.create(db.session, ev, name, type, build_id, dep_of)

          db.session.commit()

  

-     def allow_build(self, event, artifact_type, name, branch):

+     def allow_build(self, artifact_type, name, branch):

          """

          Check whether the artifact is allowed to be built by checking

          HANDLER_BUILD_WHITELIST and HANDLER_BUILD_BLACKLIST in config.

  

-         :param event: event instance.

          :param artifact_type: 'module' or 'image'.

          :param name: name of the artifact.

          :param branch: branch name of the artifact.

          :return: True or False.

          """

-         # If there is a whitelist specified for the (handler, event, artifact_type),

+         # If there is a whitelist specified for the (handler, artifact_type),

          # the build target of (name, branch) need to be in that whitelist first.

          # After that (if the build target is in whitelist), check the build target

          # is not in the specified blacklist.
@@ -150,9 +149,8 @@ 

          in_blacklist = False

  

          handler_name = self.name

-         event_name = type(event).__name__

-         whitelist_rules = conf.handler_build_whitelist.get(handler_name, {}).get(event_name, {})

-         blacklist_rules = conf.handler_build_blacklist.get(handler_name, {}).get(event_name, {})

+         whitelist_rules = conf.handler_build_whitelist.get(handler_name, {})

+         blacklist_rules = conf.handler_build_blacklist.get(handler_name, {})

  

          def match_rule(name, branch, rule):

              name_rule = rule.get('name', None)
@@ -179,8 +177,8 @@ 

                      in_blacklist = True

  

          except re.error as exc:

-             log.error("Error while compiling blacklist/whilelist rule for <handler(%s) event(%s) artifact(%s)>:\n"

+             log.error("Error while compiling blacklist/whilelist rule for <handler(%s) artifact(%s)>:\n"

                        "Incorrect regular expression: %s\nBlacklist and Whitelist will not take effect",

-                       handler_name, event_name, artifact_type, str(exc))

+                       handler_name, artifact_type, str(exc))

              return True

          return in_whitelist and not in_blacklist

@@ -49,7 +49,7 @@ 

          log.info('Found docker images to rebuild: %s', containers)

  

          for container in containers:

-             if not self.allow_build(event, 'image', container['name'], container['branch']):

+             if not self.allow_build('image', container['name'], container['branch']):

                  log.info("Skip rebuild of image %s:%s as it's not allowed by configured whitelist/blacklist",

                           container['name'], container['branch'])

                  continue

@@ -38,7 +38,7 @@ 

  

          log.info('Start to rebuild docker image %s.', event.container)

  

-         if not self.allow_build(event, 'image', event.container, event.branch):

+         if not self.allow_build('image', event.container, event.branch):

              log.info("Skip rebuild of %s:%s as it's not allowed by configured whitelist/blacklist",

                       event.container, event.branch)

              return []

@@ -39,7 +39,7 @@ 

      def handle(self, event):

          log.info("Triggering rebuild of module %s:%s, metadata updated (%s).",

                   event.module, event.branch, event.rev)

-         if not self.allow_build(event, 'module', event.module, event.branch):

+         if not self.allow_build('module', event.module, event.branch):

              log.info("Skip rebuild of %s:%s as it's not allowed by configured whitelist/blacklist",

                       event.module, event.branch)

              return []

@@ -53,7 +53,7 @@ 

          for module in modules:

              name = module['variant_name']

              version = module['variant_version']

-             if not self.allow_build(event, 'module', name, version):

+             if not self.allow_build('module', name, version):

                  log.info("Skip rebuild of %s:%s as it's not allowed by configured whitelist/blacklist",

                           name, version)

                  continue

@@ -77,7 +77,7 @@ 

              for mod in modules:

                  name = mod['variant_name']

                  version = mod['variant_version']

-                 if not self.allow_build(event, 'module', name, version):

+                 if not self.allow_build('module', name, version):

                      log.info("Skip rebuild of %s:%s as it's not allowed by configured whitelist/blacklist",

                               name, version)

                      continue

@@ -113,13 +113,11 @@ 

      def test_module_is_not_allowed_in_whitelist(self, conf, utils, PDC):

          conf.handler_build_whitelist = {

              "MBSModuleStateChangeHandler": {

-                 "MBSModuleStateChangeEvent": {

-                     "module": [

-                         {

-                             'name': 'base.*',

-                         },

-                     ],

-                 },

+                 "module": [

+                     {

+                         'name': 'base.*',

+                     },

+                 ],

              },

          }

          conf.handler_build_blacklist = {}
@@ -150,13 +148,11 @@ 

          conf.handler_build_whitelist = {}

          conf.handler_build_blacklist = {

              "MBSModuleStateChangeHandler": {

-                 "MBSModuleStateChangeEvent": {

-                     "module": [

-                         {

-                             'name': 'test.*',

-                         },

-                     ],

-                 },

+                 "module": [

+                     {

+                         'name': 'test.*',

+                     },

+                 ],

              },

          }

          msg = helpers.ModuleStateChangeMessage('testmodule', 'master', state='ready').produce()