From 944aaae35d918a39a9891c6bfcae012ca0dcf79b Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sun, 10 Feb 2019 19:55:38 +0100
Subject: [PATCH] relaxed junosspace xml validation

---
 inventory_provider/juniper.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py
index 741ef352..3bc593ce 100644
--- a/inventory_provider/juniper.py
+++ b/inventory_provider/juniper.py
@@ -105,6 +105,11 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
 </xs:schema>
 """  # noqa: E501
 
+
+# elements 'use-nat' and 'fingerprint' were added between
+# junosspace versions 15.x and 17.x ... hopefully new versions
+# will also add new elements at the end of the sequence so
+# that the final xs:any below will suffice to allow validation
 JUNOSSPACE_DEVICES_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
@@ -127,8 +132,7 @@ JUNOSSPACE_DEVICES_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
           <xs:element name="domain-id" minOccurs="1" maxOccurs="1" type="xs:string" />
           <xs:element name="domain-name" minOccurs="1" maxOccurs="1" type="xs:string" />
           <xs:element name="config-status" minOccurs="1" maxOccurs="1" type="xs:string" />
-          <xs:element name="use-nat" minOccurs="0" maxOccurs="1" type="xs:boolean" />
-          <xs:element name="fingerprint" minOccurs="0" maxOccurs="1" type="xs:string" />
+          <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
     </xs:sequence>
     <xs:attribute name="href" type="xs:string" />
     <xs:attribute name="uri" type="xs:string" />
@@ -148,7 +152,6 @@ JUNOSSPACE_DEVICES_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
 </xs:schema>
 """  # noqa: E501
 
-
 def _rpc(hostname, ssh):
     dev = Device(
         host=hostname,
@@ -336,7 +339,7 @@ def load_routers_from_junosspace(config):
     schema = etree.XMLSchema(schema_doc)
     if not schema.validate(devices):
         for e in schema.error_log:
-            juniper_logger.error("%d.%d: %s" % (e.line, e.column, e.message))
+            juniper_logger.error('%d.%d: %s' % (e.line, e.column, e.message))
         assert False
 
     for d in devices.xpath('//devices/device'):
@@ -346,6 +349,8 @@ def load_routers_from_junosspace(config):
         if m:
             hostname = m.group(1) + '.geant.net'
         else:
+            juniper_logger.error(
+                'unrecognized junosspace device name format :%s' % name)
             hostname = None
         yield {
             "OSVersion": d.xpath('./OSVersion/text()')[0],
-- 
GitLab