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
370c720d
Commit
370c720d
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
fixed incorrect subnet lookup
parent
ac42bae8
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
+35
-7
35 additions, 7 deletions
inventory_provider/routes/msr.py
test/test_msr_routes.py
+12
-3
12 additions, 3 deletions
test/test_msr_routes.py
with
47 additions
and
10 deletions
inventory_provider/routes/msr.py
+
35
−
7
View file @
370c720d
...
...
@@ -62,6 +62,7 @@ helpers
.. autofunction:: inventory_provider.routes.msr._handle_peering_group_request
"""
# noqa E501
import
functools
import
itertools
import
json
import
ipaddress
...
...
@@ -83,6 +84,7 @@ from inventory_provider.tasks import common as tasks_common
routes
=
Blueprint
(
'
msr-query-routes
'
,
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
_subnet_lookup_semaphore
=
threading
.
Semaphore
()
PEERING_GROUP_LIST_SCHEMA
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
...
...
@@ -434,15 +436,41 @@ def _find_subnet_keys(addresses):
continue
@functools.lru_cache
(
100
)
def
_get_subnets
(
r
):
result
=
{}
for
k
in
r
.
scan_iter
(
'
subnets:*
'
,
count
=
1000
):
k
=
k
.
decode
(
'
utf-8
'
)
m
=
re
.
match
(
r
'
^subnets:(.+)$
'
,
k
)
assert
m
result
[
k
]
=
ipaddress
.
ip_interface
(
m
.
group
(
1
)).
network
return
result
def
_get_subnet_interfaces
(
address
,
r
):
exploded
=
ipaddress
.
ip_address
(
address
).
exploded
for
k
in
r
.
scan_iter
(
f
'
subnets:
{
exploded
}
/*
'
,
count
=
1000
):
value
=
r
.
get
(
k
.
decode
(
'
utf-8
'
))
# synchronize calls to _get_subnets, so we don't
# call it many times together when running in
# multi-thread mode
_subnet_lookup_semaphore
.
acquire
()
try
:
all_subnets
=
_get_subnets
(
r
)
except
:
logger
.
exception
(
'
error looking up subnets
'
)
all_subnets
=
{}
finally
:
_subnet_lookup_semaphore
.
release
()
address
=
ipaddress
.
ip_address
(
address
)
for
key
,
network
in
all_subnets
.
items
():
if
address
not
in
network
:
continue
value
=
r
.
get
(
key
)
if
not
value
:
return
None
value
=
value
.
decode
(
'
utf-8
'
)
return
json
.
loads
(
value
)
return
[]
logger
.
error
(
f
'
no value for for redis key
"
{
key
}
"'
)
continue
yield
from
json
.
loads
(
value
.
decode
(
'
utf-8
'
))
def
_get_services_for_address
(
address
:
str
,
r
:
'
StrictRedis
'
):
...
...
This diff is collapsed.
Click to expand it.
test/test_msr_routes.py
+
12
−
3
View file @
370c720d
...
...
@@ -140,8 +140,16 @@ def test_peerings_group_list(client, uri):
@pytest.mark.parametrize
(
'
address
'
,
[
'
62.40.127.141
'
,
'
62.40.127.139
'
# hand-chosen, should have services
'
62.40.127.141
'
,
# from sample peering outage response
'
62.40.127.139
'
,
# from sample peering outage response
'
62.40.98.201
'
,
# AMS-AMS IP TRUNK (mx1.ams/ae0.1)
'
62.40.127.134
'
,
# BELNET AP3 (mx1.ams/ae13.2)
'
62.40.124.38
'
,
# SURF AP1 (mx1.ams/ae15.1103)
'
62.40.125.57
'
,
# JISC AP2 (mx1.lon2/ae12.0)
'
2001:0798:0099:0001:0000:0000:0000:0026
'
,
# v6 peering with Internet2
'
2001:0798:0099:0001:0000:0000:0000:0056
'
,
# v6 peering with Canarie
'
2001:0798:0018:10aa:0000:0000:0000:0016
'
,
# v6 peering with HEANET
])
def
test_lookup_services_for_address
(
address
,
mocked_redis
):
_redis_instance
=
_get_redis
({
...
...
@@ -156,7 +164,8 @@ def test_lookup_services_for_address(address, mocked_redis):
jsonschema
.
validate
(
info
,
PEERING_ADDRESS_SERVICES_LIST
)
# sanity check to be sure we have interesting test data
assert
all
(
x
[
'
services
'
]
for
x
in
info
)
assert
info
assert
any
(
x
[
'
services
'
]
for
x
in
info
)
_OUTAGE_PEER_ADDRESSES
=
[
...
...
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