diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-14 13:05:08 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-14 13:05:08 -0400 |
commit | 3d06f311274d6b942ee89d8cdb13b2ecc99af1b0 (patch) | |
tree | bc3d6403e053f0e30f525c6555bd00dd0d0c973e /src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | |
parent | acb1dde9ba48b04d1ceb701ce849e96cef3d0070 (diff) | |
download | bcfg2-3d06f311274d6b942ee89d8cdb13b2ecc99af1b0.tar.gz bcfg2-3d06f311274d6b942ee89d8cdb13b2ecc99af1b0.tar.bz2 bcfg2-3d06f311274d6b942ee89d8cdb13b2ecc99af1b0.zip |
use Executor class for better subprocess calling on server
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py index 313e53ee9..d06b864ac 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py @@ -3,8 +3,8 @@ import os import sys import shlex +from Bcfg2.Utils import Executor from Bcfg2.Server.Plugin import PluginExecutionError -from subprocess import Popen, PIPE from Bcfg2.Server.Plugins.Cfg import CfgVerifier, CfgVerificationError @@ -18,24 +18,16 @@ class CfgExternalCommandVerifier(CfgVerifier): def __init__(self, name, specific, encoding): CfgVerifier.__init__(self, name, specific, encoding) self.cmd = [] + self.exc = Executor(timeout=30) __init__.__doc__ = CfgVerifier.__init__.__doc__ def verify_entry(self, entry, metadata, data): try: - proc = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) - out, err = proc.communicate(input=data) - rv = proc.wait() - if rv != 0: - # pylint: disable=E1103 - raise CfgVerificationError(err.strip() or out.strip() or - "Non-zero return value %s" % rv) - # pylint: enable=E1103 - except CfgVerificationError: - raise - except: - err = sys.exc_info()[1] - raise CfgVerificationError("Error running external command " - "verifier: %s" % err) + result = self.exc.run(self.cmd, inputdata=data) + if not result.success: + raise CfgVerificationError(result.error) + except OSError: + raise CfgVerificationError(sys.exc_info()[1]) verify_entry.__doc__ = CfgVerifier.verify_entry.__doc__ def handle_event(self, event): |