From edca0b698637c3fd0a70af7e4752a46afca938d3 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Mon, 23 Jan 2006 22:35:40 +0000 Subject: last step of repo switches git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1716 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2-repo-validate | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/sbin/bcfg2-repo-validate (limited to 'src/sbin/bcfg2-repo-validate') diff --git a/src/sbin/bcfg2-repo-validate b/src/sbin/bcfg2-repo-validate new file mode 100644 index 000000000..a87b31cc6 --- /dev/null +++ b/src/sbin/bcfg2-repo-validate @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +'''bcfg2-repo-validate checks all xml files in Bcfg2 repos against their respective XML schemas''' +__revision__ = '$Revision$' + +from glob import glob +from lxml.etree import parse, XMLSchema +from os import system +from sys import argv +from ConfigParser import ConfigParser, NoSectionError, NoOptionError + +if __name__ == '__main__': + cf = ConfigParser() + schemadir = '/usr/share/bcfg2/schemas' + if len(argv) > 1: + repo = argv[1] + else: + cf.read(['/etc/bcfg2.conf']) + try: + repo = cf.get('server', 'repository') + except (NoSectionError, NoOptionError): + print "Repository location not specified in config file or on command line" + print "Usage: bcfg2-repo-validate " + raise SystemExit, 1 + + # add more validation as more schemas get written + filesets = {'metadata':("%s/Metadata/groups.xml", "%s/metadata.xsd"), + 'clients':("%s/Metadata/clients.xml", "%s/clients.xsd"), + 'bundle':("%s/Bundler/*.xml", "%s/bundle.xsd"), + 'pkglist':("%s/Pkgmgr/*.xml", "%s/pkglist.xsd"), + 'base':("%s/Base/*.xml", "%s/base.xsd"), + 'imageinfo':("%s/etc/reports.xml", "%s/report-configuration.xsd"), + 'services':("%s/Svcmgr/*.xml", "%s/services.xsd")} + + for k, (spec, schemaname) in filesets.iteritems(): + try: + schema = XMLSchema(parse(open(schemaname%(schemadir)))) + except: + print "Failed to process schema %s" % (schemaname%(schemadir)) + continue + for filename in glob(spec%(repo)): + try: + datafile = parse(open(filename)) + except SyntaxError: + print "%s ***FAILS*** to parse \t\t<----" % (filename) + system("xmllint %s" % filename) + continue + except IOError: + print "Failed to open file %s \t\t<---" % (filename) + continue + if schema.validate(datafile): + if '-v' in argv: + print "%s checks out" % (filename) + else: + print "%s ***FAILS*** to verify \t\t<----" % (filename) + system("xmllint --schema %s %s" % (schemaname % schemadir, filename)) -- cgit v1.2.3-1-g7c22