summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/Cfg
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-02 15:00:03 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-02 15:00:03 -0400
commitadf037aa31031be164e68b1a4817a7cada936c90 (patch)
treee4913b33fbed2bb480a2090b419a7fb3fddc67a7 /src/lib/Bcfg2/Server/Plugins/Cfg
parent414f1c017f5a1e0f0549bcb27175983b04e3312c (diff)
downloadbcfg2-adf037aa31031be164e68b1a4817a7cada936c90.tar.gz
bcfg2-adf037aa31031be164e68b1a4817a7cada936c90.tar.bz2
bcfg2-adf037aa31031be164e68b1a4817a7cada936c90.zip
testsuite: added unit tests for Cfg handlers
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgCatFilter.py1
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py12
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py24
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py6
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py6
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py1
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py1
7 files changed, 27 insertions, 24 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCatFilter.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCatFilter.py
index a2e86b3db..49a5a85b3 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCatFilter.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCatFilter.py
@@ -3,6 +3,7 @@ plaintext files """
from Bcfg2.Server.Plugins.Cfg import CfgFilter
+
class CfgCatFilter(CfgFilter):
""" CfgCatFilter appends lines to and remove lines from plaintext
:ref:`server-plugins-generators-Cfg` files"""
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
index f8d08b394..dc4bab9f6 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
@@ -30,18 +30,12 @@ class CfgEncryptedGenerator(CfgGenerator):
__init__.__doc__ = CfgGenerator.__init__.__doc__
def handle_event(self, event):
- if event.code2str() == 'deleted':
- return
- try:
- crypted = open(self.name).read()
- except UnicodeDecodeError:
- crypted = open(self.name, mode='rb').read()
- except:
- LOGGER.error("Failed to read %s" % self.name)
+ CfgGenerator.handle_event(self, event)
+ if self.data is None:
return
# todo: let the user specify a passphrase by name
try:
- self.data = bruteforce_decrypt(crypted, setup=SETUP,
+ self.data = bruteforce_decrypt(self.data, setup=SETUP,
algorithm=get_algorithm(SETUP))
except EVPError:
msg = "Failed to decrypt %s" % self.name
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py
index fb66ca8bf..023af7d4e 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py
@@ -1,6 +1,7 @@
""" Invoke an external command to verify file contents """
import os
+import sys
import shlex
import logging
import Bcfg2.Server.Plugin
@@ -23,23 +24,30 @@ class CfgExternalCommandVerifier(CfgVerifier):
__init__.__doc__ = CfgVerifier.__init__.__doc__
def verify_entry(self, entry, metadata, data):
- proc = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
- err = proc.communicate(input=data)[1]
- rv = proc.wait()
- if rv != 0:
- raise CfgVerificationError(err)
+ try:
+ proc = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ err = proc.communicate(input=data)[1]
+ rv = proc.wait()
+ if rv != 0:
+ raise CfgVerificationError(err)
+ except:
+ err = sys.exc_info()[1]
+ raise CfgVerificationError("Error running external command "
+ "verifier: %s" % err)
verify_entry.__doc__ = CfgVerifier.verify_entry.__doc__
def handle_event(self, event):
- if event.code2str() == 'deleted':
+ CfgVerifier.handle_event(self, event)
+ if not self.data:
return
self.cmd = []
if not os.access(self.name, os.X_OK):
- bangpath = open(self.name).readline().strip()
+ bangpath = self.data.splitlines()[0].strip()
if bangpath.startswith("#!"):
self.cmd.extend(shlex.split(bangpath[2:].strip()))
else:
- msg = "Cannot execute %s" % self.name
+ msg = "%s: Cannot execute %s" % (self.__class__.__name__,
+ self.name)
LOGGER.error(msg)
raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
self.cmd.append(self.name)
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
index 21662a984..2f59d74f2 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
@@ -142,13 +142,13 @@ class CfgGenshiGenerator(CfgGenerator):
raise
def handle_event(self, event):
- if event.code2str() == 'deleted':
- return
CfgGenerator.handle_event(self, event)
+ if self.data is None:
+ return
try:
self.template = self.loader.load(self.name, cls=NewTextTemplate,
encoding=self.encoding)
- except Exception:
+ except:
msg = "Cfg: Could not load template %s: %s" % (self.name,
sys.exc_info()[1])
LOGGER.error(msg)
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
index 2396d6eb6..e5ba0a51b 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgInfoXML.py
@@ -23,9 +23,9 @@ class CfgInfoXML(CfgInfo):
mdata = dict()
self.infoxml.pnode.Match(metadata, mdata, entry=entry)
if 'Info' not in mdata:
- LOGGER.error("Failed to set metadata for file %s" %
- entry.get('name'))
- raise Bcfg2.Server.Plugin.PluginExecutionError
+ msg = "Failed to set metadata for file %s" % entry.get('name')
+ LOGGER.error(msg)
+ raise Bcfg2.Server.Plugin.PluginExecutionError(msg)
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/CfgPlaintextGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py
index 333e2f670..92fb06ee9 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py
@@ -4,6 +4,7 @@
from Bcfg2.Server.Plugins.Cfg import CfgGenerator
+
class CfgPlaintextGenerator(CfgGenerator):
""" CfgPlaintextGenerator is a
:class:`Bcfg2.Server.Plugins.Cfg.CfgGenerator` that handles plain
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
index c4958ceef..0ab7fd98e 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
@@ -673,7 +673,6 @@ class Cfg(Bcfg2.Server.Plugin.GroupSpool,
Bcfg2.Server.Plugin.PullTarget.__init__(self)
SETUP = core.setup
- print "SETUP=%s" % SETUP
if 'validate' not in SETUP:
SETUP.add_option('validate', Bcfg2.Options.CFG_VALIDATION)
SETUP.reparse()