diff options
author | Alexander Bokovoy <abokovoy@redhat.com> | 2014-01-15 17:26:10 +0100 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2014-01-15 17:44:15 +0100 |
commit | f4739bc5217713cc208db292053a5f5665ea2284 (patch) | |
tree | fe411984adcb12da1b1da2461fd0080d083b72e2 | |
parent | 0292b1726b7d73e60c1bca0612d67fecb0c2347d (diff) | |
download | freeipa.git-f4739bc5217713cc208db292053a5f5665ea2284.tar.gz freeipa.git-f4739bc5217713cc208db292053a5f5665ea2284.tar.xz freeipa.git-f4739bc5217713cc208db292053a5f5665ea2284.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.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index c26f072f..3770432c 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 - - 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 @@ -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) |