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
d1c81d53
Commit
d1c81d53
authored
2 years ago
by
Sam Roberts
Browse files
Options
Downloads
Patches
Plain Diff
add docstring, return schema and test
parent
c4cc14ce
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2
Feature/reporting 307 msr vpn proxy endpoint
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/msr.py
+44
-2
44 additions, 2 deletions
inventory_provider/routes/msr.py
test/test_msr_routes.py
+13
-1
13 additions, 1 deletion
test/test_msr_routes.py
with
57 additions
and
3 deletions
inventory_provider/routes/msr.py
+
44
−
2
View file @
d1c81d53
...
@@ -64,12 +64,19 @@ These endpoints are intended for use by MSR.
...
@@ -64,12 +64,19 @@ These endpoints are intended for use by MSR.
.. autofunction:: inventory_provider.routes.msr.mdvpn
.. autofunction:: inventory_provider.routes.msr.mdvpn
/msr/services
/msr/services
--------------------------------------------
--------------------------------------------
.. autofunction:: inventory_provider.routes.msr.get_system_correlation_services
.. autofunction:: inventory_provider.routes.msr.get_system_correlation_services
/msr/vpn-proxy
--------------------------------------------
.. autofunction:: inventory_provider.routes.msr.vpn-proxy
helpers
helpers
-------------------------------------
-------------------------------------
...
@@ -327,7 +334,10 @@ VPN_PROXY_LIST_SCHEMA = {
...
@@ -327,7 +334,10 @@ VPN_PROXY_LIST_SCHEMA = {
'
vpn_proxy_peering
'
:
{
'
vpn_proxy_peering
'
:
{
'
type
'
:
'
object
'
,
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
properties
'
:
{
# TODO: THIS
'
pop
'
:
{
'
type
'
:
'
string
'
},
'
nren
'
:
{
'
type
'
:
'
string
'
},
'
group
'
:
{
'
type
'
:
'
string
'
},
'
v4
'
:
{
'
type
'
:
'
string
'
}
},
},
'
additionalProperties
'
:
False
'
additionalProperties
'
:
False
}
}
...
@@ -1086,17 +1096,42 @@ def mdvpn():
...
@@ -1086,17 +1096,42 @@ def mdvpn():
@routes.route
(
'
/vpn-proxy
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@routes.route
(
'
/vpn-proxy
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
@common.require_accepts_json
def
vpn_proxy
():
def
vpn_proxy
():
"""
Handler for `/vpn-proxy`
This method returns a list of all L3VPN related VPN proxy peerings.
The response will be formatted according to the following schema:
.. asjson::
inventory_provider.routes.msr.VPN_PROXY_LIST_SCHEMA
:return:
"""
def
_is_relevant
(
item
):
def
_is_relevant
(
item
):
"""
Determine if a given peering in the VPN-PROXY logical system is
relevant to this endpoint (whether it
'
s related to L3VPN)
:param item: peering dict
:return: True if the peering is L3VPN relevant, False otherwise
"""
desc
=
item
.
get
(
"
description
"
)
desc
=
item
.
get
(
"
description
"
)
if
desc
is
None
:
if
desc
is
None
:
return
False
return
False
return
"
L3VPN
"
in
desc
return
"
L3VPN
"
in
desc
def
_look_up_city_from_hostname
(
hostname
):
def
_look_up_city_from_hostname
(
hostname
):
"""
Get the city name for a peering from a partial hostname match.
This uses a hardcoded lookup table.
:param hostname: hostname for the peering
:return: city name if found,
"
Unknown
"
otherwise
"""
for
snippet
in
DOMAIN_TO_POP_MAPPING
:
for
snippet
in
DOMAIN_TO_POP_MAPPING
:
if
snippet
in
hostname
:
if
snippet
in
hostname
:
return
DOMAIN_TO_POP_MAPPING
[
snippet
]
return
DOMAIN_TO_POP_MAPPING
[
snippet
]
return
"
Unknown
"
def
_extract_nren_from_description
(
desc
,
group
):
def
_extract_nren_from_description
(
desc
,
group
):
"""
"""
...
@@ -1116,6 +1151,12 @@ def vpn_proxy():
...
@@ -1116,6 +1151,12 @@ def vpn_proxy():
return
'
CESNet
'
return
'
CESNet
'
def
_format_peerings
(
vpnproxy
):
def
_format_peerings
(
vpnproxy
):
"""
Generator that iterates through a list of peering dicts, yielding
appropriately reformatted peerings if they are relevant to L3VPN.
:param vpnproxy: list of peering dicts taken from current redis
:return: generator of reformated peerings
"""
for
peering
in
vpnproxy
:
for
peering
in
vpnproxy
:
if
_is_relevant
(
peering
):
if
_is_relevant
(
peering
):
desc
=
peering
[
"
description
"
]
desc
=
peering
[
"
description
"
]
...
@@ -1135,7 +1176,8 @@ def vpn_proxy():
...
@@ -1135,7 +1176,8 @@ def vpn_proxy():
cache_key
=
'
classifier-cache:msr:vpn-proxy
'
cache_key
=
'
classifier-cache:msr:vpn-proxy
'
response
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
response
=
_ignore_cache_or_retrieve
(
request
,
cache_key
,
r
)
if
not
response
:
if
not
response
:
vpnproxy
=
json
.
loads
(
r
.
get
(
'
juniper-peerings:logical-system:VPN-PROXY
'
).
decode
(
'
utf-8
'
))
vpnproxy
=
json
.
loads
(
r
.
get
(
'
juniper-peerings:logical-system:VPN-PROXY
'
).
decode
(
'
utf-8
'
))
peerings
=
list
(
filter
(
None
,
_format_peerings
(
vpnproxy
)))
peerings
=
list
(
filter
(
None
,
_format_peerings
(
vpnproxy
)))
response
=
json
.
dumps
(
peerings
)
response
=
json
.
dumps
(
peerings
)
return
Response
(
response
,
mimetype
=
'
application/json
'
)
return
Response
(
response
,
mimetype
=
'
application/json
'
)
This diff is collapsed.
Click to expand it.
test/test_msr_routes.py
+
13
−
1
View file @
d1c81d53
...
@@ -6,7 +6,7 @@ import pytest
...
@@ -6,7 +6,7 @@ import pytest
from
inventory_provider.routes.msr
import
PEERING_LIST_SCHEMA
,
\
from
inventory_provider.routes.msr
import
PEERING_LIST_SCHEMA
,
\
PEERING_GROUP_LIST_SCHEMA
,
PEERING_ADDRESS_SERVICES_LIST
,
\
PEERING_GROUP_LIST_SCHEMA
,
PEERING_ADDRESS_SERVICES_LIST
,
\
SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA
,
_get_services_for_address
,
\
SYSTEM_CORRELATION_SERVICES_LIST_SCHEMA
,
_get_services_for_address
,
\
MDVPN_LIST_SCHEMA
MDVPN_LIST_SCHEMA
,
VPN_PROXY_LIST_SCHEMA
from
inventory_provider.routes.poller
import
SERVICES_LIST_SCHEMA
from
inventory_provider.routes.poller
import
SERVICES_LIST_SCHEMA
from
inventory_provider.tasks.common
import
_get_redis
from
inventory_provider.tasks.common
import
_get_redis
...
@@ -334,3 +334,15 @@ def test_get_mdvpn_peerings(client, mocked_redis):
...
@@ -334,3 +334,15 @@ def test_get_mdvpn_peerings(client, mocked_redis):
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
MDVPN_LIST_SCHEMA
)
jsonschema
.
validate
(
response_data
,
MDVPN_LIST_SCHEMA
)
assert
response_data
# test data is non-empty
assert
response_data
# test data is non-empty
def
test_get_vpn_proxy_peerings
(
client
,
mocked_redis
):
rv
=
client
.
get
(
'
/msr/vpn-proxy
'
,
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
,
VPN_PROXY_LIST_SCHEMA
)
assert
response_data
# test data is non-empty
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