Move install script error handling to a common function

All of our install/admin scripts had a try/except block calling the
main function and handling common exceptions. These were copy-pasted
from each other and modified to various levels of sophistication.
This refactors them out of installers to a single function, which
includes a final pass/fail message for all of the scripts.

Non-install scripts that set up the same log handler levels for
stderr and log file are not changed, as it's not possible to log
to only the logfile without changing the logger configuration.

https://fedorahosted.org/freeipa/ticket/2071
This commit is contained in:
Petr Viktorin
2012-05-31 14:34:09 +02:00
committed by Martin Kosek
parent 9e877585e2
commit 0ca29fac9a
13 changed files with 243 additions and 267 deletions

View File

@@ -21,8 +21,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import traceback
from ipaserver.plugins.ldap2 import ldap2 from ipaserver.plugins.ldap2 import ldap2
from ipaserver.install import adtrustinstance from ipaserver.install import adtrustinstance
from ipaserver.install.installutils import * from ipaserver.install.installutils import *
@@ -35,6 +33,8 @@ import krbV
import ldap import ldap
from ipapython.ipa_log_manager import * from ipapython.ipa_log_manager import *
log_file_name = "/var/log/ipaserver-install.log"
def parse_options(): def parse_options():
parser = IPAOptionParser(version=version.VERSION) parser = IPAOptionParser(version=version.VERSION)
parser.add_option("-p", "--ds-password", dest="dm_password", parser.add_option("-p", "--ds-password", dest="dm_password",
@@ -86,8 +86,8 @@ def main():
if os.getegid() != 0: if os.getegid() != 0:
sys.exit("Must be root to setup AD trusts on server") sys.exit("Must be root to setup AD trusts on server")
standard_logging_setup("/var/log/ipaserver-install.log", debug=options.debug, filemode='a') standard_logging_setup(log_file_name, debug=options.debug, filemode='a')
print "\nThe log file for this installation can be found in /var/log/ipaserver-install.log" print "\nThe log file for this installation can be found in %s" % log_file_name
root_logger.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options)) root_logger.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options))
root_logger.debug("missing options might be asked for interactively later\n") root_logger.debug("missing options might be asked for interactively later\n")
@@ -227,26 +227,6 @@ def main():
return 0 return 0
try: if __name__ == '__main__':
sys.exit(main()) installutils.run_script(main, log_file_name=log_file_name,
except SystemExit, e: operation_name='ipa-adtrust-install')
sys.exit(e)
except KeyboardInterrupt:
print "Installation cancelled."
except RuntimeError, e:
print str(e)
except HostnameLocalhost:
print "The hostname resolves to the localhost address (127.0.0.1/::1)"
print "Please change your /etc/hosts file so that the hostname"
print "resolves to the ip address of your network interface."
print "The KDC service does not listen on localhost"
print ""
print "Please fix your /etc/hosts file and restart the setup program"
except Exception, e:
message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
print message
message = str(e)
for str in traceback.format_tb(sys.exc_info()[2]):
message = message + "\n" + str
root_logger.debug(message)
sys.exit(1)

View File

@@ -21,7 +21,7 @@
import sys import sys
import socket import socket
import os, traceback, shutil import os, shutil
from ipapython import ipautil from ipapython import ipautil
from ipapython import services as ipaservices from ipapython import services as ipaservices
@@ -39,8 +39,9 @@ from ipapython.config import IPAOptionParser
from ipapython import sysrestore from ipapython import sysrestore
from ipapython.ipa_log_manager import * from ipapython.ipa_log_manager import *
CACERT="/etc/ipa/ca.crt" log_file_name = "/var/log/ipareplica-ca-install.log"
REPLICA_INFO_TOP_DIR=None CACERT = "/etc/ipa/ca.crt"
REPLICA_INFO_TOP_DIR = None
def parse_options(): def parse_options():
usage = "%prog [options] REPLICA_FILE" usage = "%prog [options] REPLICA_FILE"
@@ -72,7 +73,12 @@ def get_dirman_password():
def main(): def main():
safe_options, options, filename = parse_options() safe_options, options, filename = parse_options()
standard_logging_setup("/var/log/ipareplica-ca-install.log", debug=options.debug)
if os.geteuid() != 0:
sys.exit("\nYou must be root to run this script.\n")
standard_logging_setup(log_file_name, debug=options.debug)
root_logger.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options)) root_logger.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options))
if not ipautil.file_exists(filename): if not ipautil.file_exists(filename):
@@ -150,41 +156,20 @@ def main():
# We need to restart apache as we drop a new config file in there # We need to restart apache as we drop a new config file in there
ipaservices.knownservices.httpd.restart(capture_output=True) ipaservices.knownservices.httpd.restart(capture_output=True)
try: fail_message = '''
if not os.geteuid()==0: Your system may be partly configured.
sys.exit("\nYou must be root to run this script.\n") Run /usr/sbin/ipa-server-install --uninstall to clean up.
'''
main() if __name__ == '__main__':
sys.exit(0)
except SystemExit, e:
sys.exit(e)
except socket.error, (errno, errstr):
print errstr
except HostnameLocalhost:
print "The hostname resolves to the localhost address (127.0.0.1/::1)"
print "Please change your /etc/hosts file so that the hostname"
print "resolves to the ip address of your network interface."
print ""
print "Please fix your /etc/hosts file and restart the setup program"
except Exception, e:
print "creation of replica failed: %s" % str(e)
message = str(e)
for str in traceback.format_tb(sys.exc_info()[2]):
message = message + "\n" + str
root_logger.debug(message)
except KeyboardInterrupt:
print "Installation cancelled."
finally:
# always try to remove decrypted replica file
try: try:
if REPLICA_INFO_TOP_DIR: installutils.run_script(main, log_file_name=log_file_name,
shutil.rmtree(REPLICA_INFO_TOP_DIR) operation_name='ipa-ca-install',
except OSError: fail_message=fail_message)
pass finally:
# always try to remove decrypted replica file
print "" try:
print "Your system may be partly configured." if REPLICA_INFO_TOP_DIR:
print "Run /usr/sbin/ipa-server-install --uninstall to clean up." shutil.rmtree(REPLICA_INFO_TOP_DIR)
except OSError:
# the only way to get here is on error or ^C pass
sys.exit(1)

View File

@@ -196,24 +196,5 @@ def main():
return retval return retval
try: if __name__ == '__main__':
if __name__ == "__main__": installutils.run_script(main, operation_name='ipa-compat-manage')
sys.exit(main())
except BadSyntax, e:
print "There is a syntax error in this update file:"
print " %s" % e
sys.exit(1)
except RuntimeError, e:
print "%s" % e
sys.exit(1)
except SystemExit, e:
sys.exit(e)
except KeyboardInterrupt, e:
sys.exit(1)
except config.IPAConfigError, e:
print "An IPA server to update cannot be found. Has one been configured yet?"
print "The error was: %s" % e
sys.exit(1)
except errors.LDAPError, e:
print "An error occurred while performing operations: %s" % e
sys.exit(1)

View File

@@ -19,8 +19,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import traceback
from ipaserver.plugins.ldap2 import ldap2 from ipaserver.plugins.ldap2 import ldap2
from ipaserver.install import service, bindinstance, ntpinstance, httpinstance from ipaserver.install import service, bindinstance, ntpinstance, httpinstance
from ipaserver.install.installutils import * from ipaserver.install.installutils import *
@@ -34,6 +32,8 @@ import krbV
import ldap import ldap
from ipapython.ipa_log_manager import * from ipapython.ipa_log_manager import *
log_file_name = "/var/log/ipaserver-install.log"
def parse_options(): def parse_options():
parser = IPAOptionParser(version=version.VERSION) parser = IPAOptionParser(version=version.VERSION)
parser.add_option("-p", "--ds-password", dest="dm_password", parser.add_option("-p", "--ds-password", dest="dm_password",
@@ -89,8 +89,8 @@ def main():
if os.getegid() != 0: if os.getegid() != 0:
sys.exit("Must be root to setup server") sys.exit("Must be root to setup server")
standard_logging_setup("/var/log/ipaserver-install.log", debug=options.debug, filemode='a') standard_logging_setup(log_file_name, debug=options.debug, filemode='a')
print "\nThe log file for this installation can be found in /var/log/ipaserver-install.log" print "\nThe log file for this installation can be found in %s" % log_file_name
root_logger.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options)) root_logger.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options))
root_logger.debug("missing options might be asked for interactively later\n") root_logger.debug("missing options might be asked for interactively later\n")
@@ -243,26 +243,6 @@ def main():
return 0 return 0
try: if __name__ == '__main__':
sys.exit(main()) installutils.run_script(main, log_file_name=log_file_name,
except SystemExit, e: operation_name='ipa-dns-install')
sys.exit(e)
except KeyboardInterrupt:
print "Installation cancelled."
except RuntimeError, e:
print str(e)
except HostnameLocalhost:
print "The hostname resolves to the localhost address (127.0.0.1/::1)"
print "Please change your /etc/hosts file so that the hostname"
print "resolves to the ip address of your network interface."
print "The KDC service does not listen on localhost"
print ""
print "Please fix your /etc/hosts file and restart the setup program"
except Exception, e:
message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
print message
message = str(e)
for str in traceback.format_tb(sys.exc_info()[2]):
message = message + "\n" + str
root_logger.debug(message)
sys.exit(1)

View File

@@ -237,20 +237,5 @@ def main():
return retval return retval
try: if __name__ == '__main__':
if __name__ == "__main__": installutils.run_script(main, operation_name='ipa-managed-entries')
sys.exit(main())
except RuntimeError, e:
print "%s" % e
sys.exit(1)
except SystemExit, e:
sys.exit(e)
except KeyboardInterrupt, e:
sys.exit(1)
except config.IPAConfigError, e:
print "An IPA server to update cannot be found. Has one been configured yet?"
print "The error was: %s" % e
sys.exit(1)
except errors.LDAPError, e:
print "An error occurred while performing operations: %s" % e
sys.exit(1)

View File

@@ -200,24 +200,5 @@ def main():
return retval return retval
try: if __name__ == '__main__':
if __name__ == "__main__": installutils.run_script(main, operation_name='ipa-nis-manage')
sys.exit(main())
except BadSyntax, e:
print "There is a syntax error in this update file:"
print " %s" % e
sys.exit(1)
except RuntimeError, e:
print "%s" % e
sys.exit(1)
except SystemExit, e:
sys.exit(e)
except KeyboardInterrupt, e:
sys.exit(1)
except config.IPAConfigError, e:
print "An IPA server to update cannot be found. Has one been configured yet?"
print "The error was: %s" % e
sys.exit(1)
except errors.LDAPError, e:
print "An error occurred while performing operations: %s" % e
sys.exit(1)

View File

@@ -21,7 +21,7 @@
import sys import sys
import socket import socket
import os, pwd, traceback, shutil import os, pwd, shutil
import grp import grp
from optparse import OptionGroup from optparse import OptionGroup
@@ -43,8 +43,9 @@ from ipapython import sysrestore
from ipapython import services as ipaservices from ipapython import services as ipaservices
from ipapython.ipa_log_manager import * from ipapython.ipa_log_manager import *
CACERT="/etc/ipa/ca.crt" log_file_name = "/var/log/ipareplica-install.log"
REPLICA_INFO_TOP_DIR=None CACERT = "/etc/ipa/ca.crt"
REPLICA_INFO_TOP_DIR = None
def parse_options(): def parse_options():
usage = "%prog [options] REPLICA_FILE" usage = "%prog [options] REPLICA_FILE"
@@ -278,7 +279,11 @@ def check_bind():
def main(): def main():
ipaservices.check_selinux_status() ipaservices.check_selinux_status()
safe_options, options, filename = parse_options() safe_options, options, filename = parse_options()
standard_logging_setup("/var/log/ipareplica-install.log", debug=options.debug)
if os.geteuid() != 0:
sys.exit("\nYou must be root to run this script.\n")
standard_logging_setup(log_file_name, debug=options.debug)
root_logger.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options)) root_logger.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options))
if not ipautil.file_exists(filename): if not ipautil.file_exists(filename):
@@ -502,41 +507,20 @@ def main():
#Everything installed properly, activate ipa service. #Everything installed properly, activate ipa service.
ipaservices.knownservices.ipa.enable() ipaservices.knownservices.ipa.enable()
try: fail_message = '''
if not os.geteuid()==0: Your system may be partly configured.
sys.exit("\nYou must be root to run this script.\n") Run /usr/sbin/ipa-server-install --uninstall to clean up.
'''
main() if __name__ == '__main__':
sys.exit(0)
except SystemExit, e:
sys.exit(e)
except socket.error, (errno, errstr):
print errstr
except HostnameLocalhost:
print "The hostname resolves to the localhost address (127.0.0.1/::1)"
print "Please change your /etc/hosts file so that the hostname"
print "resolves to the ip address of your network interface."
print ""
print "Please fix your /etc/hosts file and restart the setup program"
except Exception, e:
print "creation of replica failed: %s" % str(e)
message = str(e)
for str in traceback.format_tb(sys.exc_info()[2]):
message = message + "\n" + str
root_logger.debug(message)
except KeyboardInterrupt:
print "Installation cancelled."
finally:
# always try to remove decrypted replica file
try: try:
if REPLICA_INFO_TOP_DIR: installutils.run_script(main, log_file_name=log_file_name,
shutil.rmtree(REPLICA_INFO_TOP_DIR) operation_name='ipa-replica-install',
except OSError: fail_message=fail_message)
pass finally:
# always try to remove decrypted replica file
print "" try:
print "Your system may be partly configured." if REPLICA_INFO_TOP_DIR:
print "Run /usr/sbin/ipa-server-install --uninstall to clean up." shutil.rmtree(REPLICA_INFO_TOP_DIR)
except OSError:
# the only way to get here is on error or ^C pass
sys.exit(1)

View File

@@ -31,6 +31,7 @@ from ipapython.ipautil import user_input
from ipaserver.install import certs, dsinstance, httpinstance, installutils from ipaserver.install import certs, dsinstance, httpinstance, installutils
from ipalib import api from ipalib import api
from ipapython.ipa_log_manager import *
from ipaserver.plugins.ldap2 import ldap2 from ipaserver.plugins.ldap2 import ldap2
def get_realm_name(): def get_realm_name():
@@ -120,12 +121,17 @@ def import_cert(dirname, pkcs12_fname, pkcs12_passwd, db_password):
return server_cert return server_cert
def main(): def main():
if os.geteuid() != 0:
sys.exit("\nYou must be root to run this script.\n")
installutils.check_server_configuration() installutils.check_server_configuration()
options, pkcs12_fname = parse_options() options, pkcs12_fname = parse_options()
cfg = dict(in_server=True,) cfg = dict(in_server=True,)
standard_logging_setup("/var/log/ipa/default.log")
api.bootstrap(**cfg) api.bootstrap(**cfg)
api.finalize() api.finalize()
@@ -165,12 +171,5 @@ def main():
return 0 return 0
try: if __name__ == '__main__':
if not os.geteuid()==0: installutils.run_script(main, operation_name='ipa-server-certinstall')
sys.exit("\nYou must be root to run this script.\n")
main()
except SystemExit, e:
sys.exit(e)
except RuntimeError, e:
sys.exit(e)

View File

@@ -34,7 +34,6 @@ import subprocess
import signal import signal
import shutil import shutil
import glob import glob
import traceback
import pickle import pickle
import random import random
import tempfile import tempfile
@@ -50,7 +49,7 @@ from ipaserver.install import certs
from ipaserver.install import cainstance from ipaserver.install import cainstance
from ipaserver.install import memcacheinstance from ipaserver.install import memcacheinstance
from ipaserver.install import service from ipaserver.install import service, installutils
from ipapython import version from ipapython import version
from ipaserver.install.installutils import * from ipaserver.install.installutils import *
from ipaserver.plugins.ldap2 import ldap2 from ipaserver.plugins.ldap2 import ldap2
@@ -1110,37 +1109,29 @@ def main():
os.remove(ANSWER_CACHE) os.remove(ANSWER_CACHE)
return 0 return 0
try: if __name__ == '__main__':
success = True success = False
try: try:
rval = main() # FIXME: Common option parsing, logging setup, etc should be factored
if rval != 0: # out from all install scripts
success = False safe_options, options = parse_options()
sys.exit(rval) if options.uninstall:
except SystemExit, e: log_file_name = "/var/log/ipaserver-uninstall.log"
if e.code is not None or e.code != 0:
success = False
sys.exit(e)
except Exception, e:
success = False
if uninstalling:
message = "Unexpected error - see ipaserver-uninstall.log for details:\n %s" % unicode(e)
else: else:
message = "Unexpected error - see ipaserver-install.log for details:\n %s" % unicode(e) log_file_name = "/var/log/ipaserver-install.log"
print message
message = str(e)
for str in traceback.format_tb(sys.exc_info()[2]):
message = message + "\n" + str
root_logger.debug(message)
sys.exit(1)
finally:
if pw_name and ipautil.file_exists(pw_name):
os.remove(pw_name)
if not success and installation_cleanup: installutils.run_script(main, log_file_name=log_file_name,
# Do a cautious clean up as we don't know what failed and what is operation_name='ipa-server-install')
# the state of the environment success = True
try:
fstore.restore_file('/etc/hosts') finally:
except: if pw_name and ipautil.file_exists(pw_name):
pass os.remove(pw_name)
if not success and installation_cleanup:
# Do a cautious clean up as we don't know what failed and what is
# the state of the environment
try:
fstore.restore_file('/etc/hosts')
except:
pass

View File

@@ -305,10 +305,5 @@ def main():
cleanup_kdc(fstore) cleanup_kdc(fstore)
upgrade_ipa_profile(krbctx.default_realm) upgrade_ipa_profile(krbctx.default_realm)
try: if __name__ == '__main__':
if __name__ == "__main__": installutils.run_script(main, operation_name='ipa-upgradeconfig')
sys.exit(main())
except SystemExit, e:
sys.exit(e)
except KeyboardInterrupt, e:
sys.exit(1)

View File

@@ -21,10 +21,10 @@
import sys import sys
try: try:
import os import os
from ipaserver.install import service from ipaserver.install import service, installutils
from ipapython import services as ipaservices from ipapython import services as ipaservices
from ipaserver.install.dsinstance import config_dirname, realm_to_serverid from ipaserver.install.dsinstance import config_dirname, realm_to_serverid
from ipaserver.install.installutils import is_ipa_configured, wait_for_open_ports, wait_for_open_socket from ipaserver.install.installutils import is_ipa_configured, wait_for_open_ports, wait_for_open_socket, ScriptError
from ipapython import sysrestore from ipapython import sysrestore
from ipapython import config from ipapython import config
from ipalib import api, errors from ipalib import api, errors
@@ -44,13 +44,8 @@ error was:
SASL_EXTERNAL = ldap.sasl.sasl({}, 'EXTERNAL') SASL_EXTERNAL = ldap.sasl.sasl({}, 'EXTERNAL')
class IpactlError(StandardError): class IpactlError(ScriptError):
def __init__(self, msg = '', rval = 1): pass
self.msg = msg
self.rval = rval
def __str__(self):
return self.msg
def check_IPA_configuration(): def check_IPA_configuration():
if not is_ipa_configured(): if not is_ipa_configured():
@@ -386,17 +381,6 @@ def main():
elif args[0].lower() == "status": elif args[0].lower() == "status":
ipa_status(options) ipa_status(options)
try:
if __name__ == "__main__": if __name__ == '__main__':
sys.exit(main()) installutils.run_script(main, operation_name='ipactl')
except IpactlError, e:
if e.msg:
emit_err(e.msg)
sys.exit(e.rval)
except RuntimeError, e:
emit_err("%s" % e)
sys.exit(1)
except SystemExit, e:
sys.exit(e)
except KeyboardInterrupt, e:
sys.exit(1)

View File

@@ -30,13 +30,18 @@ import netaddr
import time import time
import tempfile import tempfile
import shutil import shutil
from ConfigParser import SafeConfigParser
import traceback
from dns import resolver, rdatatype from dns import resolver, rdatatype
from dns.exception import DNSException from dns.exception import DNSException
import ldap
from ConfigParser import SafeConfigParser
from ipapython import ipautil, sysrestore from ipapython import ipautil, sysrestore
from ipapython.ipa_log_manager import * from ipapython.ipa_log_manager import *
from ipalib.util import validate_hostname from ipalib.util import validate_hostname
from ipapython import config
from ipalib import errors
# Used to determine install status # Used to determine install status
IPA_MODULES = ['httpd', 'kadmin', 'dirsrv', 'pki-cad', 'pkids', 'install', 'krb5kdc', 'ntpd', 'named', 'ipa_memcached'] IPA_MODULES = ['httpd', 'kadmin', 'dirsrv', 'pki-cad', 'pkids', 'install', 'krb5kdc', 'ntpd', 'named', 'ipa_memcached']
@@ -56,6 +61,18 @@ class HostReverseLookupError(HostLookupError):
class HostnameLocalhost(HostLookupError): class HostnameLocalhost(HostLookupError):
pass pass
class ScriptError(StandardError):
"""An exception that records an error message and a return value
"""
def __init__(self, msg = '', rval = 1):
self.msg = msg
self.rval = rval
def __str__(self):
return self.msg
class ReplicaConfig: class ReplicaConfig:
def __init__(self): def __init__(self):
self.realm_name = "" self.realm_name = ""
@@ -655,3 +672,114 @@ def is_ipa_configured():
root_logger.debug('filestore is tracking no files') root_logger.debug('filestore is tracking no files')
return installed return installed
def run_script(main_function, operation_name, log_file_name=None,
fail_message=None):
"""Run the given function as a command-line utility
This function:
- Runs the given function
- Formats any errors
- Exits with the appropriate code
:param main_function: Function to call
:param log_file_name: Name of the log file (displayed on unexpected errors)
:param operation_name: Name of the script
:param fail_message: Optional message displayed on failure
"""
root_logger.info('Starting script: %s', operation_name)
try:
try:
return_value = main_function()
except BaseException, e:
if isinstance(e, SystemExit) and (e.code is None or e.code == 0):
# Not an error after all
root_logger.info('The %s command was successful',
operation_name)
else:
# Log at the INFO level, which is not output to the console
# (unless in debug/verbose mode), but is written to a logfile
# if one is open.
tb = sys.exc_info()[2]
root_logger.info('\n'.join(traceback.format_tb(tb)))
root_logger.info('The %s command failed, exception: %s: %s',
operation_name, type(e).__name__, e)
exception = e
if fail_message and not isinstance(e, SystemExit):
print fail_message
raise
else:
if return_value:
root_logger.info('The %s command failed, return value %s',
operation_name, return_value)
else:
root_logger.info('The %s command was successful',
operation_name)
sys.exit(return_value)
except BaseException, error:
handle_error(error, log_file_name)
def handle_error(error, log_file_name=None):
"""Handle specific errors"""
if isinstance(error, SystemExit):
sys.exit(error)
if isinstance(error, RuntimeError):
sys.exit(error)
if isinstance(error, KeyboardInterrupt):
print >> sys.stderr, "Cancelled."
sys.exit(1)
if isinstance(error, ScriptError):
if error.msg:
print >> sys.stderr, error.msg
sys.exit(error.rval)
if isinstance(error, socket.error):
print >> sys.stderr, error
sys.exit(1)
if isinstance(error, ldap.INVALID_CREDENTIALS):
print >> sys.stderr, "Invalid password"
sys.exit(1)
if isinstance(error, ldap.INSUFFICIENT_ACCESS):
print >> sys.stderr, "Insufficient access"
sys.exit(1)
if isinstance(error, ldap.LOCAL_ERROR):
print >> sys.stderr, error.args[0]['info']
sys.exit(1)
if isinstance(error, ldap.SERVER_DOWN):
print >> sys.stderr, error.args[0]['desc']
sys.exit(1)
if isinstance(error, ldap.LDAPError):
print >> sys.stderr, 'LDAP error: %s' % type(error).__name__
print >> sys.stderr, error.args[0]['info']
sys.exit(1)
if isinstance(error, config.IPAConfigError):
print >> sys.stderr, "An IPA server to update cannot be found. Has one been configured yet?"
print >> sys.stderr, "The error was: %s" % error
sys.exit(1)
if isinstance(error, errors.LDAPError):
print >> sys.stderr, "An error occurred while performing operations: %s" % error
sys.exit(1)
if isinstance(error, HostnameLocalhost):
print >> sys.stderr, "The hostname resolves to the localhost address (127.0.0.1/::1)"
print >> sys.stderr, "Please change your /etc/hosts file so that the hostname"
print >> sys.stderr, "resolves to the ip address of your network interface."
print >> sys.stderr, ""
print >> sys.stderr, "Please fix your /etc/hosts file and restart the setup program"
sys.exit(1)
if log_file_name:
print >> sys.stderr, "Unexpected error - see %s for details:" % log_file_name
else:
print >> sys.stderr, "Unexpected error"
print >> sys.stderr, '%s: %s' % (type(error).__name__, error)
sys.exit(1)

View File

@@ -47,9 +47,12 @@ import inspect
from ipaserver.install.plugins import PRE_UPDATE, POST_UPDATE from ipaserver.install.plugins import PRE_UPDATE, POST_UPDATE
from ipaserver.install.plugins import FIRST, MIDDLE, LAST from ipaserver.install.plugins import FIRST, MIDDLE, LAST
class BadSyntax(Exception): class BadSyntax(installutils.ScriptError):
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
self.msg = "There is a syntax error in this update file: \n %s" % value
self.rval = 1
def __str__(self): def __str__(self):
return repr(self.value) return repr(self.value)