summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Bokovoy <abokovoy@redhat.com>2014-01-15 17:26:10 +0100
committerMartin Kosek <mkosek@redhat.com>2014-01-15 17:44:10 +0100
commitcb411ff94e71579e2a608319b1c7eab877b98019 (patch)
treeb87054bcfbd7c6a1a5c8f61096b25617241a99b6
parent487a8f4749bfff9206564abe43e73c0a8362d05b (diff)
downloadfreeipa-cb411ff94e71579e2a608319b1c7eab877b98019.tar.gz
freeipa-cb411ff94e71579e2a608319b1c7eab877b98019.tar.xz
freeipa-cb411ff94e71579e2a608319b1c7eab877b98019.zip
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.
-rw-r--r--ipaserver/install/installutils.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index cc53f75c..c6376d82 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -786,15 +786,16 @@ def private_ccache(path=None):
os.environ['KRB5CCNAME'] = path
- yield
-
- if original_value is not None:
- os.environ['KRB5CCNAME'] = original_value
- else:
- os.environ.pop('KRB5CCNAME')
+ try:
+ yield
+ finally:
+ 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
@@ -827,6 +828,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)