diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-05-09 17:07:32 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-05-09 17:07:32 -0400 |
commit | 20479262fe2d860cddb3f1766e83d2a04b0b3a7f (patch) | |
tree | fd9f6e8cb335ccc2e6d63e0b2d92945b5c74adeb /src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | |
parent | 148a01651bbdf627e4848f1b455ccfe79b8b5902 (diff) | |
download | bcfg2-20479262fe2d860cddb3f1766e83d2a04b0b3a7f.tar.gz bcfg2-20479262fe2d860cddb3f1766e83d2a04b0b3a7f.tar.bz2 bcfg2-20479262fe2d860cddb3f1766e83d2a04b0b3a7f.zip |
added support for validating Cfg file contents using external commands
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py new file mode 100644 index 000000000..f0c1109ec --- /dev/null +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py @@ -0,0 +1,33 @@ +import os +import shlex +import logging +import Bcfg2.Server.Plugin +from subprocess import Popen, PIPE +from Bcfg2.Server.Plugins.Cfg import CfgVerifier, CfgVerificationError + +logger = logging.getLogger(__name__) + +class CfgExternalCommandVerifier(CfgVerifier): + __basenames__ = [':test'] + + 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) + + def handle_event(self, event): + if event.code2str() == 'deleted': + return + self.cmd = [] + if not os.access(self.name, os.X_OK): + bangpath = open(self.name).readline().strip() + if bangpath.startswith("#!"): + self.cmd.extend(shlex.split(bangpath[2:].strip())) + else: + msg = "Cannot execute %s" % self.name + logger.error(msg) + raise Bcfg2.Server.Plugin.PluginExecutionError(msg) + self.cmd.append(self.name) + |