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
10e0c052
Commit
10e0c052
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added ix public peer groups
parent
d6d79ce3
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/classifier.py
+32
-0
32 additions, 0 deletions
inventory_provider/routes/classifier.py
test/test_classifier_routes.py
+19
-12
19 additions, 12 deletions
test/test_classifier_routes.py
with
51 additions
and
12 deletions
inventory_provider/routes/classifier.py
+
32
−
0
View file @
10e0c052
import
ipaddress
import
json
import
json
from
flask
import
Blueprint
,
Response
,
jsonify
from
flask
import
Blueprint
,
Response
,
jsonify
...
@@ -49,6 +50,35 @@ def get_trap_metadata(source_equipment, interface):
...
@@ -49,6 +50,35 @@ def get_trap_metadata(source_equipment, interface):
@common.require_accepts_json
@common.require_accepts_json
def
peer_info
(
address
):
def
peer_info
(
address
):
def
_related_ix_peers
(
ix_public_peer_info
):
"""
TODO: this is probably the least efficient way of doing this
(if it
'
s a problem, pre-compute these lists)
:param ix_public_peer_info: ix public peer info loaded for address
:return:
"""
protocol
=
type
(
ipaddress
.
ip_address
(
address
)).
__name__
description
=
ix_public_peer_info
[
'
description
'
]
assert
description
is
not
None
# sanity: at least empty string
keyword
=
description
.
split
(
'
'
)[
0
]
# regex needed??? (e.g. tabs???)
r
=
common
.
get_redis
()
for
k
in
r
.
keys
(
'
ix_public_peer:*
'
):
peer
=
r
.
get
(
k
.
decode
(
'
utf-8
'
)).
decode
(
'
utf-8
'
)
peer
=
json
.
loads
(
peer
)
assert
peer
[
'
description
'
]
is
not
None
# sanity: as above...
if
not
peer
[
'
description
'
].
startswith
(
keyword
):
continue
if
peer
[
'
name
'
]
==
address
:
continue
# skip self
peer_address
=
ipaddress
.
ip_address
(
peer
[
'
name
'
])
if
protocol
==
type
(
peer_address
).
__name__
:
yield
peer
[
'
name
'
]
r
=
common
.
get_redis
()
r
=
common
.
get_redis
()
result
=
{}
result
=
{}
...
@@ -57,6 +87,8 @@ def peer_info(address):
...
@@ -57,6 +87,8 @@ def peer_info(address):
if
info
:
if
info
:
info
=
info
.
decode
(
'
utf-8
'
)
info
=
info
.
decode
(
'
utf-8
'
)
result
[
'
ix-public-peer-info
'
]
=
json
.
loads
(
info
)
result
[
'
ix-public-peer-info
'
]
=
json
.
loads
(
info
)
result
[
'
ix-public-peer-group
'
]
=
list
(
_related_ix_peers
(
result
[
'
ix-public-peer-info
'
]))
info
=
r
.
get
(
'
vpn_rr_peer:%s
'
%
address
)
info
=
r
.
get
(
'
vpn_rr_peer:%s
'
%
address
)
if
info
:
if
info
:
...
...
This diff is collapsed.
Click to expand it.
test/test_classifier_routes.py
+
19
−
12
View file @
10e0c052
...
@@ -22,14 +22,19 @@ def test_trap_metadata(client_with_mocked_data):
...
@@ -22,14 +22,19 @@ def test_trap_metadata(client_with_mocked_data):
jsonschema
.
validate
(
response_data
,
response_schema
)
jsonschema
.
validate
(
response_data
,
response_schema
)
@pytest.mark.parametrize
(
"
peer_address,peer_type
"
,
[
VPN_RR_PEER_INFO_KEYS
=
{
'
vpn-rr-peer-info
'
}
(
'
109.105.110.54
'
,
'
vpn-rr-peer-info
'
),
IX_PUBLIC_PEER_INFO_KEYS
=
{
'
ix-public-peer-info
'
,
'
ix-public-peer-group
'
}
(
'
2001:07f8:001c:024a:0000:0000:316e:0001
'
,
'
ix-public-peer-info
'
),
(
'
2001:07f8:000b:0100:01d1:a5d1:0310:0029
'
,
'
ix-public-peer-info
'
),
(
'
195.66.224.238
'
,
'
ix-public-peer-info
'
),
@pytest.mark.parametrize
(
"
peer_address,expected_response_keys
"
,
[
(
'
109.105.110.54
'
,
VPN_RR_PEER_INFO_KEYS
),
(
'
2001:07f8:001c:024a:0000:0000:316e:0001
'
,
IX_PUBLIC_PEER_INFO_KEYS
),
(
'
2001:07f8:000b:0100:01d1:a5d1:0310:0029
'
,
IX_PUBLIC_PEER_INFO_KEYS
),
(
'
195.66.224.238
'
,
IX_PUBLIC_PEER_INFO_KEYS
),
]
]
)
)
def
test_peer_info
(
client_with_mocked_data
,
peer_address
,
peer_type
):
def
test_peer_info
(
client_with_mocked_data
,
peer_address
,
expected_response_keys
):
response_schema
=
{
response_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
object
"
,
"
type
"
:
"
object
"
,
...
@@ -53,7 +58,6 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
...
@@ -53,7 +58,6 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
"
required
"
:
[
"
name
"
,
"
description
"
],
"
required
"
:
[
"
name
"
,
"
description
"
],
"
additionalProperties
"
:
False
"
additionalProperties
"
:
False
},
},
"
ix-public-peer
"
:
{
"
ix-public-peer
"
:
{
"
type
"
:
"
object
"
,
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
properties
"
:
{
...
@@ -72,12 +76,18 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
...
@@ -72,12 +76,18 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
},
},
"
required
"
:
[
"
name
"
,
"
description
"
,
"
as
"
],
"
required
"
:
[
"
name
"
,
"
description
"
,
"
as
"
],
"
additionalProperties
"
:
False
"
additionalProperties
"
:
False
}
},
"
ix-public-peer-group
"
:
{
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/ip-address
"
}
},
},
},
"
type
"
:
"
object
"
,
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
properties
"
:
{
"
ix-public-peer-info
"
:
{
"
$ref
"
:
"
#/definitions/ix-public-peer
"
},
"
ix-public-peer-info
"
:
{
"
$ref
"
:
"
#/definitions/ix-public-peer
"
},
"
ix-public-peer-group
"
:
{
"
$ref
"
:
"
#/definitions/ix-public-peer-group
"
},
"
vpn-rr-peer-info
"
:
{
"
$ref
"
:
"
#/definitions/vpn-rr-peer
"
}
"
vpn-rr-peer-info
"
:
{
"
$ref
"
:
"
#/definitions/vpn-rr-peer
"
}
},
},
"
additionalProperties
"
:
False
"
additionalProperties
"
:
False
...
@@ -91,10 +101,7 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
...
@@ -91,10 +101,7 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
response_schema
)
jsonschema
.
validate
(
response_data
,
response_schema
)
assert
len
(
response_data
)
==
1
,
\
assert
set
(
response_data
.
keys
())
==
expected_response_keys
"
peer should be only vpn-rr or ix-public, not both
"
assert
peer_type
in
response_data
def
test_peer_not_found
(
client_with_mocked_data
):
def
test_peer_not_found
(
client_with_mocked_data
):
...
...
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