From 80e760a7bb09bf26dae99bcf445f6e43d5e2349d Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Mon, 4 Feb 2019 21:48:18 +0100
Subject: [PATCH] generalize router name parsing

---
 inventory_provider/juniper.py | 2 +-
 test/test_junosspace_io.py    | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py
index 55f3e9fd..a16d7150 100644
--- a/inventory_provider/juniper.py
+++ b/inventory_provider/juniper.py
@@ -301,7 +301,7 @@ def load_routers_from_junosspace(config):
     for d in devices.xpath('//devices/device'):
         name = d.xpath('./name/text()')[0]
         # TODO: ask ops if this name->hostname operation is valid
-        m = re.match(r'^(.*)\.re\d+$', name)
+        m = re.match(r'^(.*?)(\.re\d+)?$', name)
         if m:
             hostname = m.group(1) + '.geant.net'
         else:
diff --git a/test/test_junosspace_io.py b/test/test_junosspace_io.py
index 7f7ad8ee..82c774ba 100644
--- a/test/test_junosspace_io.py
+++ b/test/test_junosspace_io.py
@@ -23,4 +23,10 @@ def test_junosspace_devices_parsing(data_config):
             body=f.read())
 
     routers = juniper.load_routers_from_junosspace(data_config['junosspace'])
-    print(list(routers))
+
+    hostnames = [r['hostname'] for r in routers]
+
+    # test for .re\d+ greediness
+    assert 'mx1.ams.nl.geant.net' in hostnames
+    # test that 'qfx1.fra.de' is parsed
+    assert 'qfx1.fra.de.geant.net' in hostnames
\ No newline at end of file
-- 
GitLab