summaryrefslogtreecommitdiffstats
path: root/tools/ValidateBcfg2Repo
blob: d4d980b5c0fcdec51358cb03e844a90d3cc995fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python

from glob import glob
from sys import argv, exit
from validate import validate, ValidationException

if __name__ == '__main__':
    try:
        repo = argv[1]
        if len(argv) == 3:
            schemadir = argv[2]
        else:
            schemadir = '/usr/share/bcfg2/schemas'
    except:
        print "Usage: validate_repo <repo directory> <schema directory>"
        exit(1)

    # add more validation as more schemas get written
    filesets = {'metadata':("%s/etc/metadata.xml", "%s/metadata.xsd"),
                'bundle':("%s/Bundler/*.xml", "%s/bundle.xsd"),
                'pkglist':("%s/Pkgmgr/*.xml", "%s/pkglist.xsd"),
                'base':("%s/etc/base.xml", "%s/base.xsd"),
                'imageinfo':("%s/etc/imageinfo.xml", "%s/translation.xsd"),
                'services':("%s/etc/services.xml", "%s/services.xsd")}

    for k, (spec, schema) in filesets.iteritems():
        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)
            except IOError:
                print "failed to open file %s"%(filename)