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
44afd145
Commit
44afd145
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
pep8
parent
370c720d
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
+19
-5
19 additions, 5 deletions
inventory_provider/routes/msr.py
test/conftest.py
+2
-11
2 additions, 11 deletions
test/conftest.py
with
21 additions
and
16 deletions
inventory_provider/routes/msr.py
+
19
−
5
View file @
44afd145
...
...
@@ -427,8 +427,10 @@ def _find_subnet_keys(addresses):
interface
=
ipaddress
.
ip_interface
(
m
.
group
(
1
))
try
:
matched_address
=
next
(
a
for
a
,
v
in
remaining_addresses
.
items
()
if
v
==
interface
.
ip
)
matched_address
=
next
(
a
for
a
,
v
in
remaining_addresses
.
items
()
if
v
==
interface
.
ip
)
del
remaining_addresses
[
matched_address
]
yield
k
,
matched_address
except
StopIteration
:
...
...
@@ -455,7 +457,7 @@ def _get_subnet_interfaces(address, r):
_subnet_lookup_semaphore
.
acquire
()
try
:
all_subnets
=
_get_subnets
(
r
)
except
:
except
Exception
:
logger
.
exception
(
'
error looking up subnets
'
)
all_subnets
=
{}
finally
:
...
...
@@ -473,8 +475,18 @@ def _get_subnet_interfaces(address, r):
yield
from
json
.
loads
(
value
.
decode
(
'
utf-8
'
))
def
_get_services_for_address
(
address
:
str
,
r
:
'
StrictRedis
'
):
def
_get_services_for_address
(
address
:
str
,
r
):
"""
match this address against all interfaces, then look up
any known services for that port
address is assumed to be in a valid v4/v6 format (it
'
s used to
construct a ipaddress.ip_address object without try/except)
:param address: ip address string
:param r: a Redis instance
:return: yields PEERING_ADDRESS_SERVICES_LIST elements
"""
def
_formatted_service
(
s
):
return
{
'
id
'
:
s
[
'
id
'
],
...
...
@@ -532,7 +544,9 @@ def _load_address_services_proc(address_queue, results_queue, config_params):
except
json
.
JSONDecodeError
:
logger
.
exception
(
f
'
error decoding redis entry for
{
address
}
'
)
except
:
except
Exception
:
# just log info about this error (for debugging only)
# ... and quit (i.e. let finally cleanup)
logger
.
exception
(
f
'
error looking up service info for
{
address
}
'
)
finally
:
# contract is to return None when finished
...
...
This diff is collapsed.
Click to expand it.
test/conftest.py
+
2
−
11
View file @
44afd145
...
...
@@ -20,6 +20,8 @@ TEST_DATA_DIRNAME = os.path.realpath(os.path.join(
"
test
"
,
"
data
"
))
_bootstrap_semaphore
=
threading
.
Semaphore
()
@pytest.fixture
def
data_config_filename
():
...
...
@@ -86,17 +88,6 @@ def data_config(data_config_filename):
return
config
.
load
(
f
)
TEST_DATA_DIRNAME
=
os
.
path
.
realpath
(
os
.
path
.
join
(
inventory_provider
.
__path__
[
0
],
"
..
"
,
"
test
"
,
"
data
"
))
_bootstrap_semaphore
=
threading
.
Semaphore
()
class
MockedRedis
(
object
):
db
=
None
...
...
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