Skip to content
Snippets Groups Projects
Commit 2ec8b093 authored by Erik Reid's avatar Erik Reid
Browse files

validate interface/unit schema

parent 089bd424
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ def _load_netconf(hostname, ssh_params):
#
SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
CONFIG_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="generic-sequence">
......@@ -50,9 +50,9 @@ SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
<xs:complexType name="juniper-interface">
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="name" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="description" minOccurs="0" maxOccurs="1" type="xs:string" />
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="name" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="description" minOccurs="0" maxOccurs="1" type="xs:string" />
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
</xs:sequence>
<xs:attribute name="inactive" type="xs:string" />
......@@ -97,6 +97,31 @@ SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
</xs:schema>
"""
UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="generic-sequence">
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute processContents="skip" />
</xs:complexType>
<xs:element name="unit">
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="1" maxOccurs="1" type="xs:int" />
<xs:element name="description" minOccurs="0" maxOccurs="1" type="xs:string" />
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="inactive" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
"""
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
......@@ -120,16 +145,26 @@ if __name__ == "__main__":
"%s-netconf.xml" % r['hostname'])
# schema_doc = etree.parse(SCHEMA_FILENAME)
schema_doc = etree.XML(SCHEMA.encode('utf-8'))
schema_doc = etree.XML(CONFIG_SCHEMA.encode('utf-8'))
schema = etree.XMLSchema(schema_doc)
parser = etree.XMLParser(schema=schema)
logging.debug("FILENAME: %s" % filename)
try:
etree.parse(filename, parser)
config_doc = etree.parse(filename, parser)
except etree.XMLSyntaxError as ex:
logging.debug(ex)
for e in parser.error_log:
logging.debug("%d.%d: %s" % (
e.line, e.column, e.message))
exit(-1)
logging.debug("%d.%d: %s" % (e.line, e.column, e.message))
continue
schema_doc = etree.XML(UNIT_SCHEMA.encode('utf-8'))
schema = etree.XMLSchema(schema_doc)
parser = etree.XMLParser(schema=schema)
# for i in data.xpath('//configuration/groups/interfaces/interface'):
for i in config_doc.xpath('//configuration/interfaces/interface'):
for u in i.xpath('./unit'):
schema.assertValid(u)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment