diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 55f3e9fdd934b5cfe7188858eaa16d3595141e7e..a16d71508b7fed297dcb9ae66d260d0bf8e90512 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 7f7ad8eeaaa4793ce4078c9d4144cf3c4b4e9461..82c774ba0f4c7081cc5c471063dabb7a727d7dda 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