Validator cleanups & more test cases for updated schema
Change-Id: If4b58dfb6aa1f54235bc9096d80a0513033ff39c
This commit is contained in:
parent
a2befb278b
commit
f31a1d2a94
4
Makefile
4
Makefile
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
validation:
|
validation:
|
||||||
@echo ===========================================================================
|
@echo ===========================================================================
|
||||||
python validate.py example-vmlist-1.yaml
|
python validate.py examples/*
|
||||||
@echo ===========================================================================
|
|
||||||
python validate.py example-vmlist-bad.yaml
|
|
||||||
@echo ===========================================================================
|
@echo ===========================================================================
|
||||||
|
|
||||||
all: test
|
all: test
|
||||||
|
|
|
@ -9,6 +9,6 @@ vmlist:
|
||||||
metadata: "{ "
|
metadata: "{ "
|
||||||
userdata: false
|
userdata: false
|
||||||
# bogus mess
|
# bogus mess
|
||||||
- noname: "idonthaveaname"
|
somevm:
|
||||||
enabled: "can't be bothered"
|
enabled: "can't be bothered"
|
||||||
extra: "peanuts"
|
extra: "peanuts"
|
|
@ -0,0 +1 @@
|
||||||
|
# nada
|
|
@ -0,0 +1,3 @@
|
||||||
|
vmlist:
|
||||||
|
- wrong
|
||||||
|
|
35
validate.py
35
validate.py
|
@ -41,20 +41,27 @@ def validate_leaves(prefix, vm, l):
|
||||||
return valid_leaves
|
return valid_leaves
|
||||||
|
|
||||||
def validate_file(filename):
|
def validate_file(filename):
|
||||||
yamlgen = yaml.load_all(open(filename))
|
try:
|
||||||
top = [ x for x in yamlgen ][0]
|
yamlgen = list(yaml.safe_load_all(open(filename)))
|
||||||
|
except yaml.parser.ParserError:
|
||||||
|
print "[E] Invalid yaml"
|
||||||
|
return
|
||||||
|
|
||||||
|
if not yamlgen or not yamlgen[0]:
|
||||||
|
print "[E] File contains no valid yaml"
|
||||||
|
return
|
||||||
|
top = list(yamlgen)[0]
|
||||||
|
|
||||||
vmlist = top["vmlist"]
|
vmlist = top["vmlist"]
|
||||||
index = 0
|
if not vmlist or not isinstance(vmlist, dict):
|
||||||
for vm in vmlist:
|
print "[E] No vmlist dict declared"
|
||||||
index += 1
|
return
|
||||||
name = ""
|
|
||||||
if "name" in vm:
|
|
||||||
name = vm["name"]
|
|
||||||
|
|
||||||
print "Checking:", name, ("(index %d)" % index)
|
for name in vmlist:
|
||||||
|
vm = vmlist[name]
|
||||||
|
print "VM:", name
|
||||||
|
|
||||||
vl = validate_leaves("", vm, [ ("name",str()), ("enabled",bool()), ("vmconfig",dict()), ("netconfig",dict()), ("cloudconfig",dict()) ] )
|
vl = validate_leaves("", vm, [ ("enabled",bool()), ("vmconfig",dict()), ("netconfig",dict()), ("cloudconfig",dict()) ] )
|
||||||
if "vmconfig" in vl:
|
if "vmconfig" in vl:
|
||||||
# validate vmconfig
|
# validate vmconfig
|
||||||
vmconfig = vm["vmconfig"]
|
vmconfig = vm["vmconfig"]
|
||||||
|
@ -76,7 +83,7 @@ def validate_file(filename):
|
||||||
if "rootfs" in vl2:
|
if "rootfs" in vl2:
|
||||||
# validate vmconfig.rootfs
|
# validate vmconfig.rootfs
|
||||||
rootfs = vmconfig["rootfs"]
|
rootfs = vmconfig["rootfs"]
|
||||||
vl3 = validate_leaves("vmconfig.rootfs.", rootfs, [ ("sourceurl",str()), ("type_notimpl",str()), ("localtarget",str()), ("pvc_size",str()), ("pvc_class",str(), True) ])
|
vl3 = validate_leaves("vmconfig.rootfs.", rootfs, [ ("sourceurl",str()), ("localtarget",str()), ("pvc_size",str()), ("pvc_class",str(), True) ])
|
||||||
|
|
||||||
if "sourceurl" in vl3:
|
if "sourceurl" in vl3:
|
||||||
if not rootfs["sourceurl"].startswith("http"):
|
if not rootfs["sourceurl"].startswith("http"):
|
||||||
|
@ -91,7 +98,7 @@ def validate_file(filename):
|
||||||
if "cloudconfig" in vl:
|
if "cloudconfig" in vl:
|
||||||
# validate cloudconfig
|
# validate cloudconfig
|
||||||
cloudconfig = vm["cloudconfig"]
|
cloudconfig = vm["cloudconfig"]
|
||||||
vl2 = validate_leaves("cloudconfig.", cloudconfig, [ ("instance_id",str()), ("metadata",str()), ("userdata",str()) ])
|
vl2 = validate_leaves("cloudconfig.", cloudconfig, [ ("metadata",str()), ("userdata",str()) ])
|
||||||
|
|
||||||
# check things look sane
|
# check things look sane
|
||||||
for yamlobj in [ "metadata", "userdata" ]:
|
for yamlobj in [ "metadata", "userdata" ]:
|
||||||
|
@ -101,9 +108,9 @@ def validate_file(filename):
|
||||||
except:
|
except:
|
||||||
print "[E] Bad yaml for vmconfig.cloudconfig.%s" % yamlobj
|
print "[E] Bad yaml for vmconfig.cloudconfig.%s" % yamlobj
|
||||||
|
|
||||||
print "Done"
|
|
||||||
print
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for fn in sys.argv[1:]:
|
for fn in sys.argv[1:]:
|
||||||
|
print "Filename:", fn
|
||||||
validate_file(fn)
|
validate_file(fn)
|
||||||
|
print
|
||||||
|
|
Loading…
Reference in New Issue