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
c07ec1e3
Commit
c07ec1e3
authored
6 months ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
add endpoint for all routers that are both in gap and in ims
parent
fb4a088f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/classifier.py
+15
-7
15 additions, 7 deletions
inventory_provider/routes/classifier.py
test/test_classifier_routes.py
+17
-0
17 additions, 0 deletions
test/test_classifier_routes.py
with
32 additions
and
7 deletions
inventory_provider/routes/classifier.py
+
15
−
7
View file @
c07ec1e3
...
@@ -61,7 +61,7 @@ import re
...
@@ -61,7 +61,7 @@ import re
from
functools
import
lru_cache
from
functools
import
lru_cache
from
typing
import
Iterable
,
List
,
Optional
from
typing
import
Iterable
,
List
,
Optional
from
flask
import
Blueprint
,
Response
,
jsonify
,
request
from
flask
import
Blueprint
,
Response
,
request
from
redis
import
Redis
from
redis
import
Redis
from
inventory_provider.routes
import
common
from
inventory_provider.routes
import
common
...
@@ -1158,14 +1158,22 @@ def _get_coriant_info(
...
@@ -1158,14 +1158,22 @@ def _get_coriant_info(
@common.require_accepts_json
@common.require_accepts_json
def
get_all_routers
()
->
Response
:
def
get_all_routers
()
->
Response
:
redis
=
common
.
get_current_redis
()
redis
=
common
.
get_current_redis
()
result
=
cache_result
(
"
classifier-cache:router:list
"
,
func
=
functools
.
partial
(
_get_router_list
,
redis
),
redis
=
redis
,
)
return
Response
(
result
,
mimetype
=
"
application/json
"
)
def
_get_router_list
(
redis
):
all_routers_raw
=
redis
.
get
(
"
netdash
"
)
all_routers_raw
=
redis
.
get
(
"
netdash
"
)
all_routers
=
json
.
loads
(
all_routers_raw
)
if
all_routers_raw
else
{}
all_routers
=
json
.
loads
(
all_routers_raw
)
if
all_routers_raw
else
{}
return
jsonify
(
return
[
[
{
"
hostname
"
:
hostname
,
"
vendor
"
:
vendor
}
{
"
hostname
"
:
hostname
,
"
vendor
"
:
vendor
}
for
hostname
,
vendor
in
all_routers
.
items
()
for
hostname
,
vendor
in
all_routers
.
items
()
if
get_ims_equipment_name_or_none
(
hostname
)
]
]
)
@routes.route
(
"
/router-info/<equipment_name>
"
,
methods
=
[
"
GET
"
])
@routes.route
(
"
/router-info/<equipment_name>
"
,
methods
=
[
"
GET
"
])
...
...
This diff is collapsed.
Click to expand it.
test/test_classifier_routes.py
+
17
−
0
View file @
c07ec1e3
...
@@ -236,6 +236,22 @@ def test_router_info_all_routers(client):
...
@@ -236,6 +236,22 @@ def test_router_info_all_routers(client):
jsonschema
.
validate
(
result
,
ROUTER_INFO_ALL_ROUTERS_RESPONSE_SCHEMA
)
jsonschema
.
validate
(
result
,
ROUTER_INFO_ALL_ROUTERS_RESPONSE_SCHEMA
)
assert
len
(
result
)
>
0
assert
len
(
result
)
>
0
def
test_router_info_all_routers
(
client
,
mocked_redis
):
rv
=
client
.
get
(
"
/classifier/router-info
"
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
assert
rv
.
is_json
result
=
rv
.
json
jsonschema
.
validate
(
result
,
ROUTER_INFO_ALL_ROUTERS_RESPONSE_SCHEMA
)
assert
len
(
result
)
>
0
def
test_all_routers_skips_routers_not_in_ims
(
client
,
mocked_redis
):
all_routers
=
json
.
loads
(
mocked_redis
.
get
(
'
netdash
'
))
all_routers
[
'
invalid.router
'
]
=
'
juniper
'
mocked_redis
.
set
(
'
netdash
'
,
json
.
dumps
(
all_routers
))
result
=
client
.
get
(
"
/classifier/router-info
"
,
headers
=
DEFAULT_REQUEST_HEADERS
).
json
assert
not
any
(
r
[
'
hostname
'
]
==
'
invalid.router
'
for
r
in
result
)
@pytest.mark.parametrize
(
"
router
"
,
[
"
mx1.ams.nl
"
,
"
mx1.ams.nl.geant.net
"
])
@pytest.mark.parametrize
(
"
router
"
,
[
"
mx1.ams.nl
"
,
"
mx1.ams.nl.geant.net
"
])
def
test_router_info
(
client
,
router
):
def
test_router_info
(
client
,
router
):
...
@@ -250,6 +266,7 @@ def test_router_info(client, router):
...
@@ -250,6 +266,7 @@ def test_router_info(client, router):
assert
len
(
result
[
'
contacts
'
])
>
0
assert
len
(
result
[
'
contacts
'
])
>
0
def
test_router_info_caches_result
(
client
,
mocked_redis
):
def
test_router_info_caches_result
(
client
,
mocked_redis
):
router
=
"
mx1.ams.nl
"
router
=
"
mx1.ams.nl
"
cache_key
=
f
"
classifier-cache:router:
{
router
.
upper
()
}
"
cache_key
=
f
"
classifier-cache:router:
{
router
.
upper
()
}
"
...
...
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