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

added some interface element schema checks

parent 11accbec
No related branches found
No related tags found
No related merge requests found
import logging
import os import os
from jnpr.junos import Device from jnpr.junos import Device
...@@ -35,16 +36,28 @@ def _load_netconf(hostname, ssh_params): ...@@ -35,16 +36,28 @@ def _load_netconf(hostname, ssh_params):
# #
SCHEMA = """<?xml version="1.0" encoding="UTF-8" ?> SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="generic-sequence"> <xs:complexType name="generic-sequence">
<xs:sequence> <xs:sequence>
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/> <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence> </xs:sequence>
<xs:anyAttribute processContents="skip" /> <xs:anyAttribute processContents="skip" />
</xs:complexType> </xs:complexType>
<!-- NOTE: 'unit' content isn't validated -->
<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:choice>
</xs:sequence>
<xs:attribute name="inactive" type="xs:string" />
</xs:complexType>
<xs:element name="configuration"> <xs:element name="configuration">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
...@@ -61,7 +74,7 @@ SCHEMA = """<?xml version="1.0" encoding="UTF-8" ?> ...@@ -61,7 +74,7 @@ SCHEMA = """<?xml version="1.0" encoding="UTF-8" ?>
<xs:sequence> <xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded"> <xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="apply-groups" minOccurs="0" type="xs:string" /> <xs:element name="apply-groups" minOccurs="0" type="xs:string" />
<xs:element name="interface" minOccurs="1" type="generic-sequence" /> <xs:element name="interface" minOccurs="1" maxOccurs="unbounded" type="juniper-interface" />
</xs:choice> </xs:choice>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
...@@ -86,6 +99,8 @@ SCHEMA = """<?xml version="1.0" encoding="UTF-8" ?> ...@@ -86,6 +99,8 @@ SCHEMA = """<?xml version="1.0" encoding="UTF-8" ?>
""" """
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
TEST_DATA_DIR = os.path.dirname(__file__) TEST_DATA_DIR = os.path.dirname(__file__)
CONFIG_FILENAME = "config.json" CONFIG_FILENAME = "config.json"
SCHEMA_FILENAME = os.path.join(TEST_DATA_DIR, "juniper-netconf.xsd") SCHEMA_FILENAME = os.path.join(TEST_DATA_DIR, "juniper-netconf.xsd")
...@@ -109,5 +124,12 @@ if __name__ == "__main__": ...@@ -109,5 +124,12 @@ if __name__ == "__main__":
schema = etree.XMLSchema(schema_doc) schema = etree.XMLSchema(schema_doc)
parser = etree.XMLParser(schema=schema) parser = etree.XMLParser(schema=schema)
print(filename) logging.debug("FILENAME: %s" % filename)
etree.parse(filename, parser) try:
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)
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