Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-polling-manager
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
brian
brian-polling-manager
Commits
ead28fe3
Commit
ead28fe3
authored
1 year ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
load netconf once and at a single timestamp for both brian and error counters
parent
6c647e4a
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
brian_polling_manager/interface_stats/cli.py
+10
-6
10 additions, 6 deletions
brian_polling_manager/interface_stats/cli.py
test/interface_stats/test_interface_stats.py
+14
-12
14 additions, 12 deletions
test/interface_stats/test_interface_stats.py
with
24 additions
and
18 deletions
brian_polling_manager/interface_stats/cli.py
+
10
−
6
View file @
ead28fe3
...
@@ -24,7 +24,7 @@ DEFAULT_INTERFACES_URL = "/poller/interfaces/"
...
@@ -24,7 +24,7 @@ DEFAULT_INTERFACES_URL = "/poller/interfaces/"
class
PointGroup
(
enum
.
Enum
):
class
PointGroup
(
enum
.
Enum
):
BRIAN
=
(
"
brian
"
,
"
brian-counters
"
,
vendors
.
brian_points
)
BRIAN
=
(
"
brian
"
,
"
brian-counters
"
,
vendors
.
brian_points
)
ERRORS
=
(
"
error
s
"
,
"
error-counters
"
,
vendors
.
error_points
)
ERRORS
=
(
"
error
"
,
"
error-counters
"
,
vendors
.
error_points
)
def
config_params
(
self
,
app_params
:
dict
):
def
config_params
(
self
,
app_params
:
dict
):
return
app_params
[
self
.
value
[
1
]]
return
app_params
[
self
.
value
[
1
]]
...
@@ -154,16 +154,15 @@ def _get_interfaces_for_router(
...
@@ -154,16 +154,15 @@ def _get_interfaces_for_router(
def
process_router
(
def
process_router
(
router_fqdn
:
str
,
router_fqdn
:
str
,
vendor
:
Vendor
,
vendor
:
Vendor
,
document
:
Any
,
timestamp
:
datetime
,
interfaces
:
Optional
[
List
[
str
]],
interfaces
:
Optional
[
List
[
str
]],
app_config_params
:
dict
,
app_config_params
:
dict
,
output
:
OutputMethod
,
output
:
OutputMethod
,
point_group
:
PointGroup
,
point_group
:
PointGroup
,
):
):
ssh_params
=
vendor
.
config_params
(
app_config_params
)
document
=
vendor
.
get_netconf
(
router_name
=
router_fqdn
,
ssh_params
=
ssh_params
)
timestamp
=
datetime
.
now
()
influx_params
=
point_group
.
config_params
(
app_config_params
)[
"
influx
"
]
influx_params
=
point_group
.
config_params
(
app_config_params
)[
"
influx
"
]
points
=
list
(
points
=
list
(
_points
(
_points
(
router_fqdn
=
router_fqdn
,
router_fqdn
=
router_fqdn
,
...
@@ -176,7 +175,7 @@ def process_router(
...
@@ -176,7 +175,7 @@ def process_router(
)
)
)
)
_log_interface_points_sorted
(
points
,
point_kind
=
"
error
"
)
_log_interface_points_sorted
(
points
,
point_kind
=
str
(
point_group
)
)
output
.
write_points
(
points
,
influx_params
=
influx_params
)
output
.
write_points
(
points
,
influx_params
=
influx_params
)
...
@@ -226,6 +225,9 @@ def main(
...
@@ -226,6 +225,9 @@ def main(
if
not
app_config_params
.
get
(
vendor_str
):
if
not
app_config_params
.
get
(
vendor_str
):
raise
ValueError
(
f
"'
{
vendor_str
}
'
ssh params are required
"
)
raise
ValueError
(
f
"'
{
vendor_str
}
'
ssh params are required
"
)
ssh_params
=
vendor
.
config_params
(
app_config_params
)
netconf
=
vendor
.
get_netconf
(
router_name
=
router_fqdn
,
ssh_params
=
ssh_params
)
timestamp
=
datetime
.
now
()
for
point_group
in
PointGroup
:
for
point_group
in
PointGroup
:
logger
.
info
(
f
"
Processing
{
str
(
point_group
).
capitalize
()
}
points...
"
)
logger
.
info
(
f
"
Processing
{
str
(
point_group
).
capitalize
()
}
points...
"
)
...
@@ -240,6 +242,8 @@ def main(
...
@@ -240,6 +242,8 @@ def main(
process_router
(
process_router
(
router_fqdn
=
router_fqdn
,
router_fqdn
=
router_fqdn
,
vendor
=
vendor
,
vendor
=
vendor
,
document
=
netconf
,
timestamp
=
timestamp
,
interfaces
=
check_interfaces
,
interfaces
=
check_interfaces
,
app_config_params
=
app_config_params
,
app_config_params
=
app_config_params
,
output
=
output
,
output
=
output
,
...
...
This diff is collapsed.
Click to expand it.
test/interface_stats/test_interface_stats.py
+
14
−
12
View file @
ead28fe3
...
@@ -208,15 +208,17 @@ def test_main_for_all_juniper_routers(
...
@@ -208,15 +208,17 @@ def test_main_for_all_juniper_routers(
def
mocked_load_inventory
():
def
mocked_load_inventory
():
with
patch
.
object
(
cli
,
"
load_inventory_json
"
)
as
mock
:
with
patch
.
object
(
cli
,
"
load_inventory_json
"
)
as
mock
:
mock
.
return_value
=
[
mock
.
return_value
=
[
{
"
router
"
:
"
router1
"
,
"
name
"
:
"
ifc1
"
},
{
"
router
"
:
"
mx1.ams.nl.geant.net
"
,
"
name
"
:
"
ifc1
"
},
{
"
router
"
:
"
router1
"
,
"
name
"
:
"
ifc2
"
},
{
"
router
"
:
"
mx1.ams.nl.geant.net
"
,
"
name
"
:
"
ifc2
"
},
{
"
router
"
:
"
router2
"
,
"
name
"
:
"
ifc3
"
},
{
"
router
"
:
"
mx1.lon.uk.geant.net
"
,
"
name
"
:
"
ifc3
"
},
]
]
yield
mock
yield
mock
@patch.object
(
cli
,
"
process_router
"
)
@patch.object
(
cli
,
"
process_router
"
)
def
test_main_with_some_interfaces
(
process_router
,
mocked_load_inventory
):
def
test_main_with_some_interfaces
(
process_router
,
mocked_load_inventory
,
mocked_get_netconf
):
config
=
{
config
=
{
"
juniper
"
:
{
"
some
"
:
"
params
"
},
"
juniper
"
:
{
"
some
"
:
"
params
"
},
"
inventory
"
:
[
"
some-inprov
"
],
"
inventory
"
:
[
"
some-inprov
"
],
...
@@ -225,7 +227,7 @@ def test_main_with_some_interfaces(process_router, mocked_load_inventory):
...
@@ -225,7 +227,7 @@ def test_main_with_some_interfaces(process_router, mocked_load_inventory):
}
}
cli
.
main
(
cli
.
main
(
config
,
config
,
"
router1
"
,
"
mx1.ams.nl.geant.net
"
,
Vendor
.
JUNIPER
,
Vendor
.
JUNIPER
,
interfaces
=
[
"
ifc1
"
],
interfaces
=
[
"
ifc1
"
],
)
)
...
@@ -234,7 +236,7 @@ def test_main_with_some_interfaces(process_router, mocked_load_inventory):
...
@@ -234,7 +236,7 @@ def test_main_with_some_interfaces(process_router, mocked_load_inventory):
@patch.object
(
cli
,
"
process_router
"
)
@patch.object
(
cli
,
"
process_router
"
)
def
test_main_with_all_interfaces_and_inprov_hosts
(
def
test_main_with_all_interfaces_and_inprov_hosts
(
process_router
,
mocked_load_inventory
process_router
,
mocked_load_inventory
,
mocked_get_netconf
):
):
config
=
{
config
=
{
"
juniper
"
:
{
"
some
"
:
"
params
"
},
"
juniper
"
:
{
"
some
"
:
"
params
"
},
...
@@ -242,20 +244,20 @@ def test_main_with_all_interfaces_and_inprov_hosts(
...
@@ -242,20 +244,20 @@ def test_main_with_all_interfaces_and_inprov_hosts(
"
brian-counters
"
:
{},
"
brian-counters
"
:
{},
"
error-counters
"
:
{},
"
error-counters
"
:
{},
}
}
cli
.
main
(
config
,
"
router1
"
,
Vendor
.
JUNIPER
)
cli
.
main
(
config
,
"
mx1.ams.nl.geant.net
"
,
Vendor
.
JUNIPER
)
assert
process_router
.
call_args
[
1
][
"
interfaces
"
]
==
[
"
ifc1
"
,
"
ifc2
"
]
assert
process_router
.
call_args
[
1
][
"
interfaces
"
]
==
[
"
ifc1
"
,
"
ifc2
"
]
@patch.object
(
cli
,
"
process_router
"
)
@patch.object
(
cli
,
"
process_router
"
)
def
test_main_with_all_interfaces_no_inprov_hosts
(
def
test_main_with_all_interfaces_no_inprov_hosts
(
process_router
,
mocked_load_inventory
process_router
,
mocked_load_inventory
,
mocked_get_netconf
):
):
config
=
{
config
=
{
"
juniper
"
:
{
"
some
"
:
"
params
"
},
"
juniper
"
:
{
"
some
"
:
"
params
"
},
"
brian-counters
"
:
{},
"
brian-counters
"
:
{
"
influx
"
:
None
},
"
error-counters
"
:
{},
"
error-counters
"
:
{
"
influx
"
:
None
},
}
}
cli
.
main
(
config
,
"
router1
"
,
Vendor
.
JUNIPER
)
cli
.
main
(
config
,
"
mx1.ams.nl.geant.net
"
,
Vendor
.
JUNIPER
)
assert
process_router
.
call_args
[
1
][
"
interfaces
"
]
is
None
assert
process_router
.
call_args
[
1
][
"
interfaces
"
]
is
None
...
@@ -274,7 +276,7 @@ def test_loads_interfaces_from_endpoint(point_group, url, mocked_load_inventory)
...
@@ -274,7 +276,7 @@ def test_loads_interfaces_from_endpoint(point_group, url, mocked_load_inventory)
"
error-counters
"
:
{
"
inventory-url
"
:
"
/error/endpoint
"
},
"
error-counters
"
:
{
"
inventory-url
"
:
"
/error/endpoint
"
},
}
}
cli
.
load_interfaces
(
cli
.
load_interfaces
(
"
router1
"
,
"
mx1.ams.nl.geant.net
"
,
interfaces
=
cli
.
ALL_
,
interfaces
=
cli
.
ALL_
,
app_config_params
=
config
,
app_config_params
=
config
,
point_group
=
point_group
,
point_group
=
point_group
,
...
...
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