summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Lint
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-07-11 13:00:12 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-07-11 13:00:12 -0400
commitba2db49bf6f8a51ba8e9102ee97a3168fc60f827 (patch)
treed297bec9afe2b7fd27c867d7a6cba6f2220f3058 /src/lib/Bcfg2/Server/Lint
parent4dc14648cce88f7d7d9a945929912a6c806dbf4f (diff)
downloadbcfg2-ba2db49bf6f8a51ba8e9102ee97a3168fc60f827.tar.gz
bcfg2-ba2db49bf6f8a51ba8e9102ee97a3168fc60f827.tar.bz2
bcfg2-ba2db49bf6f8a51ba8e9102ee97a3168fc60f827.zip
improved properties schema error handling in bcfg2-lint Validate
Diffstat (limited to 'src/lib/Bcfg2/Server/Lint')
-rw-r--r--src/lib/Bcfg2/Server/Lint/Validate.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/lib/Bcfg2/Server/Lint/Validate.py b/src/lib/Bcfg2/Server/Lint/Validate.py
index 05fedc313..aa5cfe62c 100644
--- a/src/lib/Bcfg2/Server/Lint/Validate.py
+++ b/src/lib/Bcfg2/Server/Lint/Validate.py
@@ -46,20 +46,10 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin):
if filelist:
# avoid loading schemas for empty file lists
schemafile = schemaname % schemadir
- try:
- schema = lxml.etree.XMLSchema(lxml.etree.parse(schemafile))
- except IOError:
- e = sys.exc_info()[1]
- self.LintError("input-output-error", str(e))
- continue
- except lxml.etree.XMLSchemaParseError:
- e = sys.exc_info()[1]
- self.LintError("schema-failed-to-parse",
- "Failed to process schema %s: %s" %
- (schemafile, e))
- continue
- for filename in filelist:
- self.validate(filename, schemafile, schema=schema)
+ schema = self._load_schema(schemafile)
+ if schema:
+ for filename in filelist:
+ self.validate(filename, schemafile, schema=schema)
self.check_properties()
@@ -88,11 +78,8 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin):
return True on success, False on failure """
if schema is None:
# if no schema object was provided, instantiate one
- try:
- schema = lxml.etree.XMLSchema(lxml.etree.parse(schemafile))
- except:
- self.LintError("schema-failed-to-parse",
- "Failed to process schema %s" % schemafile)
+ schema = self._load_schema(schemafile)
+ if not schema:
return False
try:
@@ -208,3 +195,15 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin):
return rv
+ def _load_schema(self, filename):
+ try:
+ return lxml.etree.XMLSchema(lxml.etree.parse(filename))
+ except IOError:
+ e = sys.exc_info()[1]
+ self.LintError("input-output-error", str(e))
+ except lxml.etree.XMLSchemaParseError:
+ e = sys.exc_info()[1]
+ self.LintError("schema-failed-to-parse",
+ "Failed to process schema %s: %s" %
+ (filename, e))
+ return None