summaryrefslogtreecommitdiffstats
path: root/src/sbin/ValidateBcfg2Repo
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2005-11-12 21:23:56 +0000
committerNarayan Desai <desai@mcs.anl.gov>2005-11-12 21:23:56 +0000
commit815b296a1dc2f212788732814b089ed5de4f80e9 (patch)
tree7f311f0493d0e355bb6f4d4e888e8a24f2ae2a9a /src/sbin/ValidateBcfg2Repo
parentb1c5fa97d8c8fa9593c9dfa7b3ab30fc414b7a23 (diff)
downloadbcfg2-815b296a1dc2f212788732814b089ed5de4f80e9.tar.gz
bcfg2-815b296a1dc2f212788732814b089ed5de4f80e9.tar.bz2
bcfg2-815b296a1dc2f212788732814b089ed5de4f80e9.zip
switch to using lxml schema validation
(Logical change 1.358) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1496 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin/ValidateBcfg2Repo')
-rw-r--r--src/sbin/ValidateBcfg2Repo28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/sbin/ValidateBcfg2Repo b/src/sbin/ValidateBcfg2Repo
index e77f33500..4da868690 100644
--- a/src/sbin/ValidateBcfg2Repo
+++ b/src/sbin/ValidateBcfg2Repo
@@ -1,9 +1,12 @@
#!/usr/bin/env python
+'''ValidateBcfg2Repo checks all xml files in Bcfg2 repos against their respective XML schemas'''
+__revision__ = '0.7.3'
+
from glob import glob
-from sys import argv, exit
-from validate import validate, ValidationException
-from ConfigParser import ConfigParser
+from lxml.etree import parse, XMLSchema
+from sys import argv
+from ConfigParser import ConfigParser, NoSectionError, NoOptionError
if __name__ == '__main__':
cf = ConfigParser()
@@ -11,8 +14,9 @@ if __name__ == '__main__':
cf.read(['/etc/bcfg2.conf'])
try:
repo = cf.get('server', 'repository')
- except:
+ except (NoSectionError, NoOptionError):
if len(argv) == 1:
+ print "Repository location not specified in config file or on command line"
print "Usage: validate_repo <repo directory>"
raise SystemExit, 1
repo = argv[1]
@@ -27,11 +31,17 @@ if __name__ == '__main__':
'services':("%s/etc/services.xml", "%s/services.xsd")}
for k, (spec, schema) in filesets.iteritems():
+ schema = XMLSchema(parse(open(schema%(schemadir))))
for filename in glob(spec%(repo)):
try:
- validate(open(filename).read(), schema%(schemadir))
- print "%s checks out"%(filename)
- except ValidationException, v:
- print "file %s fails to verify:\n%s"%(filename, v)
+ datafile = parse(open(filename))
+ except SyntaxError:
+ print "%s ***FAILS*** to parse \t\t<----" % (filename)
+ continue
except IOError:
- print "failed to open file %s"%(filename)
+ print "Failed to open file %s \t\t<---" % (filename)
+ continue
+ if schema.validate(datafile):
+ print "%s checks out" % (filename)
+ else:
+ print "%s ***FAILS*** to verify \t\t<----" % (filename)