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