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
4af1db83
Commit
4af1db83
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added an end-to-end cli flash test, bugfixes
parent
8efb4b1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
brian_polling_manager/cli.py
+9
-7
9 additions, 7 deletions
brian_polling_manager/cli.py
test/conftest.py
+9
-1
9 additions, 1 deletion
test/conftest.py
test/test_e2e.py
+22
-0
22 additions, 0 deletions
test/test_e2e.py
with
40 additions
and
8 deletions
brian_polling_manager/cli.py
+
9
−
7
View file @
4af1db83
import
json
import
logging
import
os
from
typing
import
Union
import
click
import
jsonschema
...
...
@@ -131,10 +132,13 @@ class State(object):
return
state
[
'
last
'
]
if
state
else
-
1
@last.setter
def
last
(
self
,
new_last
:
float
):
state
=
{
'
last
'
:
new_last
}
with
open
(
self
.
filenames
[
'
state
'
],
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
state
))
def
last
(
self
,
new_last
:
Union
[
float
,
None
]):
if
not
new_last
or
new_last
<
0
:
os
.
unlink
(
self
.
filenames
[
'
state
'
])
else
:
state
=
{
'
last
'
:
new_last
}
with
open
(
self
.
filenames
[
'
state
'
],
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
state
))
@property
def
interfaces
(
self
)
->
list
:
...
...
@@ -178,8 +182,6 @@ def _validate_config(ctx, param, value):
return
config
@click.command
()
@click.option
(
'
--config
'
,
...
...
@@ -195,7 +197,7 @@ def main(config, force):
state
=
State
(
config
[
'
statedir
'
])
last
=
inventory
.
last_update_timestamp
(
config
[
'
inventory
'
])
if
force
or
last
!=
state
.
last
:
if
force
or
not
last
or
last
!=
state
.
last
:
state
.
last
=
last
state
.
interfaces
=
inventory
.
load_interfaces
(
config
[
'
inventory
'
])
...
...
This diff is collapsed.
Click to expand it.
test/conftest.py
+
9
−
1
View file @
4af1db83
import
json
import
os
import
random
import
re
import
tempfile
...
...
@@ -87,7 +88,7 @@ def mocked_sensu():
responses
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r
'
.*sensu.+/api/core/v2/namespaces/[^\/]+/checks$
'
),
body
=
json
.
dumps
(
list
(
saved_sensu_checks
.
item
s
())
)
json
=
list
(
saved_sensu_checks
.
value
s
())
)
def
new_check_callback
(
request
):
...
...
@@ -138,6 +139,7 @@ def mocked_sensu():
yield
saved_sensu_checks
@pytest.fixture
def
mocked_inventory
():
...
...
@@ -147,3 +149,9 @@ def mocked_inventory():
url
=
re
.
compile
(
r
'
.*inventory.+/poller/interfaces.*
'
),
body
=
_load_test_data
(
'
interfaces.json
'
))
bogus_version
=
{
'
latch
'
:
{
'
timestamp
'
:
10000
*
random
.
random
()}}
# mocked api for returning all checks
responses
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r
'
.*inventory.+/version.*
'
),
body
=
json
.
dumps
(
bogus_version
))
This diff is collapsed.
Click to expand it.
test/test_e2e.py
0 → 100644
+
22
−
0
View file @
4af1db83
import
json
import
tempfile
from
click.testing
import
CliRunner
import
responses
from
brian_polling_manager
import
cli
@responses.activate
def
test_run_flashtest
(
config
,
mocked_sensu
,
mocked_inventory
):
with
tempfile
.
NamedTemporaryFile
(
mode
=
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
config
))
f
.
flush
()
runner
=
CliRunner
()
result
=
runner
.
invoke
(
cli
.
main
,
[
'
--config
'
,
f
.
name
,
'
--force
'
]
)
assert
result
.
exit_code
==
0
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