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>
This commit is contained in:
Martin Babinsky 2015-04-14 13:55:33 +02:00 committed by Jan Cholasta
parent a1f91247cc
commit 98376589de

View File

@ -236,6 +236,25 @@ def logging_setup(options):
console_format='%(message)s') 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): def log_service_error(name, action, error):
root_logger.error("%s failed to %s: %s", name, action, str(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, 'key3.db'),
os.path.join(ipa_db.secdir, 'secmod.db'), os.path.join(ipa_db.secdir, 'secmod.db'),
os.path.join(ipa_db.secdir, 'pwdfile.txt')): os.path.join(ipa_db.secdir, 'pwdfile.txt')):
try: remove_file(filename)
os.remove(filename)
except OSError, e:
root_logger.error("Failed to remove %s: %s", filename, e)
for nickname, trust_flags in ipa_certs: for nickname, trust_flags in ipa_certs:
while sys_db.has_nickname(nickname): while sys_db.has_nickname(nickname):
@ -772,25 +788,13 @@ def uninstall(options, env):
'to its pre-installation state.') 'to its pre-installation state.')
# Remove the IPA configuration file # Remove the IPA configuration file
try: remove_file(paths.IPA_DEFAULT_CONF)
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 the CA cert from the systemwide certificate store # Remove the CA cert from the systemwide certificate store
tasks.remove_ca_certs_from_systemwide_ca_store() tasks.remove_ca_certs_from_systemwide_ca_store()
# Remove the CA cert # Remove the CA cert
try: remove_file(CACERT)
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)
root_logger.info("Client uninstall complete.") root_logger.info("Client uninstall complete.")