#2651 make policy test thread safe
Merged a year ago by tkopecek. Opened a year ago by mikem.

file modified
+11 -8
@@ -9728,22 +9728,25 @@ 

  

      def __init__(self, str):

          super(PolicyTest, self).__init__(str)

-         self.depth = 0

-         # this is used to detect loops. Note that each test in a ruleset is

-         # a distinct instance of its test class. So this value is particular

-         # to a given appearance of a policy check in a ruleset.

  

      def run(self, data):

          args = self.str.split()[1:]

-         if self.depth != 0:

+         # we store some instance-specific state in context for loop detection

+         # note that context is thread local and cleared after each call

+         # note that this instance represents a specific test in the policy

+         # i.e. each occurrence of 'policy foo' is a separate instance

+         key = 'policy_test_state_%s_running' % id(self)

+         if hasattr(context, key):

              # LOOP!

              raise koji.GenericError("encountered policy loop at %s" % self.str)

          ruleset = context.policy.get(args[0])

          if not ruleset:

              raise koji.GenericError("no such policy: %s" % args[0])

-         self.depth += 1

-         result = ruleset.apply(data)

-         self.depth -= 1

+         setattr(context, key, True)

+         try:

+             result = ruleset.apply(data)

+         finally:

+             delattr(context, key)

          if result is None:

              return False

          else:

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Metadata Update from @jcupova:
- Pull-request untagged with: testing-ready

a year ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-ready

a year ago

Metadata Update from @mfilip:
- Pull-request tagged with: testing-done

a year ago

Commit 10a08e3 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago
Metadata