From e386c37ff7436f78c1a9dd33e0c90e2b3254c99d Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 13 Apr 2011 11:40:50 -0400 Subject: * Made Metadata files validate whether or not XIncludes had been processed * bcfg2-repo-validate does not chase XIncludes if --stdin has been specified, but just validates the Metadata files you provide on stdin --- schemas/metadata.xsd | 6 +++++- schemas/xinclude.xsd | 41 ++++++++++++++++++++++++++++++++++++ src/sbin/bcfg2-repo-validate | 49 ++++++++++++++++++++++---------------------- 3 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 schemas/xinclude.xsd diff --git a/schemas/metadata.xsd b/schemas/metadata.xsd index 7d07c4971..58f9e8029 100644 --- a/schemas/metadata.xsd +++ b/schemas/metadata.xsd @@ -1,4 +1,5 @@ - + @@ -10,6 +11,8 @@ + @@ -37,6 +40,7 @@ + diff --git a/schemas/xinclude.xsd b/schemas/xinclude.xsd new file mode 100644 index 000000000..de58df4e0 --- /dev/null +++ b/schemas/xinclude.xsd @@ -0,0 +1,41 @@ + + + + The official XInclude XML Schema document is not normative or + deterministic. This schema implements only the features of + XInclude that are used in Bcfg2 in a manner that is deterministic + (i.e., passes XML validation). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/sbin/bcfg2-repo-validate b/src/sbin/bcfg2-repo-validate index 271f498cd..d4eb0ffd2 100755 --- a/src/sbin/bcfg2-repo-validate +++ b/src/sbin/bcfg2-repo-validate @@ -30,7 +30,7 @@ if __name__ == '__main__': if setup['stdin']: file_list = map(lambda s: s.strip(), sys.stdin.readlines()) info_list = [f for f in file_list if os.path.basename(f) == 'info.xml'] - metadata_list = fnmatch.filter(file_list, "*/Metadata/groups.xml") + metadata_list = fnmatch.filter(file_list, "*/Metadata/*.xml") clients_list = fnmatch.filter(file_list, "*/Metadata/clients.xml") bundle_list = fnmatch.filter(file_list, "*/Bundler/*.xml") genshibundle_list = fnmatch.filter(file_list, "*/Bundler/*.genshi") @@ -71,24 +71,30 @@ if __name__ == '__main__': pkgcfg_list = glob.glob("%s/Packages/config.xml" % repo) gp_list = glob.glob('%s/GroupPatterns/config.xml' % repo) - # include files in metadata_list - ref_bundles = set() - xdata = lxml.etree.parse("%s/Metadata/groups.xml" % repo) - included = set([ent.get('href') for ent in \ - xdata.findall('./{http://www.w3.org/2001/XInclude}include')]) - while included: - try: - filename = included.pop() - except KeyError: - continue - metadata_list.append("%s/Metadata/%s" % (repo, filename)) - groupdata = lxml.etree.parse("%s/Metadata/%s" % (repo, filename)) - group_ents = [ent.get('href') for ent in \ - groupdata. - findall('./{http://www.w3.org/2001/XInclude}include')] - for ent in group_ents: - included.add(ent) - included.discard(filename) + # include files in metadata_list + ref_bundles = set() + xdata = lxml.etree.parse("%s/Metadata/groups.xml" % repo) + included = set([ent.get('href') for ent in + xdata.findall('./{http://www.w3.org/2001/XInclude}include')]) + while included: + try: + filename = included.pop() + except KeyError: + continue + if not setup['stdin'] or filepath in file_list: + metadata_list.append("%s/Metadata/%s" % (repo, filename)) + groupdata = lxml.etree.parse("%s/Metadata/%s" % (repo, filename)) + group_ents = [ent.get('href') for ent in \ + groupdata. + findall('./{http://www.w3.org/2001/XInclude}include')] + for ent in group_ents: + included.add(ent) + included.discard(filename) + + # get all XIncluded bundles + xdata.xinclude() + for bundle in xdata.findall("//Bundle"): + ref_bundles.add("%s/Bundler/%s" % (repo, bundle.get('name'))) # check for multiple default group definitions default_groups = [] @@ -101,11 +107,6 @@ if __name__ == '__main__': for grp in default_groups: print(" %s" % grp.get('name')) - # get all XIncluded bundles - xdata.xinclude() - for bundle in xdata.findall("//Bundle"): - ref_bundles.add("%s/Bundler/%s" % (repo, bundle.get('name'))) - # verify attributes for configuration entries # (as defined in doc/server/configurationentries) # TODO: See if it is possible to do this in the schema instead -- cgit v1.2.3-1-g7c22