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

pull out netconf validation for testability

parent 0f97054f
No related branches found
No related tags found
No related merge requests found
...@@ -101,19 +101,8 @@ def _rpc(hostname, ssh): ...@@ -101,19 +101,8 @@ def _rpc(hostname, ssh):
return dev.rpc return dev.rpc
def load_config(hostname, ssh_params): def validate_netconf_config(config_doc):
"""
loads netconf data from the router, validates and
returns as an lxml etree doc
:param hostname: router hostname
:param ssh_params: 'ssh' config element(cf. config.py:CONFIG_SCHEMA)
:return:
"""
juniper_logger = logging.getLogger(JUNIPER_LOGGER_NAME) juniper_logger = logging.getLogger(JUNIPER_LOGGER_NAME)
juniper_logger.info("capturing netconf data for '%s'" % hostname)
def _validate(schema, doc): def _validate(schema, doc):
if schema.validate(doc): if schema.validate(doc):
return return
...@@ -124,16 +113,28 @@ def load_config(hostname, ssh_params): ...@@ -124,16 +113,28 @@ def load_config(hostname, ssh_params):
schema_doc = etree.XML(CONFIG_SCHEMA.encode('utf-8')) schema_doc = etree.XML(CONFIG_SCHEMA.encode('utf-8'))
config_schema = etree.XMLSchema(schema_doc) config_schema = etree.XMLSchema(schema_doc)
config = _rpc(hostname, ssh_params).get_config() _validate(config_schema, config_doc)
_validate(config_schema, config)
# validate interfaces/interface/unit elements ... # validate interfaces/interface/unit elements ...
schema_doc = etree.XML(UNIT_SCHEMA.encode('utf-8')) schema_doc = etree.XML(UNIT_SCHEMA.encode('utf-8'))
unit_schema = etree.XMLSchema(schema_doc) unit_schema = etree.XMLSchema(schema_doc)
for i in config.xpath('//configuration/interfaces/interface'): for i in config_doc.xpath('//configuration/interfaces/interface'):
for u in i.xpath('./unit'): for u in i.xpath('./unit'):
_validate(unit_schema, u) _validate(unit_schema, u)
def load_config(hostname, ssh_params):
"""
loads netconf data from the router, validates and
returns as an lxml etree doc
:param hostname: router hostname
:param ssh_params: 'ssh' config element(cf. config.py:CONFIG_SCHEMA)
:return:
"""
juniper_logger = logging.getLogger(JUNIPER_LOGGER_NAME)
juniper_logger.info("capturing netconf data for '%s'" % hostname)
config = _rpc(hostname, ssh_params).get_config()
validate_netconf_config(config)
return config return config
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment