URL: https://github.com/freeipa/freeipa/pull/98
Author: martbab
 Title: #98: Make server uninstaller exit with non-zero exit status during 
failed validation
Action: opened

PR body:
"""
https://fedorahosted.org/freeipa/ticket/5725
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/98/head:pr98
git checkout pr98
From 96f61a20e5bf0d6c1a945bc6288700b7531ac315 Mon Sep 17 00:00:00 2001
From: Martin Babinsky <mbabi...@redhat.com>
Date: Tue, 20 Sep 2016 15:12:30 +0200
Subject: [PATCH 1/2] 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
---
 ipapython/install/core.py | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

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 @@ def _validator(self):
         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 @@ def _executor(self):
         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 @@ def run_until_executing(self, gen):
             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 @@ def __runner(self, pending_state, running_state):
             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 @@ def _handle_exception(self, exc_info):
 
         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)

From 8c990e0407c9682a306e2c9d66c768aa6be87b0e Mon Sep 17 00:00:00 2001
From: Martin Babinsky <mbabi...@redhat.com>
Date: Tue, 20 Sep 2016 15:15:50 +0200
Subject: [PATCH 2/2] Make Continuous installer continuous only during
 execution phase

`common.Continuous` class is a basis for uninstallers, which should execute
all the steps regardless of occuring errors. However, we would like the
installer to raise exceptions and return non-zero exit code during validation
phase when some preconditions are not met.

Add a separate exception handler which catches exceptions and logs them as
errors during execution phase only.

https://fedorahosted.org/freeipa/ticket/5725
---
 ipapython/install/common.py | 4 ++--
 ipapython/install/core.py   | 5 +----
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/ipapython/install/common.py b/ipapython/install/common.py
index 799ce50..fc8e332 100644
--- a/ipapython/install/common.py
+++ b/ipapython/install/common.py
@@ -86,9 +86,9 @@ class Interactive(core.Configurable):
 
 
 class Continuous(core.Configurable):
-    def _handle_exception(self, exc_info):
+    def _handle_execute_exception(self, exc_info):
         try:
-            super(Continuous, self)._handle_exception(exc_info)
+            super(Continuous, self)._handle_execute_exception(exc_info)
         except BaseException as e:
             self.log.debug(traceback.format_exc())
             if isinstance(e, Exception):
diff --git a/ipapython/install/core.py b/ipapython/install/core.py
index 881d3c6..8593690 100644
--- a/ipapython/install/core.py
+++ b/ipapython/install/core.py
@@ -375,11 +375,8 @@ def __runner(self, pending_state, running_state, exc_handler):
                 try:
                     exc_handler(exc_info)
                 except BaseException:
-                    raise
-                else:
-                    break
-                finally:
                     self.__transition(running_state, _FAILED)
+                    raise
 
             if self.__state != running_state:
                 break
-- 
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