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
6a9a582e
Commit
6a9a582e
authored
3 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
added additional impact route implementation. RE DBOARD3-571
parent
9ddcc3ce
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/mic.py
+45
-27
45 additions, 27 deletions
inventory_provider/routes/mic.py
test/test_mic_routes.py
+7
-4
7 additions, 4 deletions
test/test_mic_routes.py
with
52 additions
and
31 deletions
inventory_provider/routes/mic.py
+
45
−
27
View file @
6a9a582e
...
@@ -135,43 +135,61 @@ def get_interfaces(node):
...
@@ -135,43 +135,61 @@ def get_interfaces(node):
return
Response
(
result
,
mimetype
=
'
application/json
'
)
return
Response
(
result
,
mimetype
=
'
application/json
'
)
@routes.route
(
'
/impact/<site>
'
)
@routes.route
(
'
/impact/<site>
'
,
defaults
=
{
'
node
'
:
None
,
'
interface_
'
:
None
}
)
@routes.route
(
'
/impact/<site>/<node>
'
)
@routes.route
(
'
/impact/<site>/<node>
'
,
defaults
=
{
'
interface_
'
:
None
}
)
@routes.route
(
'
/impact/<site>/<node>/<interface_>
'
)
@routes.route
(
'
/impact/<site>/<node>/<interface_>
'
)
def
get_impact
(
site
,
node
=
None
,
interface_
=
None
):
def
get_impact
(
site
,
node
,
interface_
):
cache_key_end
=
'
:
'
.
join
(
filter
(
None
,
(
site
,
node
,
interface_
)))
cache_key_end
=
'
:
'
.
join
(
filter
(
None
,
(
site
,
node
,
interface_
)))
cache_key
=
f
"
classifier-cache:mic:impact:
{
cache_key_end
}
"
cache_key
=
f
"
classifier-cache:mic:impact:
{
cache_key_end
}
"
logger
.
debug
(
cache_key
)
r
=
common
.
get_current_redis
()
r
=
common
.
get_current_redis
()
result
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
result
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
if
not
result
:
if
not
result
:
data
=
[]
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
if
interface_
:
if
interface_
:
key_pattern
=
f
"
ims:interface_services:
{
node
}
:
{
interface_
}
"
key_pattern
=
f
"
ims:interface_services:
{
node
}
:
{
interface_
}
"
data
=
[
r
.
get
(
key_pattern
)
]
raw_
data
=
r
.
get
(
key_pattern
)
elif
node
:
if
raw_data
:
data
=
[]
data
=
json
.
loads
(
raw_data
.
decode
(
'
utf-8
'
))
else
:
else
:
data
=
[]
def
_get_data
(
_key_pattern
):
data
=
(
json
.
loads
(
all_data
.
decode
(
'
utf-8
'
))
for
all_data
in
data
)
for
doc
in
common
.
load_json_docs
(
# convert list of lists to single dimensional list
config_params
=
config
,
data
=
itertools
.
chain
(
*
data
)
key_pattern
=
_key_pattern
,
# extract all related services from each list element and join into a
num_threads
=
20
,):
# single list
yield
from
doc
[
'
value
'
]
data
=
itertools
.
chain
(
*
(
d
.
get
(
'
related-services
'
,
[])
for
d
in
data
))
if
node
:
data
=
filter
(
key_pattern
=
f
"
ims:interface_services:
{
node
}
:*
"
lambda
x
:
x
[
'
circuit_type
'
]
==
'
service
'
else
:
and
x
[
'
status
'
]
==
'
operational
'
,
key_pattern
=
"
ims:interface_services:*
"
data
)
data
=
_get_data
(
key_pattern
)
unique_services
=
sorted
({
d
[
'
id
'
]:
d
for
d
in
data
}.
values
(),
key
=
lambda
x
:
x
[
'
name
'
])
services_by_type
=
defaultdict
(
list
)
services_by_type
=
defaultdict
(
list
)
for
service
in
unique_services
:
if
data
:
services_by_type
[
service
[
'
service_type
'
]].
append
({
'
id
'
:
service
[
'
id
'
],
rs
=
itertools
.
chain
(
'
sid
'
:
service
[
'
sid
'
],
*
(
d
.
get
(
'
related-services
'
,
[])
'
name
'
:
service
[
'
name
'
],
for
d
in
data
if
d
[
'
pop_name
'
]
==
site
))
'
service_type
'
:
service
[
'
service_type
'
],
'
contacts
'
:
service
[
'
contacts
'
]
rs
=
filter
(
})
lambda
x
:
x
[
'
circuit_type
'
]
==
'
service
'
and
x
[
'
status
'
]
==
'
operational
'
,
rs
)
unique_services
=
sorted
({
d
[
'
id
'
]:
d
for
d
in
rs
}.
values
(),
key
=
lambda
x
:
x
[
'
name
'
])
try
:
for
service
in
unique_services
:
services_by_type
[
service
[
'
service_type
'
]].
append
({
'
id
'
:
service
[
'
id
'
],
'
sid
'
:
service
.
get
(
'
sid
'
,
''
),
'
name
'
:
service
[
'
name
'
],
'
service_type
'
:
service
[
'
service_type
'
],
'
contacts
'
:
service
[
'
contacts
'
]
})
except
Exception
as
e
:
logger
.
debug
(
json
.
dumps
(
service
,
indent
=
2
))
raise
e
result
=
json
.
dumps
(
services_by_type
)
result
=
json
.
dumps
(
services_by_type
)
r
.
set
(
cache_key
,
result
.
encode
(
'
utf-8
'
))
r
.
set
(
cache_key
,
result
.
encode
(
'
utf-8
'
))
...
...
This diff is collapsed.
Click to expand it.
test/test_mic_routes.py
+
7
−
4
View file @
6a9a582e
import
json
import
json
import
jsonschema
import
jsonschema
import
pytest
from
inventory_provider.routes.mic
import
SITES_LIST_SCHEMA
,
\
from
inventory_provider.routes.mic
import
SITES_LIST_SCHEMA
,
\
NODES_LIST_SCHEMA
,
INTERFACES_LIST_SCHEMA
,
IMPACT_SCHEMA
NODES_LIST_SCHEMA
,
INTERFACES_LIST_SCHEMA
,
IMPACT_SCHEMA
...
@@ -41,10 +42,12 @@ def test_get_interfaces(client, mocked_redis):
...
@@ -41,10 +42,12 @@ def test_get_interfaces(client, mocked_redis):
jsonschema
.
validate
(
response_data
,
INTERFACES_LIST_SCHEMA
)
jsonschema
.
validate
(
response_data
,
INTERFACES_LIST_SCHEMA
)
def
test_get_impact
(
client
,
mocked_redis
):
@pytest.mark.parametrize
(
'
endpoint
'
,
[
rv
=
client
.
get
(
'
/mic/impact/AMSTERDAM/MX1.AMS.NL/AE21
'
,
'
/mic/impact/AMSTERDAM/MX1.AMS.NL/AE21
'
,
'
/mic/impact/LONDON/MX1.LON.UK
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
'
/mic/impact/GENEVA
'
])
def
test_get_impact
(
endpoint
,
client
,
mocked_redis
):
rv
=
client
.
get
(
endpoint
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
assert
rv
.
status_code
==
200
assert
rv
.
is_json
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
...
...
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