]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Better error handling
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 18 Nov 2022 10:16:10 +0000 (11:16 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 18 Nov 2022 10:16:10 +0000 (11:16 +0100)
lib/pp_admintools/app/__init__.py
lib/pp_admintools/app/dns_deploy_zones.py
lib/pp_admintools/app/mail.py
lib/pp_admintools/app/pdns.py

index aebc7170c39d740e2a0f8e53a17f0611efe74a9b..351f4a19b1ef6e90de900b9d770ca09614ca4e98 100644 (file)
@@ -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
index 216a178f2f2091479c91ec58d12dfd3253755b13..7f7c1e1135016a7d8ad75b2e952a6f325fcf3f0a 100644 (file)
@@ -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:
index 8e838c39c67f08d08b09cd7b6e28cfdf9ec72a85..1b62f0aabbe10a7bfaf6bc9dc878fae784a11f93 100644 (file)
@@ -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):
 
index 22f79ecdcaf8ebea39967e67570c828819672527..f588fde73dd69d9bc5311cade2b8939a81a149d4 100644 (file)
@@ -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):