From 347f5ca0e145491d387f60f95b67ef59e7c28316 Mon Sep 17 00:00:00 2001 From: Martin Babinsky Date: Sep 26 2016 16:38:37 +0000 Subject: use separate exception handlers for executors and validators installer framework has been modified to allow for different error handling during validation and execution phases. https://fedorahosted.org/freeipa/ticket/5725 Reviewed-By: Petr Spacek --- diff --git a/ipapython/install/core.py b/ipapython/install/core.py index 9582852..881d3c6 100644 --- a/ipapython/install/core.py +++ b/ipapython/install/core.py @@ -322,7 +322,9 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)): Coroutine which runs the validation part of the configurable. """ - return self.__runner(_VALIDATE_PENDING, _VALIDATE_RUNNING) + return self.__runner(_VALIDATE_PENDING, + _VALIDATE_RUNNING, + self._handle_validate_exception) def execute(self): """ @@ -337,7 +339,9 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)): Coroutine which runs the execution part of the configurable. """ - return self.__runner(_EXECUTE_PENDING, _EXECUTE_RUNNING) + return self.__runner(_EXECUTE_PENDING, + _EXECUTE_RUNNING, + self._handle_execute_exception) def done(self): """ @@ -353,7 +357,7 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)): except StopIteration: break - def __runner(self, pending_state, running_state): + def __runner(self, pending_state, running_state, exc_handler): self.__transition(pending_state, running_state) step = lambda: next(self.__gen) @@ -369,7 +373,7 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)): except BaseException: exc_info = sys.exc_info() try: - self._handle_exception(exc_info) + exc_handler(exc_info) except BaseException: raise else: @@ -393,6 +397,16 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)): six.reraise(*exc_info) + def _handle_validate_exception(self, exc_info): + assert not hasattr(super(Configurable, self), + '_handle_validate_exception') + self._handle_exception(exc_info) + + def _handle_execute_exception(self, exc_info): + assert not hasattr(super(Configurable, self), + '_handle_execute_exception') + self._handle_exception(exc_info) + def __transition(self, from_state, to_state): if self.__state != from_state: raise InvalidStateError(self.__state)