summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-13 17:04:42 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-13 17:04:42 -0500
commit3787db7a50f70e1c8cb575546949f32c2958fe20 (patch)
treed1f35ec1e3c68cb950d84ae301e5551007fe6de5 /src/lib/Bcfg2/Server
parentee16ced43e5050455368bb794e1fdfbba8eaa9f0 (diff)
downloadbcfg2-3787db7a50f70e1c8cb575546949f32c2958fe20.tar.gz
bcfg2-3787db7a50f70e1c8cb575546949f32c2958fe20.tar.bz2
bcfg2-3787db7a50f70e1c8cb575546949f32c2958fe20.zip
Cfg: improved error messages
Diffstat (limited to 'src/lib/Bcfg2/Server')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py9
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgDiffFilter.py10
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py7
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py9
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py10
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py31
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py12
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py4
8 files changed, 27 insertions, 65 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py
index 73c70901b..8ebd8d921 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py
@@ -2,12 +2,9 @@
<http://www.cheetahtemplate.org/>`_ templating system to generate
:ref:`server-plugins-generators-cfg` files. """
-import logging
-import Bcfg2.Server.Plugin
+from Bcfg2.Server.Plugin import PluginExecutionError
from Bcfg2.Server.Plugins.Cfg import CfgGenerator
-LOGGER = logging.getLogger(__name__)
-
try:
from Cheetah.Template import Template
HAS_CHEETAH = True
@@ -33,9 +30,7 @@ class CfgCheetahGenerator(CfgGenerator):
def __init__(self, fname, spec, encoding):
CfgGenerator.__init__(self, fname, spec, encoding)
if not HAS_CHEETAH:
- msg = "Cfg: Cheetah is not available: %s" % self.name
- LOGGER.error(msg)
- raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ raise PluginExecutionError("Cheetah is not available")
__init__.__doc__ = CfgGenerator.__init__.__doc__
def get_data(self, entry, metadata):
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgDiffFilter.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgDiffFilter.py
index 00b95c970..da506a195 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgDiffFilter.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgDiffFilter.py
@@ -1,14 +1,11 @@
""" Handle .diff files, which apply diffs to plaintext files """
import os
-import logging
import tempfile
-import Bcfg2.Server.Plugin
+from Bcfg2.Server.Plugin import PluginExecutionError
from subprocess import Popen, PIPE
from Bcfg2.Server.Plugins.Cfg import CfgFilter
-LOGGER = logging.getLogger(__name__)
-
class CfgDiffFilter(CfgFilter):
""" CfgDiffFilter applies diffs to plaintext
@@ -32,8 +29,7 @@ class CfgDiffFilter(CfgFilter):
output = open(basename, 'r').read()
os.unlink(basename)
if ret != 0:
- msg = "Error applying diff %s: %s" % (self.name, stderr)
- LOGGER.error(msg)
- raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ raise PluginExecutionError("Error applying diff %s: %s" %
+ (self.name, stderr))
return output
modify_data.__doc__ = CfgFilter.modify_data.__doc__
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
index 26faf6e2c..3b4703ddb 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
@@ -1,7 +1,6 @@
""" CfgEncryptedGenerator lets you encrypt your plaintext
:ref:`server-plugins-generators-cfg` files on the server. """
-import logging
from Bcfg2.Server.Plugin import PluginExecutionError
from Bcfg2.Server.Plugins.Cfg import CfgGenerator, SETUP
try:
@@ -11,8 +10,6 @@ try:
except ImportError:
HAS_CRYPTO = False
-LOGGER = logging.getLogger(__name__)
-
class CfgEncryptedGenerator(CfgGenerator):
""" CfgEncryptedGenerator lets you encrypt your plaintext
@@ -28,9 +25,7 @@ class CfgEncryptedGenerator(CfgGenerator):
def __init__(self, fname, spec, encoding):
CfgGenerator.__init__(self, fname, spec, encoding)
if not HAS_CRYPTO:
- msg = "Cfg: M2Crypto is not available"
- LOGGER.error(msg)
- raise PluginExecutionError(msg)
+ raise PluginExecutionError("M2Crypto is not available")
__init__.__doc__ = CfgGenerator.__init__.__doc__
def handle_event(self, event):
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py
index feedbdb1b..130652aef 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py
@@ -1,7 +1,6 @@
""" Handle encrypted Genshi templates (.crypt.genshi or .genshi.crypt
files) """
-import logging
from Bcfg2.Compat import StringIO
from Bcfg2.Server.Plugin import PluginExecutionError
from Bcfg2.Server.Plugins.Cfg import SETUP
@@ -19,10 +18,6 @@ except ImportError:
# CfgGenshiGenerator will raise errors if genshi doesn't exist
TemplateLoader = object # pylint: disable=C0103
-LOGGER = logging.getLogger(__name__)
-
-LOGGER = logging.getLogger(__name__)
-
class EncryptedTemplateLoader(TemplateLoader):
""" Subclass :class:`genshi.template.TemplateLoader` to decrypt
@@ -53,6 +48,4 @@ class CfgEncryptedGenshiGenerator(CfgGenshiGenerator):
def __init__(self, fname, spec, encoding):
CfgGenshiGenerator.__init__(self, fname, spec, encoding)
if not HAS_CRYPTO:
- msg = "Cfg: M2Crypto is not available"
- LOGGER.error(msg)
- raise PluginExecutionError(msg)
+ raise PluginExecutionError("M2Crypto is not available")
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py
index 023af7d4e..b702ac899 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py
@@ -3,13 +3,10 @@
import os
import sys
import shlex
-import logging
-import Bcfg2.Server.Plugin
+from Bcfg2.Server.Plugin import PluginExecutionError
from subprocess import Popen, PIPE
from Bcfg2.Server.Plugins.Cfg import CfgVerifier, CfgVerificationError
-LOGGER = logging.getLogger(__name__)
-
class CfgExternalCommandVerifier(CfgVerifier):
""" Invoke an external script to verify
@@ -46,9 +43,6 @@ class CfgExternalCommandVerifier(CfgVerifier):
if bangpath.startswith("#!"):
self.cmd.extend(shlex.split(bangpath[2:].strip()))
else:
- msg = "%s: Cannot execute %s" % (self.__class__.__name__,
- self.name)
- LOGGER.error(msg)
- raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ raise PluginExecutionError("Cannot execute %s" % self.name)
self.cmd.append(self.name)
handle_event.__doc__ = CfgVerifier.handle_event.__doc__
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
index cfb978c42..df0c30c09 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
@@ -4,13 +4,10 @@
import re
import sys
-import logging
import traceback
-import Bcfg2.Server.Plugin
+from Bcfg2.Server.Plugin import PluginExecutionError
from Bcfg2.Server.Plugins.Cfg import CfgGenerator
-LOGGER = logging.getLogger(__name__)
-
try:
import genshi.core
from genshi.template import TemplateLoader, NewTextTemplate
@@ -67,9 +64,7 @@ class CfgGenshiGenerator(CfgGenerator):
def __init__(self, fname, spec, encoding):
CfgGenerator.__init__(self, fname, spec, encoding)
if not HAS_GENSHI:
- msg = "Cfg: Genshi is not available: %s" % fname
- LOGGER.error(msg)
- raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ raise PluginExecutionError("Genshi is not available")
self.template = None
self.loader = self.__loader_cls__(max_cache_size=0)
__init__.__doc__ = CfgGenerator.__init__.__doc__
@@ -92,15 +87,15 @@ class CfgGenshiGenerator(CfgGenerator):
stack = traceback.extract_tb(sys.exc_info()[2])
for quad in stack:
if quad[0] == self.name:
- LOGGER.error("Cfg: Error rendering %s at '%s': %s: %s" %
- (fname, quad[2], err.__class__.__name__, err))
- break
+ raise PluginExecutionError("%s: %s at '%s'" %
+ (err.__class__.__name__, err,
+ quad[2]))
raise
except:
- self._handle_genshi_exception(fname, sys.exc_info())
+ self._handle_genshi_exception(sys.exc_info())
get_data.__doc__ = CfgGenerator.get_data.__doc__
- def _handle_genshi_exception(self, fname, exc):
+ def _handle_genshi_exception(self, exc):
""" this is horrible, and I deeply apologize to whoever gets
to maintain this after I go to the Great Beer Garden in the
Sky. genshi is incredibly opaque about what's being executed,
@@ -140,9 +135,9 @@ class CfgGenshiGenerator(CfgGenerator):
# single line break)
real_lineno = lineno - contents.code.co_firstlineno
src = re.sub(r'\n\n+', '\n', contents.source).splitlines()
- LOGGER.error("Cfg: Error rendering %s at '%s': %s: %s" %
- (fname, src[real_lineno], err.__class__.__name__,
- err))
+ raise PluginExecutionError("%s: %s at '%s'" %
+ (err.__class__.__name__, err,
+ src[real_lineno]))
raise
def handle_event(self, event):
@@ -150,8 +145,6 @@ class CfgGenshiGenerator(CfgGenerator):
self.template = self.loader.load(self.name, cls=NewTextTemplate,
encoding=self.encoding)
except:
- msg = "Cfg: Could not load template %s: %s" % (self.name,
- sys.exc_info()[1])
- LOGGER.error(msg)
- raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ raise PluginExecutionError("Failed to load template: %s" %
+ sys.exc_info()[1])
handle_event.__doc__ = CfgGenerator.handle_event.__doc__
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
index e5ba0a51b..3b6fc8fa0 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
@@ -1,11 +1,8 @@
""" Handle info.xml files """
-import logging
-import Bcfg2.Server.Plugin
+from Bcfg2.Server.Plugin import PluginExecutionError, InfoXML
from Bcfg2.Server.Plugins.Cfg import CfgInfo
-LOGGER = logging.getLogger(__name__)
-
class CfgInfoXML(CfgInfo):
""" CfgInfoXML handles :file:`info.xml` files for
@@ -16,16 +13,15 @@ class CfgInfoXML(CfgInfo):
def __init__(self, path):
CfgInfo.__init__(self, path)
- self.infoxml = Bcfg2.Server.Plugin.InfoXML(path)
+ self.infoxml = InfoXML(path)
__init__.__doc__ = CfgInfo.__init__.__doc__
def bind_info_to_entry(self, entry, metadata):
mdata = dict()
self.infoxml.pnode.Match(metadata, mdata, entry=entry)
if 'Info' not in mdata:
- msg = "Failed to set metadata for file %s" % entry.get('name')
- LOGGER.error(msg)
- raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
+ raise PluginExecutionError("Failed to set metadata for file %s" %
+ entry.get('name'))
self._set_info(entry, mdata['Info'][None])
bind_info_to_entry.__doc__ = CfgInfo.bind_info_to_entry.__doc__
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
index 58f6e1e42..db6810e7c 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
@@ -542,8 +542,8 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet):
try:
return generator.get_data(entry, metadata)
except:
- msg = "Cfg: exception rendering %s with %s: %s" % \
- (entry.get("name"), generator, sys.exc_info()[1])
+ msg = "Cfg: Error rendering %s: %s" % (entry.get("name"),
+ sys.exc_info()[1])
LOGGER.error(msg)
raise Bcfg2.Server.Plugin.PluginExecutionError(msg)