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

add .geant.net to hostnames, if necessary

parent 9c9e6edd
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ These endpoints are intended for use by LG.
"""
import json
import logging
import re
from flask import Blueprint, jsonify, Response, request
......@@ -93,6 +94,10 @@ def routers(access):
.. asjson::
inventory_provider.routes.lg.LG_ROUTERS_SCHEMA
"equipment name" will be the IMS node name, but if this
doesn't end in ".geant.org" or ".geant.net", will be appended
with "geant.net"
:param access: one of `public` or `all`
:return:
"""
......@@ -113,7 +118,16 @@ def routers(access):
def _routers():
for k in redis.scan_iter('ims:lg:*', count=1000):
rtr = redis.get(k.decode('utf-8')).decode('utf-8')
yield json.loads(rtr)
rtr = json.loads(rtr)
hostname = rtr['equipment name'].lower()
if ' ' in hostname:
logger.warning(
'skipping LG router with ws in hostname: {hostname}')
continue
if not re.match(r'.*\.geant\.(net|org)$', hostname):
hostname = f'{hostname}.geant.net'
rtr['equipment name'] = hostname
yield rtr
cache_key = f'classifier-cache:ims-lg:{access}'
......
import json
import re
import jsonschema
import pytest
from inventory_provider.routes.lg import LG_ROUTERS_SCHEMA
......@@ -21,6 +23,8 @@ def test_public_routers(client):
assert response_data # test data is non-empty
# no internal routers should be present
assert all(r['type'] == 'CORE' for r in response_data)
assert all(
re.match(r'^\S+\.geant\.(net|org)$', r['equipment name']) for r in response_data)
def test_with_cache(client):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment