diff options
-rw-r--r-- | ipapython/install/cli.py | 7 | ||||
-rw-r--r-- | ipapython/install/core.py | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/ipapython/install/cli.py b/ipapython/install/cli.py index 0047eecb0..d2250e516 100644 --- a/ipapython/install/cli.py +++ b/ipapython/install/cli.py @@ -282,7 +282,8 @@ class ConfigureTool(admintool.AdminTool): kwargs = {} transformed_cls = self._transform(self.configurable_class) - for owner_cls, name in transformed_cls.knobs(): + knob_classes = {n: getattr(c, n) for c, n in transformed_cls.knobs()} + for name in knob_classes: value = getattr(self.options, name, None) if value is not None: kwargs[name] = value @@ -294,8 +295,10 @@ class ConfigureTool(admintool.AdminTool): try: cfgr = transformed_cls(**kwargs) except core.KnobValueError as e: - knob_cls = getattr(transformed_cls, e.name) + knob_cls = knob_classes[e.name] try: + if self.positional_arguments is None: + raise IndexError index = self.positional_arguments.index(e.name) except IndexError: cli_name = knob_cls.cli_name or e.name.replace('_', '-') diff --git a/ipapython/install/core.py b/ipapython/install/core.py index 479149be6..8e3ba5802 100644 --- a/ipapython/install/core.py +++ b/ipapython/install/core.py @@ -118,6 +118,16 @@ 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 @@ -243,7 +253,8 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)): except KeyError: pass else: - setattr(self, name, value) + prop = prop_cls(self) + prop.__set__(self, value) if kwargs: extra = sorted(kwargs) |