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
84d3395b
Commit
84d3395b
authored
5 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added msr route
parent
1e8024e9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/__init__.py
+3
-0
3 additions, 0 deletions
inventory_provider/__init__.py
inventory_provider/routes/msr.py
+42
-0
42 additions, 0 deletions
inventory_provider/routes/msr.py
test/test_msr_routes.py
+51
-0
51 additions, 0 deletions
test/test_msr_routes.py
with
96 additions
and
0 deletions
inventory_provider/__init__.py
+
3
−
0
View file @
84d3395b
...
...
@@ -61,6 +61,9 @@ def create_app():
from
inventory_provider.routes
import
lg
app
.
register_blueprint
(
lg
.
routes
,
url_prefix
=
'
/lg
'
)
from
inventory_provider.routes
import
msr
app
.
register_blueprint
(
msr
.
routes
,
url_prefix
=
'
/msr
'
)
if
app
.
config
.
get
(
'
ENABLE_TESTING_ROUTES
'
,
False
):
from
inventory_provider.routes
import
testing
app
.
register_blueprint
(
testing
.
routes
,
url_prefix
=
'
/testing
'
)
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/routes/msr.py
0 → 100644
+
42
−
0
View file @
84d3395b
import
json
from
flask
import
Blueprint
,
jsonify
,
Response
from
inventory_provider.routes
import
common
routes
=
Blueprint
(
"
msr-query-routes
"
,
__name__
)
@routes.after_request
def
after_request
(
resp
):
return
common
.
after_request
(
resp
)
@routes.route
(
"
/access-services
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
access_services
():
redis
=
common
.
get_current_redis
()
def
_services
():
for
k
in
redis
.
scan_iter
(
'
opsdb:access_services:*
'
):
service
=
redis
.
get
(
k
.
decode
(
'
utf-8
'
)).
decode
(
'
utf-8
'
)
yield
json
.
loads
(
service
)
cache_key
=
f
'
classifier-cache:msr:access-services
'
result
=
redis
.
get
(
cache_key
)
if
result
:
result
=
json
.
loads
(
result
.
decode
(
'
utf-8
'
))
else
:
result
=
list
(
_services
())
# cache this data for the next call
redis
.
set
(
cache_key
,
json
.
dumps
(
result
).
encode
(
'
utf-8
'
))
if
not
result
:
return
Response
(
response
=
f
'
no access services found
'
,
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
(
result
)
This diff is collapsed.
Click to expand it.
test/test_msr_routes.py
0 → 100644
+
51
−
0
View file @
84d3395b
import
json
import
jsonschema
import
pytest
DEFAULT_REQUEST_HEADERS
=
{
"
Content-type
"
:
"
application/json
"
,
"
Accept
"
:
[
"
application/json
"
]
}
ACCESS_SERVICES_LIST_SCHEMA
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
definitions
"
:
{
"
service
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
id
"
:
{
"
type
"
:
"
integer
"
},
"
name
"
:
{
"
type
"
:
"
string
"
},
"
equipment
"
:
{
"
type
"
:
"
string
"
},
"
pop_name
"
:
{
"
type
"
:
"
string
"
},
"
other_end_equipment
"
:
{
"
type
"
:
"
string
"
},
"
other_end_pop_name
"
:
{
"
type
"
:
"
string
"
},
"
speed_value
"
:
{
"
type
"
:
"
integer
"
},
"
speed_unit
"
:
{
"
type
"
:
"
string
"
}
},
"
required
"
:
[
"
id
"
,
"
name
"
,
"
pop_name
"
,
"
equipment
"
,
"
other_end_pop_name
"
,
"
other_end_equipment
"
,
"
speed_value
"
,
"
speed_unit
"
],
"
additionalProperties
"
:
False
}
},
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/service
"
}
}
def
test_access_services
(
client
):
rv
=
client
.
get
(
'
/msr/access-services
'
,
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
,
ACCESS_SERVICES_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