Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
8d3f081e
Commit
8d3f081e
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Plain Diff
Finished feature DBOARD3-445-fix-broken-lg-api.
parents
d97b4a22
634b9792
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/lg.py
+23
-10
23 additions, 10 deletions
inventory_provider/routes/lg.py
test/test_lg_routes.py
+25
-15
25 additions, 15 deletions
test/test_lg_routes.py
with
48 additions
and
25 deletions
inventory_provider/routes/lg.py
+
23
−
10
View file @
8d3f081e
...
...
@@ -12,8 +12,9 @@ These endpoints are intended for use by LG.
"""
import
json
import
logging
import
re
from
flask
import
Blueprint
,
jsonify
,
Response
,
request
from
flask
import
Blueprint
,
Response
,
request
from
inventory_provider.routes
import
common
from
inventory_provider.routes.common
import
_ignore_cache_or_retrieve
...
...
@@ -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:
"""
...
...
@@ -111,22 +116,30 @@ def routers(access):
return
router
[
'
type
'
]
==
'
CORE
'
def
_routers
():
i
=
0
for
k
in
redis
.
scan_iter
(
'
ims:lg:*
'
):
for
k
in
redis
.
scan_iter
(
'
ims:lg:*
'
,
count
=
1000
):
rtr
=
redis
.
get
(
k
.
decode
(
'
utf-8
'
)).
decode
(
'
utf-8
'
)
rtr
=
json
.
loads
(
rtr
)
i
+=
1
if
_visible
(
rtr
):
yield
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
}
'
result
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
redis
)
if
not
result
:
result
=
list
(
_routers
())
# cache this data for the next call
redis
.
set
(
cache_key
,
json
.
dumps
(
result
).
encode
(
'
utf-8
'
))
result
=
list
(
filter
(
_visible
,
_routers
()))
if
result
:
result
=
json
.
dumps
(
result
)
# cache this data for the next call
redis
.
set
(
cache_key
,
result
)
if
not
result
:
return
Response
(
...
...
@@ -134,4 +147,4 @@ def routers(access):
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
(
result
)
return
Response
(
result
,
mimetype
=
"
application/json
"
)
This diff is collapsed.
Click to expand it.
test/test_lg_routes.py
+
25
−
15
View file @
8d3f081e
import
json
import
re
import
jsonschema
import
pytest
from
inventory_provider.routes.lg
import
LG_ROUTERS_SCHEMA
...
...
@@ -21,23 +23,31 @@ 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
):
test_public_routers
(
client
)
test_public_routers
(
client
)
@pytest.mark.skip
(
reason
=
'
IMS INTERNAL vs CORE calcualtion is not clear
'
)
def
test_internal_routers
(
client
):
rv
=
client
.
get
(
'
/lg/routers/all
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
LG_ROUTERS_SCHEMA
)
assert
response_data
# test data is non-empty
# Temporarily removed until I check IMS - RL
# def test_internal_routers(client):
# rv = client.get(
# '/lg/routers/all',
# headers=DEFAULT_REQUEST_HEADERS)
# assert rv.status_code == 200
# assert rv.is_json
# response_data = json.loads(rv.data.decode('utf-8'))
# jsonschema.validate(response_data, LG_ROUTERS_SCHEMA)
#
# assert response_data # test data is non-empty
#
# # response should contain both public & internal routers
# assert any(r['type'] == 'INTERNAL' for r in response_data)
# assert any(r['type'] == 'CORE' for r in response_data)
# response should contain both public & internal routers
assert
any
(
r
[
'
type
'
]
==
'
INTERNAL
'
for
r
in
response_data
)
assert
any
(
r
[
'
type
'
]
==
'
CORE
'
for
r
in
response_data
)
@pytest.mark.parametrize
(
'
bad_endpoint
'
,
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment