diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-02 15:00:03 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-02 15:00:03 -0400 |
commit | adf037aa31031be164e68b1a4817a7cada936c90 (patch) | |
tree | e4913b33fbed2bb480a2090b419a7fb3fddc67a7 /src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | |
parent | 414f1c017f5a1e0f0549bcb27175983b04e3312c (diff) | |
download | bcfg2-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/CfgExternalCommandVerifier.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | 24 |
1 files changed, 16 insertions, 8 deletions
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) |