diff options
author | Martin Babinsky <mbabinsk@redhat.com> | 2015-04-14 13:55:33 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-04-29 05:24:58 +0000 |
commit | 98376589de9b33d7007c8d43366d26f3e3307662 (patch) | |
tree | 65ddf3563b845ba337ebc1d7a98f5cd004b5f36b /ipa-client | |
parent | a1f91247ccf69a60d1e18942e6697f45b951fe4b (diff) | |
download | freeipa-98376589de9b33d7007c8d43366d26f3e3307662.tar.gz freeipa-98376589de9b33d7007c8d43366d26f3e3307662.tar.xz freeipa-98376589de9b33d7007c8d43366d26f3e3307662.zip |
suppress errors arising from deleting non-existent files during client uninstall
When rolling back partially configured IPA client a number of OSErrors pop up
due to uninstaller trying to remove files that do not exist anymore. This
patch supresses these errors while keeping them in log as debug messages.
https://fedorahosted.org/freeipa/ticket/4966
Reviewed-By: Martin Basti <mbasti@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipa-client')
-rwxr-xr-x | ipa-client/ipa-install/ipa-client-install | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/ipa-client/ipa-install/ipa-client-install b/ipa-client/ipa-install/ipa-client-install index 083bcf3ec..efa97a9ae 100755 --- a/ipa-client/ipa-install/ipa-client-install +++ b/ipa-client/ipa-install/ipa-client-install @@ -236,6 +236,25 @@ def logging_setup(options): console_format='%(message)s') +def remove_file(filename): + """ + Deletes a file. If the file does not exist (OSError 2) does nothing. + Otherwise logs an error message and instructs the user to remove the + offending file manually + :param filename: name of the file to be removed + """ + + try: + os.remove(filename) + except OSError as e: + if e.errno == 2: + return + + root_logger.error("Failed to remove file %s: %s", filename, e) + root_logger.error('Please remove %s manually, as it can cause ' + 'subsequent installation to fail.', filename) + + def log_service_error(name, action, error): root_logger.error("%s failed to %s: %s", name, action, str(error)) @@ -541,10 +560,7 @@ def uninstall(options, env): os.path.join(ipa_db.secdir, 'key3.db'), os.path.join(ipa_db.secdir, 'secmod.db'), os.path.join(ipa_db.secdir, 'pwdfile.txt')): - try: - os.remove(filename) - except OSError, e: - root_logger.error("Failed to remove %s: %s", filename, e) + remove_file(filename) for nickname, trust_flags in ipa_certs: while sys_db.has_nickname(nickname): @@ -772,25 +788,13 @@ def uninstall(options, env): 'to its pre-installation state.') # Remove the IPA configuration file - try: - os.remove(paths.IPA_DEFAULT_CONF) - except OSError, e: - root_logger.warning('/etc/ipa/default.conf could not be removed: %s', - str(e)) - root_logger.warning('Please remove /etc/ipa/default.conf manually, ' - 'as it can cause subsequent installation to fail.') + remove_file(paths.IPA_DEFAULT_CONF) # Remove the CA cert from the systemwide certificate store tasks.remove_ca_certs_from_systemwide_ca_store() # Remove the CA cert - try: - os.remove(CACERT) - except OSError, e: - root_logger.warning('%s could not be removed: %s', CACERT, str(e)) - root_logger.warning('Please remove %s manually, ' - 'as it can cause subsequent ' - 'installation to fail.', CACERT) + remove_file(CACERT) root_logger.info("Client uninstall complete.") |