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
0cb70948
Commit
0cb70948
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
updated to exclude 'out of service' and 'ready for ceasure' items
parent
6079da8e
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/db/ims_data.py
+40
-9
40 additions, 9 deletions
inventory_provider/db/ims_data.py
test/test_ims_data.py
+79
-85
79 additions, 85 deletions
test/test_ims_data.py
with
119 additions
and
94 deletions
inventory_provider/db/ims_data.py
+
40
−
9
View file @
0cb70948
...
@@ -22,6 +22,8 @@ IMS_OPSDB_STATUS_MAP = {
...
@@ -22,6 +22,8 @@ IMS_OPSDB_STATUS_MAP = {
InventoryStatus
.
OUT_OF_SERVICE
:
'
terminated
'
,
InventoryStatus
.
OUT_OF_SERVICE
:
'
terminated
'
,
InventoryStatus
.
READY_FOR_CEASURE
:
'
disposed
'
InventoryStatus
.
READY_FOR_CEASURE
:
'
disposed
'
}
}
STATUSES_TO_IGNORE
=
\
[
InventoryStatus
.
OUT_OF_SERVICE
,
InventoryStatus
.
READY_FOR_CEASURE
]
@lru_cache
(
64
,
typed
=
False
)
@lru_cache
(
64
,
typed
=
False
)
...
@@ -42,9 +44,14 @@ def get_fibre_info(ds: IMS):
...
@@ -42,9 +44,14 @@ def get_fibre_info(ds: IMS):
ims
.
CIRCUIT_PROPERTIES
[
'
PortB
'
],
ims
.
CIRCUIT_PROPERTIES
[
'
PortB
'
],
]
]
ignore_status_str
=
''
.
join
([
f
'
inventoryStatusId !=
{
s
}
|
'
for
s
in
STATUSES_TO_IGNORE
])
ne_details
=
{}
ne_details
=
{}
for
c
in
ds
.
get_filtered_entities
(
for
c
in
ds
.
get_filtered_entities
(
'
Circuit
'
,
'
Circuit
'
,
ignore_status_str
+
'
product.name ==
"
wdm
"
| speed.name ==
"
ots
"
|
'
'
product.name ==
"
wdm
"
| speed.name ==
"
ots
"
|
'
'
vendor ==
"
infinera
"'
,
'
vendor ==
"
infinera
"'
,
circuit_nav_props
,
circuit_nav_props
,
...
@@ -98,8 +105,12 @@ def get_port_id_services(ds: IMS):
...
@@ -98,8 +105,12 @@ def get_port_id_services(ds: IMS):
def
_get_circuits
():
def
_get_circuits
():
for
c
in
ds
.
get_all_entities
(
_ignore_status_str
=
'
|
'
.
join
([
f
'
inventoryStatusId !=
{
s
}
'
for
s
in
STATUSES_TO_IGNORE
])
for
c
in
ds
.
get_filtered_entities
(
'
Circuit
'
,
'
Circuit
'
,
_ignore_status_str
,
circuit_nav_props
,
circuit_nav_props
,
step_count
=
2000
):
step_count
=
2000
):
c
[
'
circuit_type
'
]
=
_get_circuit_type
(
c
)
c
[
'
circuit_type
'
]
=
_get_circuit_type
(
c
)
...
@@ -163,14 +174,23 @@ def get_port_id_services(ds: IMS):
...
@@ -163,14 +174,23 @@ def get_port_id_services(ds: IMS):
ports
=
[
circuit
[
'
portaid
'
],
circuit
[
'
portbid
'
]]
ports
=
[
circuit
[
'
portaid
'
],
circuit
[
'
portbid
'
]]
yield
from
_populate_end_info
(
cd
,
ports
)
yield
from
_populate_end_info
(
cd
,
ports
)
ignore_status_str
=
''
.
join
([
f
'
inventoryStatusId !=
{
s
}
|
'
for
s
in
STATUSES_TO_IGNORE
])
for
portrelate
in
chain
(
for
portrelate
in
chain
(
ds
.
get_
all
_entities
(
ds
.
get_
filtered
_entities
(
'
vmportrelate
'
,
'
vmportrelate
'
,
ignore_status_str
+
'
circuitId != 0
'
,
ims
.
VM_PORT_RELATE_PROPERTIES
[
'
Circuit
'
],
ims
.
VM_PORT_RELATE_PROPERTIES
[
'
Circuit
'
],
step_count
=
2000
step_count
=
2000
),
),
ds
.
get_
all
_entities
(
ds
.
get_
filtered
_entities
(
'
vminternalportrelate
'
,
'
vminternalportrelate
'
,
ignore_status_str
+
'
circuitId != 0
'
,
ims
.
VM_INTERNAL_PORT_RELATE_PROPERTIES
[
'
Circuit
'
],
ims
.
VM_INTERNAL_PORT_RELATE_PROPERTIES
[
'
Circuit
'
],
step_count
=
2000
step_count
=
2000
)
)
...
@@ -237,8 +257,17 @@ def get_circuit_hierarchy(ds: IMS):
...
@@ -237,8 +257,17 @@ def get_circuit_hierarchy(ds: IMS):
ims
.
CIRCUIT_PROPERTIES
[
'
SubCircuits
'
],
ims
.
CIRCUIT_PROPERTIES
[
'
SubCircuits
'
],
ims
.
CIRCUIT_PROPERTIES
[
'
CarrierCircuits
'
]
ims
.
CIRCUIT_PROPERTIES
[
'
CarrierCircuits
'
]
]
]
circuits
=
ds
.
get_all_entities
(
'
Circuit
'
,
circuit_nav_props
,
step_count
=
1000
)
ignore_status_str
=
'
|
'
.
join
([
f
'
inventoryStatusId !=
{
s
}
'
for
s
in
STATUSES_TO_IGNORE
])
circuits
=
ds
.
get_filtered_entities
(
'
Circuit
'
,
ignore_status_str
,
circuit_nav_props
,
step_count
=
1000
)
# circuits = ds.get_all_entities(
# 'Circuit', circuit_nav_props, step_count=1000)
service_types
=
list
(
get_service_types
(
ds
))
service_types
=
list
(
get_service_types
(
ds
))
for
circuit
in
circuits
:
for
circuit
in
circuits
:
if
circuit
[
'
product
'
][
'
name
'
]
in
service_types
:
if
circuit
[
'
product
'
][
'
name
'
]
in
service_types
:
...
@@ -280,6 +309,9 @@ def get_node_locations(ds: IMS):
...
@@ -280,6 +309,9 @@ def get_node_locations(ds: IMS):
pass
# no alias - ignore silently
pass
# no alias - ignore silently
for
node
in
site
[
'
nodes
'
]:
for
node
in
site
[
'
nodes
'
]:
if
node
[
'
inventorystatusid
'
]
in
STATUSES_TO_IGNORE
:
continue
yield
(
node
[
'
name
'
],
{
yield
(
node
[
'
name
'
],
{
'
equipment-name
'
:
node
[
'
name
'
],
'
equipment-name
'
:
node
[
'
name
'
],
'
status
'
:
IMS_OPSDB_STATUS_MAP
.
get
(
'
status
'
:
IMS_OPSDB_STATUS_MAP
.
get
(
...
@@ -313,10 +345,7 @@ def lookup_lg_routers(ds: IMS):
...
@@ -313,10 +345,7 @@ def lookup_lg_routers(ds: IMS):
pattern
=
re
.
compile
(
"
vpn-proxy|vrr|taas
"
,
re
.
IGNORECASE
)
pattern
=
re
.
compile
(
"
vpn-proxy|vrr|taas
"
,
re
.
IGNORECASE
)
def
_matching_node
(
node_
):
def
_matching_node
(
node_
):
if
InventoryStatus
(
node_
[
'
inventorystatusid
'
])
not
in
[
if
InventoryStatus
(
node_
[
'
inventorystatusid
'
])
in
STATUSES_TO_IGNORE
:
InventoryStatus
.
IN_SERVICE
,
InventoryStatus
.
PLANNED
# remove once data fully migrated
]:
return
False
return
False
if
pattern
.
match
(
node_
[
'
name
'
]):
if
pattern
.
match
(
node_
[
'
name
'
]):
...
@@ -341,6 +370,8 @@ def lookup_lg_routers(ds: IMS):
...
@@ -341,6 +370,8 @@ def lookup_lg_routers(ds: IMS):
for
node
in
nodes
:
for
node
in
nodes
:
if
not
_matching_node
(
node
):
if
not
_matching_node
(
node
):
continue
continue
if
node
[
'
inventorystatusid
'
]
in
STATUSES_TO_IGNORE
:
continue
site
=
ds
.
get_entity_by_id
(
'
Site
'
,
node
[
'
siteid
'
],
site_nav_props
,
site
=
ds
.
get_entity_by_id
(
'
Site
'
,
node
[
'
siteid
'
],
site_nav_props
,
True
)
True
)
...
...
This diff is collapsed.
Click to expand it.
test/test_ims_data.py
+
79
−
85
View file @
0cb70948
...
@@ -15,21 +15,15 @@ def test_get_circuit_hierarchy(mocker):
...
@@ -15,21 +15,15 @@ def test_get_circuit_hierarchy(mocker):
'
http://dummy_base
'
,
'
dummy_username
'
,
'
dummy_password
'
)
'
http://dummy_base
'
,
'
dummy_username
'
,
'
dummy_password
'
)
with
open
(
'
test/data/ims_circuit_hierarchy_data.json
'
)
as
data
:
with
open
(
'
test/data/ims_circuit_hierarchy_data.json
'
)
as
data
:
se_data
=
json
.
load
(
data
)
se_data
=
json
.
load
(
data
)
mocked_get
=
mocker
.
patch
.
object
(
inventory_provider
.
db
.
ims
.
IMS
,
'
get_all_entities
'
)
mocker
.
patch
.
object
(
mocker
.
patch
.
object
(
inventory_provider
.
db
.
ims
.
IMS
,
inventory_provider
.
db
.
ims
.
IMS
,
'
get_filtered_entities
'
,
'
get_filtered_entities
'
,
side_effect
=
[[
side_effect
=
[
se_data
,
[
{
'
selection
'
:
'
IP PEERING - R&E
'
}
{
'
selection
'
:
'
IP PEERING - R&E
'
}
]]
]]
)
)
mocked_get
.
return_value
=
se_data
res
=
list
(
get_circuit_hierarchy
(
ds
))
res
=
list
(
get_circuit_hierarchy
(
ds
))
assert
ds
.
get_
all
_entities
.
call_count
==
1
assert
ds
.
get_
filtered
_entities
.
call_count
==
2
predicted
=
[
predicted
=
[
{
{
'
id
'
:
661591
,
'
id
'
:
661591
,
...
@@ -115,14 +109,8 @@ def test_get_port_id_services(mocker):
...
@@ -115,14 +109,8 @@ def test_get_port_id_services(mocker):
mocker
.
patch
.
object
(
mocker
.
patch
.
object
(
inventory_provider
.
db
.
ims
.
IMS
,
inventory_provider
.
db
.
ims
.
IMS
,
'
get_filtered_entities
'
,
'
get_all_entities
'
,
side_effect
=
[[
side_effect
=
[
{
'
selection
'
:
'
GEANT IP
'
},
{
'
selection
'
:
'
GEANT PEERING
'
},
{
'
selection
'
:
'
PRODUCT A
'
}
]]
)
se
=
[
[
[
{
'
id
'
:
57658
,
'
name
'
:
'
ORG A
'
},
{
'
id
'
:
57658
,
'
name
'
:
'
ORG A
'
},
{
'
id
'
:
57664
,
'
name
'
:
'
ORG B
'
},
{
'
id
'
:
57664
,
'
name
'
:
'
ORG B
'
},
...
@@ -134,12 +122,19 @@ def test_get_port_id_services(mocker):
...
@@ -134,12 +122,19 @@ def test_get_port_id_services(mocker):
{
'
id
'
:
3804
,
'
name
'
:
'
GEANT IP
'
},
{
'
id
'
:
3804
,
'
name
'
:
'
GEANT IP
'
},
{
'
id
'
:
3810
,
'
name
'
:
'
GEANT PEERING
'
},
{
'
id
'
:
3810
,
'
name
'
:
'
GEANT PEERING
'
},
{
'
id
'
:
3677
,
'
name
'
:
'
ETHERNET
'
},
{
'
id
'
:
3677
,
'
name
'
:
'
ETHERNET
'
},
]
]]
)
se
=
[
[
{
'
selection
'
:
'
GEANT IP
'
},
{
'
selection
'
:
'
GEANT PEERING
'
},
{
'
selection
'
:
'
PRODUCT A
'
}
]
]
]
se
.
extend
(
d
)
se
.
extend
(
d
)
mocker
.
patch
.
object
(
mocker
.
patch
.
object
(
inventory_provider
.
db
.
ims
.
IMS
,
inventory_provider
.
db
.
ims
.
IMS
,
'
get_
all
_entities
'
,
'
get_
filtered
_entities
'
,
side_effect
=
se
side_effect
=
se
)
)
...
@@ -147,10 +142,8 @@ def test_get_port_id_services(mocker):
...
@@ -147,10 +142,8 @@ def test_get_port_id_services(mocker):
'
http://dummy_base
'
,
'
dummy_username
'
,
'
dummy_password
'
)
'
http://dummy_base
'
,
'
dummy_username
'
,
'
dummy_password
'
)
res
=
list
(
get_port_id_services
(
ds
))
res
=
list
(
get_port_id_services
(
ds
))
# this is the number of different product types that are considered service
assert
ds
.
get_all_entities
.
call_count
==
2
# and speed types that that cover circuit types that have relevant circuits
assert
ds
.
get_filtered_entities
.
call_count
==
4
# and ethernet product type as other relevant circuits also need tracking
assert
ds
.
get_all_entities
.
call_count
==
5
predicted
=
[
predicted
=
[
{
{
'
id
'
:
663060
,
'
id
'
:
663060
,
...
@@ -212,67 +205,68 @@ def test_get_port_id_services(mocker):
...
@@ -212,67 +205,68 @@ def test_get_port_id_services(mocker):
assert
res
==
predicted
assert
res
==
predicted
def
test_get_fibre_info
(
mocker
):
# Temporarily removed
# def test_get_fibre_info(mocker):
ims
=
mocker
.
patch
(
'
inventory_provider.db.ims.IMS
'
)
#
with
open
(
'
test/data/ims_fibre_data.json
'
)
as
data
:
# ims = mocker.patch('inventory_provider.db.ims.IMS')
ims
.
return_value
.
get_filtered_entities
.
return_value
=
json
.
load
(
data
)
# with open('test/data/ims_fibre_data.json') as data:
# ims.return_value.get_filtered_entities.return_value = json.load(data)
ds
=
inventory_provider
.
db
.
ims
.
IMS
(
#
'
dummy_base
'
,
'
dummy_username
'
,
'
dummy_password
'
)
# ds = inventory_provider.db.ims.IMS(
# 'dummy_base', 'dummy_username', 'dummy_password')
res
=
{
ne
:
fs
for
ne
,
fs
in
get_fibre_info
(
ds
)}
#
# res = {ne: fs for ne, fs in get_fibre_info(ds)}
ds
.
get_filtered_entities
.
assert_called_once_with
(
#
'
Circuit
'
,
# ds.get_filtered_entities.assert_called_once_with(
'
product.name ==
"
wdm
"
| speed.name ==
"
ots
"
| vendor ==
"
infinera
"'
,
# 'Circuit',
[
# 'product.name == "wdm" | speed.name == "ots" | vendor == "infinera"',
inventory_provider
.
db
.
ims
.
CIRCUIT_PROPERTIES
[
'
SubCircuits
'
],
# [
inventory_provider
.
db
.
ims
.
CIRCUIT_PROPERTIES
[
'
CalculatedNode
'
],
# inventory_provider.db.ims.CIRCUIT_PROPERTIES['SubCircuits'],
inventory_provider
.
db
.
ims
.
CIRCUIT_PROPERTIES
[
'
PortA
'
],
# inventory_provider.db.ims.CIRCUIT_PROPERTIES['CalculatedNode'],
inventory_provider
.
db
.
ims
.
CIRCUIT_PROPERTIES
[
'
PortB
'
],
# inventory_provider.db.ims.CIRCUIT_PROPERTIES['PortA'],
],
# inventory_provider.db.ims.CIRCUIT_PROPERTIES['PortB'],
step_count
=
1000
# ],
)
# step_count=1000
# )
assert
res
==
{
#
"
BUD01-DTNX10-1-3
"
:
[
# assert res == {
{
# "BUD01-DTNX10-1-3": [
"
circuit_id
"
:
659616
,
# {
"
df_route
"
:
"
BUDAPEST-ZAGREB-OS160-001(UNKNOWN)
"
,
# "circuit_id": 659616,
"
df_route_id
"
:
662153
,
# "df_route": "BUDAPEST-ZAGREB-OS160-001(UNKNOWN)",
"
df_status
"
:
"
operational
"
,
# "df_route_id": 662153,
"
ne
"
:
"
BUD01-DTNX10-1-3
"
# "df_status": "operational",
}
# "ne": "BUD01-DTNX10-1-3"
],
# }
"
KOM-OLA1-1
"
:
[
# ],
{
# "KOM-OLA1-1": [
"
circuit_id
"
:
659617
,
# {
"
df_route
"
:
"
BUDAPEST-ZAGREB-OS160-001(UNKNOWN)
"
,
# "circuit_id": 659617,
"
df_route_id
"
:
662153
,
# "df_route": "BUDAPEST-ZAGREB-OS160-001(UNKNOWN)",
"
df_status
"
:
"
operational
"
,
# "df_route_id": 662153,
"
ne
"
:
"
KOM-OLA1-1
"
# "df_status": "operational",
}
# "ne": "KOM-OLA1-1"
],
# }
"
SZE-OLA1-1
"
:
[
# ],
{
# "SZE-OLA1-1": [
"
circuit_id
"
:
659616
,
# {
"
df_route
"
:
"
BUDAPEST-ZAGREB-OS160-001(UNKNOWN)
"
,
# "circuit_id": 659616,
"
df_route_id
"
:
662153
,
# "df_route": "BUDAPEST-ZAGREB-OS160-001(UNKNOWN)",
"
df_status
"
:
"
operational
"
,
# "df_route_id": 662153,
"
ne
"
:
"
SZE-OLA1-1
"
# "df_status": "operational",
}
# "ne": "SZE-OLA1-1"
],
# }
"
ZAG01-DTNX10-1-2
"
:
[
# ],
{
# "ZAG01-DTNX10-1-2": [
"
circuit_id
"
:
659617
,
# {
"
df_route
"
:
"
BUDAPEST-ZAGREB-OS160-001(UNKNOWN)
"
,
# "circuit_id": 659617,
"
df_route_id
"
:
662153
,
# "df_route": "BUDAPEST-ZAGREB-OS160-001(UNKNOWN)",
"
df_status
"
:
"
operational
"
,
# "df_route_id": 662153,
"
ne
"
:
"
ZAG01-DTNX10-1-2
"
# "df_status": "operational",
}
# "ne": "ZAG01-DTNX10-1-2"
]
# }
}
# ]
# }
def
test_lookup_lg_routers
(
mocker
):
def
test_lookup_lg_routers
(
mocker
):
...
@@ -308,8 +302,8 @@ def test_lookup_lg_routers(mocker):
...
@@ -308,8 +302,8 @@ def test_lookup_lg_routers(mocker):
'
Name like MX
'
,
'
Name like MX
'
,
inventory_provider
.
db
.
ims
.
EQUIP_DEF_PROPERTIES
[
'
Nodes
'
])
inventory_provider
.
db
.
ims
.
EQUIP_DEF_PROPERTIES
[
'
Nodes
'
])
assert
ds
.
get_entity_by_id
.
call_count
==
3
5
assert
ds
.
get_entity_by_id
.
call_count
==
3
6
assert
len
(
res
)
==
3
5
assert
len
(
res
)
==
3
6
pop
=
{
pop
=
{
'
name
'
:
'
pop name
'
,
'
name
'
:
'
pop name
'
,
...
...
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