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

generalize router name parsing

parent bbe3c44e
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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
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