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
0df055b5
Commit
0df055b5
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added a response schema and test this
parent
834595eb
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/msr.py
+42
-3
42 additions, 3 deletions
inventory_provider/routes/msr.py
test/test_msr_routes.py
+24
-4
24 additions, 4 deletions
test/test_msr_routes.py
with
66 additions
and
7 deletions
inventory_provider/routes/msr.py
+
42
−
3
View file @
0df055b5
...
@@ -139,6 +139,36 @@ IP_ADDRESS_LIST_SCHEMA = {
...
@@ -139,6 +139,36 @@ IP_ADDRESS_LIST_SCHEMA = {
'
minItems
'
:
1
'
minItems
'
:
1
}
}
PEERING_ADDRESS_SERVICES_LIST
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
'
definitions
'
:
{
'
service
'
:
{
'
properties
'
:
{
'
name
'
:
{
'
type
'
:
'
string
'
},
'
type
'
:
{
'
type
'
:
'
string
'
},
'
status
'
:
{
'
type
'
:
'
string
'
}
},
'
required
'
:
[
'
name
'
,
'
type
'
,
'
status
'
],
'
additionalProperties
'
:
False
},
'
address-service-info
'
:
{
'
properties
'
:
{
'
address
'
:
{
'
type
'
:
'
string
'
},
'
hostname
'
:
{
'
type
'
:
'
string
'
},
'
interface
'
:
{
'
type
'
:
'
string
'
},
'
services
'
:
{
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/service
'
}
}
},
'
required
'
:
[
'
address
'
,
'
hostname
'
,
'
interface
'
,
'
services
'
],
'
additionalProperties
'
:
False
}
},
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/address-service-info
'
}
}
@routes.after_request
@routes.after_request
def
after_request
(
resp
):
def
after_request
(
resp
):
...
@@ -414,7 +444,7 @@ def _get_subnet_interfaces(address, r):
...
@@ -414,7 +444,7 @@ def _get_subnet_interfaces(address, r):
return
[]
return
[]
def
_get_peer_address_services
(
address
:
str
,
r
):
def
_get_peer_address_services
(
address
:
str
,
r
:
'
StrictRedis
'
):
for
ifc_info
in
_get_subnet_interfaces
(
address
,
r
):
for
ifc_info
in
_get_subnet_interfaces
(
address
,
r
):
ims_source_equipment
=
get_ims_equipment_name
(
ims_source_equipment
=
get_ims_equipment_name
(
ifc_info
[
'
router
'
],
r
)
ifc_info
[
'
router
'
],
r
)
...
@@ -549,10 +579,19 @@ def get_peering_services():
...
@@ -549,10 +579,19 @@ def get_peering_services():
"""
"""
Handler for `/msr/bgp/peering-services`
Handler for `/msr/bgp/peering-services`
Takes a json-formatted payload with the following schema:
This method must be called with POST method, and the payload
should be a json-formatted list of addresses (strings), which will
be validated against the following schema:
.. asjson::
inventory_provider.routes.msr.IP_ADDRESS_LIST_SCHEMA
The response will be formatted as follows:
.. asjson::
inventory_provider.routes.msr.PEERING_ADDRESS_SERVICES_LIST
A
parameter
`no-threads` can be given. If its truthiness
A `no-threads` can be
also be
given. If its truthiness
value evaluates to True, then the lookups are done in a single thread.
value evaluates to True, then the lookups are done in a single thread.
(This functionality is mainly for testing/debugging - it
'
s not
(This functionality is mainly for testing/debugging - it
'
s not
expected to be used in production.)
expected to be used in production.)
...
...
This diff is collapsed.
Click to expand it.
test/test_msr_routes.py
+
24
−
4
View file @
0df055b5
...
@@ -4,11 +4,13 @@ import jsonschema
...
@@ -4,11 +4,13 @@ import jsonschema
import
pytest
import
pytest
from
inventory_provider.routes.msr
import
PEERING_LIST_SCHEMA
,
\
from
inventory_provider.routes.msr
import
PEERING_LIST_SCHEMA
,
\
PEERING_GROUP_LIST_SCHEMA
,
IP_ADDRESS_LIST_SCHEMA
PEERING_GROUP_LIST_SCHEMA
,
PEERING_ADDRESS_SERVICES_LIST
,
\
_get_peer_address_services
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
DEFAULT_REQUEST_HEADERS
=
{
DEFAULT_REQUEST_HEADERS
=
{
"
Content-type
"
:
"
application/json
"
,
"
Accept
"
:
[
"
application/json
"
]
"
Accept
"
:
[
"
application/json
"
]
}
}
...
@@ -242,6 +244,24 @@ _OUTAGE_PEER_ADDRESSES = [
...
@@ -242,6 +244,24 @@ _OUTAGE_PEER_ADDRESSES = [
]
]
@pytest.mark.parametrize
(
'
address
'
,
[
'
62.40.127.141
'
,
'
62.40.127.139
'
])
def
test_lookup_peer_services
(
address
,
mocked_redis
):
_redis_instance
=
_get_redis
({
'
redis
'
:
{
'
hostname
'
:
None
,
'
port
'
:
None
},
'
redis-databases
'
:
[
0
,
7
]
})
info
=
list
(
_get_peer_address_services
(
address
,
r
=
_redis_instance
))
jsonschema
.
validate
(
info
,
PEERING_ADDRESS_SERVICES_LIST
)
assert
all
(
x
[
'
services
'
]
for
x
in
info
)
def
test_peering_services
(
client
):
def
test_peering_services
(
client
):
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
headers
.
update
(
DEFAULT_REQUEST_HEADERS
)
headers
.
update
(
DEFAULT_REQUEST_HEADERS
)
...
@@ -252,9 +272,9 @@ def test_peering_services(client):
...
@@ -252,9 +272,9 @@ def test_peering_services(client):
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
'
))
# jsonschema.validate(response_data, IP_ADDRESS_LIST_SCHEMA)
assert
response_data
# test data is non-empty
assert
response_data
# test data is non-empty
jsonschema
.
validate
(
response_data
,
PEERING_ADDRESS_SERVICES_LIST
)
def
test_peering_services_single_threaded
(
client
):
def
test_peering_services_single_threaded
(
client
):
...
@@ -268,6 +288,6 @@ def test_peering_services_single_threaded(client):
...
@@ -268,6 +288,6 @@ def test_peering_services_single_threaded(client):
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
'
))
# jsonschema.validate(response_data, IP_ADDRESS_LIST_SCHEMA)
assert
response_data
# test data is non-empty
assert
response_data
# test data is non-empty
jsonschema
.
validate
(
response_data
,
PEERING_ADDRESS_SERVICES_LIST
)
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