From 98376589de9b33d7007c8d43366d26f3e3307662 Mon Sep 17 00:00:00 2001 From: Martin Babinsky Date: Tue, 14 Apr 2015 13:55:33 +0200 Subject: 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 Reviewed-By: Jan Cholasta --- ipa-client/ipa-install/ipa-client-install | 40 +++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'ipa-client') 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.") -- cgit