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
4928c78a
Commit
4928c78a
authored
3 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
added chorded update task and test route to trigger
parent
763d8a7f
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/routes/testing.py
+6
-0
6 additions, 0 deletions
inventory_provider/routes/testing.py
inventory_provider/tasks/worker.py
+625
-2
625 additions, 2 deletions
inventory_provider/tasks/worker.py
test/test_worker.py
+301
-2
301 additions, 2 deletions
test/test_worker.py
with
932 additions
and
4 deletions
inventory_provider/routes/testing.py
+
6
−
0
View file @
4928c78a
...
@@ -18,6 +18,12 @@ routes = Blueprint("inventory-data-testing-support-routes", __name__)
...
@@ -18,6 +18,12 @@ routes = Blueprint("inventory-data-testing-support-routes", __name__)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
@routes.route
(
"
chord-update
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
chord_update
():
r
=
worker
.
update_entry_point
.
delay
().
get
()
return
jsonify
(
r
)
@routes.route
(
"
flushdb
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@routes.route
(
"
flushdb
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
flushdb
():
def
flushdb
():
common
.
get_current_redis
().
flushdb
()
common
.
get_current_redis
().
flushdb
()
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
625
−
2
View file @
4928c78a
This diff is collapsed.
Click to expand it.
test/test_worker.py
+
301
−
2
View file @
4928c78a
from
inventory_provider.tasks
import
common
from
inventory_provider.tasks.worker
import
transform_ims_data
,
\
extract_ims_data
,
persist_ims_data
def
test_place_holder
():
def
test_extract_ims_data
(
mocker
):
assert
True
mocker
.
patch
(
'
inventory_provider.tasks.worker.InventoryTask.config
'
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.get_node_locations
'
,
return_value
=
[(
'
loc_a
'
,
'
LOC A
'
),
(
'
loc_b
'
,
'
LOC B
'
)]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.lookup_lg_routers
'
,
return_value
=
[
'
lg router 1
'
,
'
lg router 2
'
]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.get_customer_service_emails
'
,
return_value
=
[(
'
123
'
,
'
CON A
'
),
(
'
456
'
,
'
CON B
'
)]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.get_monitored_circuit_ids
'
,
return_value
=
[
123
,
456
,
789
]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.
'
'
get_circuit_related_customer_ids
'
,
return_value
=
[{
'
id a
'
:
[
'
A
'
,
'
A2
'
]},
{
'
id b
'
:
[
'
B
'
]}]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.get_circuit_hierarchy
'
,
return_value
=
[
{
'
id
'
:
'
1
'
,
'
value
'
:
'
A
'
},
{
'
id
'
:
'
2
'
,
'
value
'
:
'
B
'
}
]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.get_port_details
'
,
return_value
=
[
{
'
port_id
'
:
'
A
'
,
'
value
'
:
'
a
'
},
{
'
port_id
'
:
'
B
'
,
'
value
'
:
'
b
'
},
{
'
port_id
'
:
'
B
'
,
'
value
'
:
'
c
'
}
]
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.ims_data.get_port_id_services
'
,
return_value
=
[
{
'
port_a_id
'
:
'
1
'
,
'
value
'
:
'
1A
'
},
{
'
port_a_id
'
:
'
1
'
,
'
value
'
:
'
1B
'
},
{
'
port_a_id
'
:
'
2
'
,
'
value
'
:
'
2A
'
}
]
)
res
=
extract_ims_data
()
assert
res
[
'
locations
'
]
==
{
'
loc_a
'
:
'
LOC A
'
,
'
loc_b
'
:
'
LOC B
'
}
assert
res
[
'
lg_routers
'
]
==
[
'
lg router 1
'
,
'
lg router 2
'
]
assert
res
[
'
customer_contacts
'
]
==
{
'
123
'
:
'
CON A
'
,
'
456
'
:
'
CON B
'
}
assert
res
[
'
circuit_ids_to_monitor
'
]
==
[
123
,
456
,
789
]
assert
res
[
'
additional_circuit_customer_ids
'
]
==
\
[{
'
id a
'
:
[
'
A
'
,
'
A2
'
]},
{
'
id b
'
:
[
'
B
'
]}]
assert
res
[
'
hierarchy
'
]
==
{
'
1
'
:
{
'
id
'
:
'
1
'
,
'
value
'
:
'
A
'
},
'
2
'
:
{
'
id
'
:
'
2
'
,
'
value
'
:
'
B
'
}
}
assert
res
[
'
port_id_details
'
]
==
{
'
A
'
:
[{
'
port_id
'
:
'
A
'
,
'
value
'
:
'
a
'
}],
'
B
'
:
[
{
'
port_id
'
:
'
B
'
,
'
value
'
:
'
b
'
},
{
'
port_id
'
:
'
B
'
,
'
value
'
:
'
c
'
}
]
}
assert
res
[
'
port_id_services
'
]
==
{
'
1
'
:
[
{
'
port_a_id
'
:
'
1
'
,
'
value
'
:
'
1A
'
},
{
'
port_a_id
'
:
'
1
'
,
'
value
'
:
'
1B
'
}
],
'
2
'
:
[{
'
port_a_id
'
:
'
2
'
,
'
value
'
:
'
2A
'
}]
}
def
test_transform_ims_data
():
locations
=
{
"
eq_a
"
:
{
"
pop
"
:
{
"
name
"
:
"
pop_loc_a
"
,
"
abbreviation
"
:
"
pla
"
,
}
},
"
eq_b
"
:
{
"
pop
"
:
{
"
name
"
:
"
pop_loc_b
"
,
"
abbreviation
"
:
"
plb
"
,
}
},
"
UNKNOWN_LOC
"
:
{
"
pop
"
:
{
"
name
"
:
"
UNKNOWN
"
,
"
abbreviation
"
:
"
UNKNOWN
"
,
}
}
}
additional_circuit_customer_ids
=
{
"
circ_id_1
"
:
"
cu_1_1
"
}
customer_contacts
=
{
"
cu_1
"
:
[
"
customer_1@a.org
"
],
"
cu_1_1
"
:
[
"
customer_1_1@a.org
"
]
}
port_id_details
=
{
"
port_id_1
"
:
[{
"
equipment_name
"
:
"
eq_a
"
,
"
interface_name
"
:
"
if_a
"
,
"
port_id
"
:
"
port_id_1
"
}],
"
port_id_2
"
:
[{
"
equipment_name
"
:
"
eq_b
"
,
"
interface_name
"
:
"
if_b
"
,
"
port_id
"
:
"
port_id_2
"
}]
}
port_id_services
=
{
"
port_id_1
"
:
[
{
"
id
"
:
"
circ_id_1
"
,
"
customerid
"
:
"
cu_1
"
,
"
circuit_type
"
:
"
circuit
"
,
"
service_type
"
:
"
ETHERNET
"
,
"
status
"
:
"
operational
"
,
"
port_a_id
"
:
"
port_id_1
"
,
"
port_b_id
"
:
"
port_id_2
"
,
}
],
"
port_id_2
"
:
[
{
"
id
"
:
"
circ_id_1
"
,
"
customerid
"
:
"
cu_1
"
,
"
circuit_type
"
:
"
circuit
"
,
"
service_type
"
:
"
ETHERNET
"
,
"
status
"
:
"
operational
"
,
"
port_a_id
"
:
"
port_id_2
"
,
"
port_b_id
"
:
"
port_id_1
"
,
}
]
}
hierarchy
=
{
"
circ_id_1
"
:
{
"
id
"
:
"
circ_id_1
"
,
"
name
"
:
"
circ_name_1
"
,
"
status
"
:
"
operational
"
,
"
circuit-type
"
:
"
circuit
"
,
"
product
"
:
"
ethernet
"
,
"
speed
"
:
"
not fibre_route
"
,
"
carrier-circuits
"
:
[
"
carrier_id_1
"
],
"
sub-circuits
"
:
[
"
sub_circuit_1
"
],
"
customerid
"
:
"
cu_1
"
,
},
"
carrier_id_1
"
:
{
"
id
"
:
"
carrier_id_1
"
,
"
name
"
:
"
circ_carrier_name_1
"
,
"
status
"
:
"
operational
"
,
"
circuit-type
"
:
"
circuit
"
,
"
product
"
:
"
ethernet
"
,
"
speed
"
:
"
10G
"
,
"
carrier-circuits
"
:
[
"
carrier_id_2
"
],
"
sub-circuits
"
:
[
"
circ_id_1
"
],
"
customerid
"
:
"
cu_1
"
,
},
"
carrier_id_2
"
:
{
"
id
"
:
"
carrier_id_2
"
,
"
name
"
:
"
circ_carrier_name_3
"
,
"
status
"
:
"
operational
"
,
"
circuit-type
"
:
"
circuit
"
,
"
product
"
:
"
ethernet
"
,
"
speed
"
:
"
not fibre_route
"
,
"
carrier-circuits
"
:
[
"
carrier_id_3
"
],
"
sub-circuits
"
:
[
"
carrier_id_1
"
],
"
customerid
"
:
"
cu_1
"
,
},
"
carrier_id_3
"
:
{
"
id
"
:
"
carrier_id_3
"
,
"
name
"
:
"
Fiber Route Circuit
"
,
"
status
"
:
"
operational
"
,
"
circuit-type
"
:
"
circuit
"
,
"
product
"
:
"
OCG4
"
,
"
speed
"
:
"
fibre_route
"
,
"
carrier-circuits
"
:
[],
"
sub-circuits
"
:
[
"
carrier_id_2
"
],
"
customerid
"
:
"
cu_1
"
,
},
"
sub_circuit_1
"
:
{
"
id
"
:
"
sub_circuit_1
"
,
"
name
"
:
"
sub_circuit_name_1
"
,
"
status
"
:
"
operational
"
,
"
circuit-type
"
:
"
circuit
"
,
"
product
"
:
"
ethernet
"
,
"
speed
"
:
"
not fibre_route
"
,
"
carrier-circuits
"
:
[
"
circ_id_1
"
],
"
sub-circuits
"
:
[
"
sub_circuit_2
"
],
"
customerid
"
:
"
cu_1
"
,
},
"
sub_circuit_2
"
:
{
"
id
"
:
"
sub_circuit_2
"
,
"
name
"
:
"
sub_circuit_name_2
"
,
"
status
"
:
"
operational
"
,
"
circuit-type
"
:
"
service
"
,
"
product
"
:
"
PEERING R & E
"
,
"
speed
"
:
"
not fiber route
"
,
"
project
"
:
"
Project A
"
,
"
carrier-circuits
"
:
[
"
sub_circuit_1
"
],
"
sub-circuits
"
:
[],
"
customerid
"
:
"
cu_1
"
,
}
}
data
=
{
"
locations
"
:
locations
,
"
customer_contacts
"
:
customer_contacts
,
"
circuit_ids_to_monitor
"
:
[],
"
additional_circuit_customer_ids
"
:
additional_circuit_customer_ids
,
"
hierarchy
"
:
hierarchy
,
"
port_id_details
"
:
port_id_details
,
"
port_id_services
"
:
port_id_services
}
res
=
transform_ims_data
(
data
)
ifs
=
res
[
"
interface_services
"
]
assert
list
(
ifs
.
keys
())
==
[
"
eq_a:if_a
"
,
"
eq_b:if_b
"
]
for
v
in
ifs
.
values
():
assert
len
(
v
)
==
1
assert
len
(
v
[
0
][
"
related-services
"
])
==
1
assert
v
[
0
][
"
related-services
"
][
0
][
"
id
"
]
==
"
sub_circuit_2
"
assert
len
(
v
[
0
][
"
fibre-routes
"
])
==
1
assert
v
[
0
][
"
fibre-routes
"
][
0
][
"
id
"
]
==
"
carrier_id_3
"
def
test_persist_ims_data
(
mocker
,
data_config
,
mocked_redis
):
r
=
common
.
_get_redis
(
data_config
)
mocker
.
patch
(
'
inventory_provider.tasks.worker.get_next_redis
'
,
return_value
=
r
)
data
=
{
"
locations
"
:
{
"
loc_a
"
:
"
LOC A
"
,
"
loc_b
"
:
"
LOC B
"
},
"
lg_routers
"
:
[
{
"
equipment name
"
:
"
lg_eq1
"
},
{
"
equipment name
"
:
"
lg_eq2
"
}
],
"
hierarchy
"
:
{
"
c1
"
:
{
"
id
"
:
"
123
"
},
"
c2
"
:
{
"
id
"
:
"
456
"
}},
"
interface_services
"
:
{
"
if1
"
:
[
{
"
equipment
"
:
"
eq1
"
,
"
port
"
:
"
port1
"
,
"
id
"
:
"
id1
"
,
"
name
"
:
"
name1
"
,
"
service_type
"
:
"
type1
"
,
"
status
"
:
"
operational
"
},
{
"
equipment
"
:
"
eq1
"
,
"
port
"
:
"
port2
"
,
"
id
"
:
"
id3
"
,
"
name
"
:
"
name2
"
,
"
service_type
"
:
"
type2
"
,
"
status
"
:
"
operational
"
}
],
"
if2
"
:
[
{
"
equipment
"
:
"
eq2
"
,
"
port
"
:
"
port1
"
,
"
id
"
:
"
id3
"
,
"
name
"
:
"
name3
"
,
"
service_type
"
:
"
type1
"
,
"
status
"
:
"
operational
"
}
]
},
"
services_by_type
"
:
{},
}
for
k
in
r
.
keys
(
"
ims:*
"
):
r
.
delete
(
k
)
persist_ims_data
(
data
)
assert
[
k
.
decode
(
"
utf-8
"
)
for
k
in
r
.
keys
(
"
ims:location:*
"
)]
==
\
[
"
ims:location:loc_a
"
,
"
ims:location:loc_b
"
]
assert
[
k
.
decode
(
"
utf-8
"
)
for
k
in
r
.
keys
(
"
ims:lg:*
"
)]
==
\
[
"
ims:lg:lg_eq1
"
,
"
ims:lg:lg_eq2
"
]
assert
[
k
.
decode
(
"
utf-8
"
)
for
k
in
r
.
keys
(
"
ims:circuit_hierarchy:*
"
)]
==
\
[
"
ims:circuit_hierarchy:123
"
,
"
ims:circuit_hierarchy:456
"
]
assert
[
k
.
decode
(
"
utf-8
"
)
for
k
in
r
.
keys
(
"
ims:interface_services:*
"
)]
==
\
[
"
ims:interface_services:if1
"
,
"
ims:interface_services:if2
"
]
assert
[
k
.
decode
(
"
utf-8
"
)
for
k
in
r
.
keys
(
"
poller_cache:*
"
)]
==
\
[
"
poller_cache:eq1
"
,
"
poller_cache:eq2
"
]
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