Martin Sivák has uploaded a new change for review.

Change subject: Create new evaluator for each evaluation run
......................................................................

Create new evaluator for each evaluation run

MoM used one evaluator for all the policy runs. That caused weird
side effects because the stack already contained old values from
previous runs.

Policies could not be evaluated properly because we changed defvar
semantic from set to setdefault in one of previous patches.

Change-Id: I3d5343e94d8ecddca0e0c9dd7fc893d94e751378
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1025845
Signed-off-by: Martin Sivak <msi...@redhat.com>
---
M mom/Policy/Policy.py
1 file changed, 6 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/04/21704/1

diff --git a/mom/Policy/Policy.py b/mom/Policy/Policy.py
index 3bcdea1..6d2fbbd 100644
--- a/mom/Policy/Policy.py
+++ b/mom/Policy/Policy.py
@@ -26,7 +26,6 @@
     def __init__(self):
         self.logger = logging.getLogger('mom.Policy')
         self.policy_sem = threading.Semaphore()
-        self.evaluator = Evaluator()
         self.clear_policy()
 
     def get_strings(self, name=None):
@@ -62,7 +61,7 @@
             else:
                 self.policy_strings[name] = policyStr
             try:
-                self.code = get_code(self.evaluator, self._cat_policies())
+                self.code = get_code(Evaluator(), self._cat_policies())
             except PolicyError, e:
                 self.logger.warn("Unable to load policy: %s" % e)
                 if oldStr is None:
@@ -81,13 +80,15 @@
 
     def evaluate(self, host, guest_list):
         results = []
-        self.evaluator.stack.set('Host', host, alloc=True)
-        self.evaluator.stack.set('Guests', guest_list, alloc=True)
+        # each run needs separate evaluator so the stack is clean
+        evaluator = Evaluator()
+        evaluator.stack.set('Host', host, alloc=True)
+        evaluator.stack.set('Guests', guest_list, alloc=True)
 
         with self.policy_sem:
             try:
                 for expr in self.code:
-                    results.append(self.evaluator.eval(expr))
+                    results.append(evaluator.eval(expr))
                 self.logger.debug("Results: %s" % results)
             except PolicyError as e:
                 self.logger.error("Policy error: %s" % e)


-- 
To view, visit http://gerrit.ovirt.org/21704
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d5343e94d8ecddca0e0c9dd7fc893d94e751378
Gerrit-PatchSet: 1
Gerrit-Project: mom
Gerrit-Branch: master
Gerrit-Owner: Martin Sivák <msi...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to