On 07/12/15 14:05, David Kupka wrote:
Running validators after all Knobs are set allows use of other Knob
value during validation.

Updated patch attached.

--
David Kupka
From 7f18ac0d8b78ea08ed797ceb9393c6b3121b734d Mon Sep 17 00:00:00 2001
From: David Kupka <dku...@redhat.com>
Date: Mon, 7 Dec 2015 13:35:49 +0100
Subject: [PATCH] install: Run all validators at once.

---
 ipapython/install/core.py | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/ipapython/install/core.py b/ipapython/install/core.py
index 8e3ba58021adba263eb038c5cb70603e4e8c9352..2f62b8568fea129255e42b404789fd29b70dca7c 100644
--- a/ipapython/install/core.py
+++ b/ipapython/install/core.py
@@ -118,16 +118,6 @@ class KnobBase(PropertyBase):
     def __init__(self, outer):
         self.outer = outer
 
-    def __set__(self, obj, value):
-        try:
-            self.validate(value)
-        except KnobValueError:
-            raise
-        except ValueError as e:
-            raise KnobValueError(self.__outer_name__, str(e))
-
-        super(KnobBase, self).__set__(obj, value)
-
     def validate(self, value):
         pass
 
@@ -253,8 +243,25 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)):
             except KeyError:
                 pass
             else:
-                prop = prop_cls(self)
-                prop.__set__(self, value)
+                setattr(self, name, value)
+
+        for owner_cls, name in cls.knobs():
+            if name.startswith('_'):
+                continue
+            if not isinstance(self, owner_cls):
+                continue
+            value = getattr(self, name, None)
+            if value is None:
+                continue
+
+            prop_cls = getattr(owner_cls, name)
+            prop = prop_cls(self)
+            try:
+                prop.validate(value)
+            except KnobValueError:
+                raise
+            except ValueError as e:
+                raise KnobValueError(name, str(e))
 
         if kwargs:
             extra = sorted(kwargs)
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to