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
905a4a66
Commit
905a4a66
authored
1 year ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
more polish and update gitignore
parent
772b004e
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
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
test/error_report/test_error_report.py
+15
-17
15 additions, 17 deletions
test/error_report/test_error_report.py
with
17 additions
and
18 deletions
.gitignore
+
2
−
1
View file @
905a4a66
...
@@ -6,4 +6,5 @@ coverage.xml
...
@@ -6,4 +6,5 @@ coverage.xml
.coverage
.coverage
htmlcov
htmlcov
docs/build
docs/build
*.log
*.log
\ No newline at end of file
dist/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/error_report/test_error_report.py
+
15
−
17
View file @
905a4a66
...
@@ -5,7 +5,6 @@ import json
...
@@ -5,7 +5,6 @@ import json
import
pathlib
import
pathlib
import
smtplib
import
smtplib
from
unittest.mock
import
Mock
,
patch
,
call
from
unittest.mock
import
Mock
,
patch
,
call
import
brian_polling_manager.error_report.report
from
brian_polling_manager.error_report.report
import
(
from
brian_polling_manager.error_report.report
import
(
SMTP_TIMEOUT_SECONDS
,
SMTP_TIMEOUT_SECONDS
,
render_email
,
render_email
,
...
@@ -33,12 +32,6 @@ from click.testing import CliRunner
...
@@ -33,12 +32,6 @@ from click.testing import CliRunner
DATA_DIR
=
pathlib
.
Path
(
__file__
).
parent
/
"
data
"
DATA_DIR
=
pathlib
.
Path
(
__file__
).
parent
/
"
data
"
@pytest.fixture
(
autouse
=
True
)
def
mock_setup_logging
():
with
patch
.
object
(
cli
,
"
setup_logging
"
)
as
mock
:
yield
mock
@pytest.fixture
(
scope
=
"
session
"
)
@pytest.fixture
(
scope
=
"
session
"
)
def
full_inventory
():
def
full_inventory
():
return
json
.
loads
(((
DATA_DIR
/
"
full-inventory.json
"
).
read_text
()))
return
json
.
loads
(((
DATA_DIR
/
"
full-inventory.json
"
).
read_text
()))
...
@@ -52,6 +45,10 @@ def small_inventory():
...
@@ -52,6 +45,10 @@ def small_inventory():
@pytest.fixture
@pytest.fixture
def
mock_influx_client
():
def
mock_influx_client
():
class
FakeInfluxClient
:
class
FakeInfluxClient
:
"""
Fake influx client, see `create_error_point` for usage how to set it up
"""
INFLUX_ERROR_FIELDS
=
{
v
.
replace
(
"
-
"
,
"
_
"
):
k
for
k
,
v
in
ERROR_FIELDS
.
items
()}
INFLUX_ERROR_FIELDS
=
{
v
.
replace
(
"
-
"
,
"
_
"
):
k
for
k
,
v
in
ERROR_FIELDS
.
items
()}
def
__init__
(
self
)
->
None
:
def
__init__
(
self
)
->
None
:
...
@@ -76,7 +73,9 @@ def mock_influx_client():
...
@@ -76,7 +73,9 @@ def mock_influx_client():
return
self
.
today
.
append
(
point
)
return
self
.
today
.
append
(
point
)
if
timestamp
==
"
yesterday
"
:
if
timestamp
==
"
yesterday
"
:
return
self
.
yesterday
.
append
(
point
)
return
self
.
yesterday
.
append
(
point
)
raise
ValueError
(
"'
when
'
argument must be either
'
today
'
or
'
yesterday
"
)
raise
ValueError
(
"'
timestamp
'
argument must be either
'
today
'
or
'
yesterday
'"
)
def
query
(
self
,
q
):
def
query
(
self
,
q
):
result
=
Mock
()
result
=
Mock
()
...
@@ -100,7 +99,7 @@ def create_error_point(mock_influx_client):
...
@@ -100,7 +99,7 @@ def create_error_point(mock_influx_client):
``input_crc_errors``, ``input_total_errors``,``input_discards``,``input_drops``,
``input_crc_errors``, ``input_total_errors``,``input_discards``,``input_drops``,
``output_drops``
``output_drops``
The created error points will be returned by
the
mock_influx fixture
The created error points will be returned by
``
mock_influx
_client``
fixture
"""
"""
def
_create
(
hostname
,
interface
,
timestamp
,
**
fields
):
def
_create
(
hostname
,
interface
,
timestamp
,
**
fields
):
...
@@ -114,7 +113,7 @@ def create_error_point(mock_influx_client):
...
@@ -114,7 +113,7 @@ def create_error_point(mock_influx_client):
def
get_interface_errors
(
small_inventory
,
mock_influx_client
):
def
get_interface_errors
(
small_inventory
,
mock_influx_client
):
interfaces
=
_filter_and_sort_interfaces
(
small_inventory
)
interfaces
=
_filter_and_sort_interfaces
(
small_inventory
)
def
_get
(
**
kwargs
):
def
_get
_interface_errors
(
**
kwargs
):
defaults
=
{
defaults
=
{
"
client
"
:
mock_influx_client
,
"
client
"
:
mock_influx_client
,
"
interface_info
"
:
interfaces
,
"
interface_info
"
:
interfaces
,
...
@@ -125,7 +124,7 @@ def get_interface_errors(small_inventory, mock_influx_client):
...
@@ -125,7 +124,7 @@ def get_interface_errors(small_inventory, mock_influx_client):
jsonschema
.
validate
(
result
,
PROCESSED_ERROR_COUNTERS_SCHEMA
)
jsonschema
.
validate
(
result
,
PROCESSED_ERROR_COUNTERS_SCHEMA
)
return
result
return
result
return
_get
return
_get
_interface_errors
def
test_validate_config
(
tmp_path
):
def
test_validate_config
(
tmp_path
):
...
@@ -139,6 +138,7 @@ def test_validate_config(tmp_path):
...
@@ -139,6 +138,7 @@ def test_validate_config(tmp_path):
"
hostname
"
:
"
some.smtp.server
"
,
"
hostname
"
:
"
some.smtp.server
"
,
"
username
"
:
"
smtp-user
"
,
"
username
"
:
"
smtp-user
"
,
"
password
"
:
"
smtp-password
"
,
"
password
"
:
"
smtp-password
"
,
"
starttls
"
:
False
,
},
},
"
inventory
"
:
[
"
blah
"
],
"
inventory
"
:
[
"
blah
"
],
"
influx
"
:
{
"
influx
"
:
{
...
@@ -384,7 +384,7 @@ def test_processes_excluded_interface(create_error_point, get_interface_errors):
...
@@ -384,7 +384,7 @@ def test_processes_excluded_interface(create_error_point, get_interface_errors):
)
)
create_error_point
(
create_error_point
(
"
mx1.fra.de.geant.net
"
,
"
ae10
"
,
"
today
"
,
input_drops
=
3
,
framing_errors
=
4
"
mx1.fra.de.geant.net
"
,
"
ae10
"
,
"
today
"
,
input_drops
=
3
,
framing_errors
=
4
)
)
# this interface is excluded through its description
errors
=
get_interface_errors
(
exclusions
=
[
"
foo
"
])
errors
=
get_interface_errors
(
exclusions
=
[
"
foo
"
])
assert
errors
[
"
interfaces
"
]
==
[
assert
errors
[
"
interfaces
"
]
==
[
...
@@ -425,7 +425,7 @@ def test_render_html(create_error_point, get_interface_errors):
...
@@ -425,7 +425,7 @@ def test_render_html(create_error_point, get_interface_errors):
create_error_point
(
"
mx1.fra.de.geant.net
"
,
"
ae10
"
,
"
today
"
,
input_drops
=
3
)
create_error_point
(
"
mx1.fra.de.geant.net
"
,
"
ae10
"
,
"
today
"
,
input_drops
=
3
)
errors
=
get_interface_errors
()
errors
=
get_interface_errors
()
result
=
render_html
(
errors
=
errors
,
date
=
"
<some date>
"
)
result
=
render_html
(
errors
=
errors
,
date
=
"
<some date>
"
)
# careful, there are tabs mixed with spaces here, but hey, we want to keep the
#
be
careful, there are tabs mixed with spaces here, but hey, we want to keep the
# output as close to the original script
# output as close to the original script
expected
=
"""
\
expected
=
"""
\
<html>
<html>
...
@@ -473,7 +473,7 @@ def test_render_html_with_exclusions(create_error_point, get_interface_errors):
...
@@ -473,7 +473,7 @@ def test_render_html_with_exclusions(create_error_point, get_interface_errors):
)
)
errors
=
get_interface_errors
(
exclusions
=
[
"
foo
"
])
errors
=
get_interface_errors
(
exclusions
=
[
"
foo
"
])
result
=
render_html
(
errors
=
errors
,
date
=
"
<some date>
"
)
result
=
render_html
(
errors
=
errors
,
date
=
"
<some date>
"
)
# careful, mixing tabs with spaces here
#
be
careful, mixing tabs with spaces here
expected
=
"""
\
expected
=
"""
\
<html>
<html>
<body>
<body>
...
@@ -632,9 +632,7 @@ def test_e2e(
...
@@ -632,9 +632,7 @@ def test_e2e(
config_file
,
config_file
,
create_error_point
,
create_error_point
,
):
):
create_error_point
(
create_error_point
(
"
mx1.ams.nl.geant.net
"
,
"
ae1
"
,
"
today
"
,
input_drops
=
1
)
"
mx1.ams.nl.geant.net
"
,
"
ae1
"
,
"
today
"
,
input_drops
=
1
)
with
patch
.
object
(
with
patch
.
object
(
cli
,
"
load_interfaces
"
,
return_value
=
small_inventory
cli
,
"
load_interfaces
"
,
return_value
=
small_inventory
...
...
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