#354 Do not override "global" whitelist with handler-specific whitelist in handler.allow_build().
Merged 3 months ago by jkaluza. Opened 3 months ago by jkaluza.
jkaluza/freshmaker whitelist-overriden  into  master

@@ -25,6 +25,7 @@ 

  import json

  import re

  import six

+ import copy

  from functools import wraps

  

  from freshmaker import conf, log, db, models

@@ -368,8 +369,10 @@ 

          :rtype: bool

          """

          # Global rules

-         whitelist_rules = conf.handler_build_whitelist.get("global", {})

-         blacklist_rules = conf.handler_build_blacklist.get("global", {})

+         whitelist_rules = copy.deepcopy(

+             conf.handler_build_whitelist.get("global", {}))

+         blacklist_rules = copy.deepcopy(

+             conf.handler_build_blacklist.get("global", {}))

  

          # This handler rules

          handler_name = self.name

file modified
+34

@@ -248,6 +248,40 @@ 

      """Test BaseHandler.allow_build"""

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

+         'global': {

+             'image': any_(

+                 {

+                     'advisory_state': 'ON_QA',

+                     'advisory_name': 'RHBA-.*',

+                 }

+             )

+         },

+         'RebuildImagesOnImageAdvisoryChange': {

+             'image': any_(

+                 {

+                     'advisory_state': 'SHIPPED_LIVE',

+                     'advisory_name': 'RHBA-.*',

+                 }

+             )

+         }

+     })

+     def test_whitelist_not_overwritten(self):

+         """

+         Test that "global" config section is not overwritten by handler-specific

+         section after calling the handler.allow_build().

+         """

+         handler = MyHandler()

+         handler.name = "RebuildImagesOnImageAdvisoryChange"

+         allowed = handler.allow_build(

+             ArtifactType.IMAGE, advisory_state="SHIPPED_LIVE")

+         self.assertTrue(allowed)

+ 

+         handler.name = "foo"

+         allowed = handler.allow_build(

+             ArtifactType.IMAGE, advisory_state="SHIPPED_LIVE")

+         self.assertFalse(allowed)

+ 

+     @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

          'MyHandler': {

              'image': {

                  'name': 'test'

The conf.handler_build_whitelist.get() returns directly the dict from the whitelist.
We later called .update() on that dict which effectively changed it in
the conf.handler_build_whitelist.

In this commit, we created copy of that dict instead so the update() does not get
it into the Config class itself and stays local in allow_build method.

rebased onto d6e72d2

3 months ago

Pull-Request has been merged by jkaluza

3 months ago