9991ea
From fcd4ec48c2515aff7c10f10653628631d832146b Mon Sep 17 00:00:00 2001
9991ea
From: Alexander Bokovoy <abokovoy@redhat.com>
9991ea
Date: Wed, 15 Jan 2014 17:26:10 +0100
9991ea
Subject: [PATCH 26/27] ipaserver/install/installutils: clean up properly after
9991ea
 yield
9991ea
9991ea
When a context to which we yield generates exception, the code in
9991ea
private_ccache() and stopped_service() didn't get called for cleanup.
9991ea
---
9991ea
 ipaserver/install/installutils.py | 25 ++++++++++++++-----------
9991ea
 1 file changed, 14 insertions(+), 11 deletions(-)
9991ea
9991ea
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
9991ea
index c26f072f2f44149746d55b1160d09ebce8394fd5..3770432cae79f653fd57f726de43787dec8dd7d1 100644
9991ea
--- a/ipaserver/install/installutils.py
9991ea
+++ b/ipaserver/install/installutils.py
9991ea
@@ -784,15 +784,16 @@ def private_ccache(path=None):
9991ea
 
9991ea
     os.environ['KRB5CCNAME'] = path
9991ea
 
9991ea
-    yield
9991ea
+    try:
9991ea
+        yield
9991ea
+    finally:
9991ea
+        if original_value is not None:
9991ea
+            os.environ['KRB5CCNAME'] = original_value
9991ea
+        else:
9991ea
+            os.environ.pop('KRB5CCNAME')
9991ea
 
9991ea
-    if original_value is not None:
9991ea
-        os.environ['KRB5CCNAME'] = original_value
9991ea
-    else:
9991ea
-        os.environ.pop('KRB5CCNAME')
9991ea
-
9991ea
-    if os.path.exists(path):
9991ea
-        os.remove(path)
9991ea
+        if os.path.exists(path):
9991ea
+            os.remove(path)
9991ea
 
9991ea
 
9991ea
 @contextmanager
9991ea
@@ -825,6 +826,8 @@ def stopped_service(service, instance_name=""):
9991ea
         # Stop the service, do the required stuff and start it again
9991ea
         root_logger.debug('Stopping %s%s.', service, log_instance_name)
9991ea
         ipaservices.knownservices[service].stop(instance_name)
9991ea
-        yield
9991ea
-        root_logger.debug('Starting %s%s.', service, log_instance_name)
9991ea
-        ipaservices.knownservices[service].start(instance_name)
9991ea
+        try:
9991ea
+            yield
9991ea
+        finally:
9991ea
+            root_logger.debug('Starting %s%s.', service, log_instance_name)
9991ea
+            ipaservices.knownservices[service].start(instance_name)
9991ea
-- 
9991ea
1.8.4.2
9991ea