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
15c9f627
Commit
15c9f627
authored
5 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
test coriant response against schema
parent
b8455ebf
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/db/opsdb.py
+27
-5
27 additions, 5 deletions
inventory_provider/db/opsdb.py
inventory_provider/routes/classifier.py
+3
-0
3 additions, 0 deletions
inventory_provider/routes/classifier.py
test/test_opsdb_queries.py
+57
-3
57 additions, 3 deletions
test/test_opsdb_queries.py
with
87 additions
and
8 deletions
inventory_provider/db/opsdb.py
+
27
−
5
View file @
15c9f627
...
...
@@ -254,14 +254,23 @@ SELECT
vcc.circuit_type,
vcc.service_type,
vcc.peering_type,
vcc.status,
eq_a.name as equipment_name_a,
eq_b.name as equipment_name_b,
eqc_a.card_id as card_id_a,
eqc_a.card_id as card_id_b,
pop_a.name as pop_name_a,
pop_b.name as pop_name_b,
vcc.port_a as port_a,
vcc.port_b as port_b
pop_a.abbreviation as pop_abbreviation_a,
pop_b.abbreviation as pop_abbreviation_b,
pop_a.absid as pop_absid_a,
pop_b.absid as pop_absid_b,
pop_a.city as pop_city_a,
pop_b.city as pop_city_b,
pop_a.country as pop_country_a,
pop_b.country as pop_country_b,
vcc.port_a,
vcc.port_b
FROM vcircuitconns vcc
LEFT JOIN equipment eq_a ON eq_a.absid = vcc.PTR_equip_a
...
...
@@ -279,22 +288,35 @@ SELECT
'
circuit_type
'
:
row
[
'
circuit_type
'
],
'
service_type
'
:
row
[
'
service_type
'
],
'
peering_type
'
:
row
[
'
peering_type
'
],
'
status
'
:
row
[
'
status
'
],
'
a
'
:
{
'
name
'
:
row
[
'
equipment_name_a
'
],
'
card id
'
:
row
[
'
card_id_a
'
],
'
port number
'
:
row
[
'
port_a
'
],
'
pop
'
:
row
[
'
pop_name_a
'
]
'
pop
'
:
{
'
absid
'
:
row
[
'
pop_absid_a
'
],
'
name
'
:
row
[
'
pop_name_a
'
],
'
city
'
:
row
[
'
pop_city_a
'
],
'
country
'
:
row
[
'
pop_country_a
'
],
'
abbreviation
'
:
row
[
'
pop_abbreviation_a
'
]
}
},
'
b
'
:
{
'
name
'
:
row
[
'
equipment_name_b
'
],
'
card id
'
:
row
[
'
card_id_b
'
],
'
port number
'
:
row
[
'
port_b
'
],
'
pop
'
:
row
[
'
pop_name_b
'
]
'
pop
'
:
{
'
absid
'
:
row
[
'
pop_absid_b
'
],
'
name
'
:
row
[
'
pop_name_b
'
],
'
city
'
:
row
[
'
pop_city_b
'
],
'
country
'
:
row
[
'
pop_country_b
'
],
'
abbreviation
'
:
row
[
'
pop_abbreviation_b
'
]
}
}
}
circuit_query
=
base_query
+
"""
WHERE vcc.status
=
'
Operational
'
WHERE vcc.status
<>
'
Terminated
'
AND (
(eq_a.name = %(equipment_name)s
AND eqc_a.card_id = %(card_id)s
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/routes/classifier.py
+
3
−
0
View file @
15c9f627
...
...
@@ -294,7 +294,9 @@ def get_coriant_info(equipment_name, card_id, port_number):
if
result
:
result
=
result
.
decode
(
'
utf-8
'
)
else
:
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
with
db
.
connection
(
config
[
'
ops-db
'
])
as
cx
:
path
=
opsdb
.
get_coriant_path
(
cx
,
equipment_name
,
card_id
,
port_number
)
...
...
@@ -307,6 +309,7 @@ def get_coriant_info(equipment_name, card_id, port_number):
mimetype
=
"
text/html
"
)
result
=
json
.
dumps
({
'
path
'
:
path
})
# cache this data for the next call
r
.
set
(
cache_key
,
result
.
encode
(
'
utf-8
'
))
...
...
This diff is collapsed.
Click to expand it.
test/test_opsdb_queries.py
+
57
−
3
View file @
15c9f627
import
os
import
pytest
import
jsonschema
from
inventory_provider.db
import
db
from
inventory_provider.db
import
opsdb
...
...
@@ -35,6 +37,60 @@ def connection(db_params):
yield
c
CORIANT_PATH_METADATA
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
object
"
,
"
definitions
"
:
{
"
pop-info
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
absid
"
:
{
"
type
"
:
"
integer
"
},
"
name
"
:
{
"
type
"
:
"
string
"
},
"
abbreviation
"
:
{
"
type
"
:
"
string
"
},
"
country
"
:
{
"
type
"
:
"
string
"
},
"
city
"
:
{
"
type
"
:
"
string
"
}
},
"
required
"
:
[
"
absid
"
,
"
name
"
,
"
abbreviation
"
,
"
country
"
,
"
city
"
],
"
additionalProperties
"
:
False
},
"
endpoint
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
name
"
:
{
"
type
"
:
"
string
"
},
"
card id
"
:
{
"
type
"
:
"
string
"
},
"
port number
"
:
{
"
type
"
:
"
string
"
},
"
pop
"
:
{
"
$ref
"
:
"
#/definitions/pop-info
"
}
},
"
required
"
:
[
"
name
"
,
"
port number
"
,
"
pop
"
],
"
additionalProperties
"
:
False
}
},
"
type
"
:
"
object
"
,
"
properties
"
:
{
'
absid
'
:
{
"
type
"
:
"
integer
"
},
'
category
'
:
{
"
type
"
:
"
string
"
},
'
circuit_type
'
:
{
"
type
"
:
"
string
"
},
'
service_type
'
:
{
"
type
"
:
"
string
"
},
'
peering_type
'
:
{
"
type
"
:
"
string
"
},
'
status
'
:
{
"
type
"
:
"
string
"
},
'
a
'
:
{
"
$ref
"
:
"
#/definitions/endpoint
"
},
'
b
'
:
{
"
$ref
"
:
"
#/definitions/endpoint
"
}
},
"
required
"
:
[
"
absid
"
,
"
category
"
,
"
circuit_type
"
,
"
service_type
"
,
"
peering_type
"
,
"
status
"
,
"
a
"
,
"
b
"
],
"
additionalProperties
"
:
False
}
@pytest.mark.parametrize
(
'
equipment,card,port
'
,
[
(
'
grv3.lon.uk.geant.net
'
,
'
1-1
'
,
'
3
'
),
(
'
grv3.lon.uk.geant.net
'
,
'
1-1
'
,
'
5
'
),
...
...
@@ -43,6 +99,4 @@ def connection(db_params):
])
def
test_query
(
connection
,
equipment
,
card
,
port
):
circuit
=
opsdb
.
get_coriant_path
(
connection
,
equipment
,
card
,
port
)
from
pprint
import
pprint
pprint
(
circuit
)
jsonschema
.
validate
(
circuit
,
CORIANT_PATH_METADATA
)
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