From e1edce98761782fe51c451be4f5e114c75f46bd5 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 8 Feb 2013 08:12:47 -0500 Subject: Cfg: better error handling from verifiers, :test --- .../Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | 12 ++++++++++-- src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py | 9 ++++----- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg') diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py index b702ac899..8e2d98db9 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py @@ -23,10 +23,18 @@ class CfgExternalCommandVerifier(CfgVerifier): def verify_entry(self, entry, metadata, data): try: proc = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) - err = proc.communicate(input=data)[1] + out, err = proc.communicate(input=data) rv = proc.wait() if rv != 0: - raise CfgVerificationError(err) + if not err: + if out: + # got nothing on stderr, try stdout + err = out + else: + err = "Non-zero return value %s" % rv + raise CfgVerificationError(err.strip()) + except CfgVerificationError: + raise except: err = sys.exc_info()[1] raise CfgVerificationError("Error running external command " diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py index fcfaa393b..ec3ba222c 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py @@ -589,11 +589,10 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet, try: self._validate_data(entry, metadata, data) except CfgVerificationError: - msg = "Data for %s for %s failed to verify: %s" % \ - (entry.get('name'), metadata.hostname, - sys.exc_info()[1]) - self.logger.error(msg) - raise PluginExecutionError(msg) + raise PluginExecutionError("Failed to verify %s for %s: %s" % + (entry.get('name'), + metadata.hostname, + sys.exc_info()[1])) if entry.get('encoding') == 'base64': data = b64encode(data) -- cgit v1.2.3-1-g7c22 From b4d6a72ae4db7a5b83415b6fcf632ed04475fb09 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 13 Feb 2013 16:30:47 -0500 Subject: fixed unit tests --- .../Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg') diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py index 8e2d98db9..313e53ee9 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgExternalCommandVerifier.py @@ -26,13 +26,10 @@ class CfgExternalCommandVerifier(CfgVerifier): out, err = proc.communicate(input=data) rv = proc.wait() if rv != 0: - if not err: - if out: - # got nothing on stderr, try stdout - err = out - else: - err = "Non-zero return value %s" % rv - raise CfgVerificationError(err.strip()) + # pylint: disable=E1103 + raise CfgVerificationError(err.strip() or out.strip() or + "Non-zero return value %s" % rv) + # pylint: enable=E1103 except CfgVerificationError: raise except: -- cgit v1.2.3-1-g7c22 From e3f871022b9cc4bb4916c23920c6621be8c33e7d Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 14 Feb 2013 11:17:32 -0500 Subject: fixed checking Genshi templates for comments (#1141) --- src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg') diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py index 73550cd9d..4fa2fb894 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py @@ -190,6 +190,7 @@ class CfgGenshiGenerator(CfgGenerator): raise def handle_event(self, event): + CfgGenerator.handle_event(self, event) try: self.template = self.loader.load(self.name, cls=NewTextTemplate, encoding=self.encoding) -- cgit v1.2.3-1-g7c22