From: Frank Brehm Date: Fri, 18 Nov 2022 10:16:10 +0000 (+0100) Subject: Better error handling X-Git-Tag: 0.7.2^2^2~3 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=a0bdcc5bafb012950bce90e09eeba642a4068126;p=pixelpark%2Fpp-admin-tools.git Better error handling --- diff --git a/lib/pp_admintools/app/__init__.py b/lib/pp_admintools/app/__init__.py index aebc717..351f4a1 100644 --- a/lib/pp_admintools/app/__init__.py +++ b/lib/pp_admintools/app/__init__.py @@ -28,7 +28,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.6.3' +__version__ = '0.6.4' # ============================================================================= @@ -110,5 +110,10 @@ class BaseDPXApplication(FbConfigApplication): super(BaseDPXApplication, self).post_init() + if self.logfile: + LOG.debug(_("Using logfile {!r}.").format(str(self.logfile))) + else: + LOG.debug(_("Don't using a logfile.")) + # vim: ts=4 et list diff --git a/lib/pp_admintools/app/dns_deploy_zones.py b/lib/pp_admintools/app/dns_deploy_zones.py index 216a178..7f7c1e1 100644 --- a/lib/pp_admintools/app/dns_deploy_zones.py +++ b/lib/pp_admintools/app/dns_deploy_zones.py @@ -45,7 +45,7 @@ from ..config.dns_deploy_zones import DnsDeployZonesConfig from ..xlate import XLATOR -__version__ = '0.8.6' +__version__ = '0.8.7' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -346,7 +346,12 @@ class PpDeployZonesApp(PpPDNSApplication): LOG.error(msg) self.exit(1) - super(PpDeployZonesApp, self).pre_run() + LOG.info(_("Starting: {}").format(self.current_timestamp())) + + try: + super(PpDeployZonesApp, self).pre_run() + except PpPDNSAppError as e: + self.exit(5, str(e)) if self.cfg.pdns_instance == 'global': LOG.error(_( @@ -357,8 +362,6 @@ class PpDeployZonesApp(PpPDNSApplication): # ------------------------------------------------------------------------- def _run(self): - LOG.info(_("Starting: {}").format(self.current_timestamp())) - self.get_named_keys() try: diff --git a/lib/pp_admintools/app/mail.py b/lib/pp_admintools/app/mail.py index 8e838c3..1b62f0a 100644 --- a/lib/pp_admintools/app/mail.py +++ b/lib/pp_admintools/app/mail.py @@ -37,7 +37,7 @@ from ..config.mail import MailConfiguration from . import DPXAppError, BaseDPXApplication -__version__ = '0.3.2' +__version__ = '0.3.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -271,6 +271,8 @@ class BaseMailApplication(BaseDPXApplication): if self.verbose > 2: LOG.debug(_("Got command line arguments:") + '\n' + pp(self.args)) + super(BaseMailApplication, self).perform_arg_parser() + # ------------------------------------------------------------------------- def send_mail(self, subject, body): diff --git a/lib/pp_admintools/app/pdns.py b/lib/pp_admintools/app/pdns.py index 22f79ec..f588fde 100644 --- a/lib/pp_admintools/app/pdns.py +++ b/lib/pp_admintools/app/pdns.py @@ -20,6 +20,8 @@ import socket # Third party modules import psutil +from requests.exceptions import ConnectionError, ReadTimeout, ConnectTimeout + # Own modules from fb_tools import MAX_TIMEOUT from fb_tools.xlate import format_list @@ -41,7 +43,7 @@ from ..config.pdns import PdnsConfiguration from ..xlate import XLATOR -__version__ = '0.9.8' +__version__ = '0.9.9' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -288,12 +290,6 @@ class PpPDNSApplication(BaseMailApplication): super(PpPDNSApplication, self).init_arg_parser() # ------------------------------------------------------------------------- - def perform_arg_parser(self): - """ - Public available method to execute some actions after parsing - the command line parameters. - """ - # ------------------------------------------------------------------------- def init_logging(self): """Initialize the logger object. @@ -433,12 +429,19 @@ class PpPDNSApplication(BaseMailApplication): # ------------------------------------------------------------------------- def get_api_server_version(self): - if not self.pdns: - raise PpPDNSAppError(_("The PDNS server object does not exists.")) - if not self.pdns.initialized: - raise PpPDNSAppError(_("The PDNS server object is not initialized.")) + try: + if not self.pdns: + raise PpPDNSAppError(_("The PDNS server object does not exists.")) + if not self.pdns.initialized: + raise PpPDNSAppError(_("The PDNS server object is not initialized.")) - return self.pdns.get_api_server_version() + return self.pdns.get_api_server_version() + + except (ConnectionError, ReadTimeout, ConnectTimeout) as e: + msg = _("Got a {} during evaluating the PDNS server version from API:").format( + e.__class__.__name__) + msg += ' ' + str(e) + raise PpPDNSAppError(msg) # ------------------------------------------------------------------------- def _build_url(self, path):