Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Autocnet
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Autocnet
Commits
b2e9f2e5
Commit
b2e9f2e5
authored
Dec 6, 2021
by
Gavin
Browse files
Options
Downloads
Patches
Plain Diff
updated matcher module to use logging rather then warnings
parent
dd77e5eb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
autocnet/graph/cluster_submit.py
+11
-4
11 additions, 4 deletions
autocnet/graph/cluster_submit.py
autocnet/graph/tests/test_cluster_submit.py
+13
-3
13 additions, 3 deletions
autocnet/graph/tests/test_cluster_submit.py
with
24 additions
and
7 deletions
autocnet/graph/cluster_submit.py
+
11
−
4
View file @
b2e9f2e5
...
@@ -5,7 +5,7 @@ import copy
...
@@ -5,7 +5,7 @@ import copy
import
os
import
os
import
json
import
json
import
sys
import
sys
import
warn
ing
s
import
logg
ing
from
io
import
StringIO
from
io
import
StringIO
from
contextlib
import
redirect_stdout
from
contextlib
import
redirect_stdout
...
@@ -20,6 +20,9 @@ from autocnet.utils.utils import import_func
...
@@ -20,6 +20,9 @@ from autocnet.utils.utils import import_func
from
autocnet.utils.serializers
import
JsonEncoder
,
object_hook
from
autocnet.utils.serializers
import
JsonEncoder
,
object_hook
from
autocnet.io.db.model
import
JobsHistory
from
autocnet.io.db.model
import
JobsHistory
# set up the logging file
log
=
logging
.
getLogger
(
__name__
)
def
parse_args
():
# pragma: no cover
def
parse_args
():
# pragma: no cover
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
-r
'
,
'
--host
'
,
help
=
'
The host URL for the redis queue to to pull messages from.
'
)
parser
.
add_argument
(
'
-r
'
,
'
--host
'
,
help
=
'
The host URL for the redis queue to to pull messages from.
'
)
...
@@ -178,7 +181,7 @@ def manage_messages(args, queue):
...
@@ -178,7 +181,7 @@ def manage_messages(args, queue):
if
msg
is
None
:
if
msg
is
None
:
if
args
[
'
queue
'
]
==
False
:
if
args
[
'
queue
'
]
==
False
:
warning
s
.
warn
(
'
Expected to process a cluster job, but the message queue is empty.
'
)
log
.
warning
(
'
Expected to process a cluster job, but the message queue is empty.
'
)
return
return
elif
args
[
'
queue
'
]
==
True
:
elif
args
[
'
queue
'
]
==
True
:
print
(
f
'
Completed processing from queue:
{
queue
}
.
'
)
print
(
f
'
Completed processing from queue:
{
queue
}
.
'
)
...
@@ -197,8 +200,9 @@ def manage_messages(args, queue):
...
@@ -197,8 +200,9 @@ def manage_messages(args, queue):
with
redirect_stdout
(
stdout
):
with
redirect_stdout
(
stdout
):
# Apply the algorithm
# Apply the algorithm
response
=
process
(
msgdict
)
response
=
process
(
msgdict
)
# Should go to a logger someday!
# Should go to a logger someday! (today is that day!)
print
(
response
)
log
.
info
(
response
)
out
=
stdout
.
getvalue
()
out
=
stdout
.
getvalue
()
# print to get everything on the logs in the directory
# print to get everything on the logs in the directory
...
@@ -226,6 +230,9 @@ def manage_messages(args, queue):
...
@@ -226,6 +230,9 @@ def manage_messages(args, queue):
def
main
():
# pragma: no cover
def
main
():
# pragma: no cover
args
=
vars
(
parse_args
())
args
=
vars
(
parse_args
())
# set up the logger
logging
.
basicConfig
(
level
=
os
.
environ
.
get
(
"
autocnet_loglevel
"
,
"
INFO
"
))
log
.
error
(
"
hello
"
)
# Get the message
# Get the message
queue
=
StrictRedis
(
host
=
args
[
'
host
'
],
port
=
args
[
'
port
'
],
db
=
0
)
queue
=
StrictRedis
(
host
=
args
[
'
host
'
],
port
=
args
[
'
port
'
],
db
=
0
)
manage_messages
(
args
,
queue
)
manage_messages
(
args
,
queue
)
...
...
This diff is collapsed.
Click to expand it.
autocnet/graph/tests/test_cluster_submit.py
+
13
−
3
View file @
b2e9f2e5
...
@@ -5,6 +5,7 @@ from unittest.mock import patch
...
@@ -5,6 +5,7 @@ from unittest.mock import patch
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
import
logging
from
autocnet.utils.serializers
import
JsonEncoder
,
object_hook
from
autocnet.utils.serializers
import
JsonEncoder
,
object_hook
from
autocnet.graph
import
cluster_submit
from
autocnet.graph
import
cluster_submit
...
@@ -12,6 +13,7 @@ from autocnet.graph.node import NetworkNode
...
@@ -12,6 +13,7 @@ from autocnet.graph.node import NetworkNode
from
autocnet.graph.edge
import
NetworkEdge
from
autocnet.graph.edge
import
NetworkEdge
from
autocnet.io.db.model
import
Points
,
JobsHistory
from
autocnet.io.db.model
import
Points
,
JobsHistory
log
=
logging
.
getLogger
(
__name__
)
@pytest.fixture
@pytest.fixture
def
args
():
def
args
():
...
@@ -102,9 +104,11 @@ def test_finalize_message_from_work_queue(args, queue, simple_message):
...
@@ -102,9 +104,11 @@ def test_finalize_message_from_work_queue(args, queue, simple_message):
cluster_submit
.
finalize_message_from_work_queue
(
queue
,
args
[
'
working_queue
'
],
remove_key
)
cluster_submit
.
finalize_message_from_work_queue
(
queue
,
args
[
'
working_queue
'
],
remove_key
)
assert
queue
.
llen
(
args
[
'
working_queue
'
])
==
0
assert
queue
.
llen
(
args
[
'
working_queue
'
])
==
0
def
test_no_msg
(
args
,
queue
):
def
test_no_msg
(
caplog
,
args
,
queue
):
with
pytest
.
warns
(
UserWarning
,
match
=
'
Expected to process a cluster job, but the message queue is empty.
'
):
cluster_submit
.
manage_messages
(
args
,
queue
)
cluster_submit
.
manage_messages
(
args
,
queue
)
expected_log
=
'
Expected to process a cluster job, but the message queue is empty.
'
assert
expected_log
in
caplog
.
text
# Classes and funcs for testing job submission.
# Classes and funcs for testing job submission.
...
@@ -167,6 +171,11 @@ def test_process_row(along, func, msg_additions, mocker):
...
@@ -167,6 +171,11 @@ def test_process_row(along, func, msg_additions, mocker):
cluster_submit
.
_instantiate_row
.
assert_called_once
()
cluster_submit
.
_instantiate_row
.
assert_called_once
()
@pytest.mark.parametrize
()
def
_do_something
():
log
.
debug
(
"
Doing something!
"
)
log
.
info
(
"
This is some info
"
)
@pytest.mark.parametrize
(
"
along, func, msg_additions
"
,[
@pytest.mark.parametrize
(
"
along, func, msg_additions
"
,[
([
1
,
2
,
3
,
4
,
5
],
_do_nothing
,
{})
([
1
,
2
,
3
,
4
,
5
],
_do_nothing
,
{})
])
])
...
@@ -181,6 +190,7 @@ def test_process_generic(along, func, msg_additions, mocker):
...
@@ -181,6 +190,7 @@ def test_process_generic(along, func, msg_additions, mocker):
mocker
.
patch
(
'
autocnet.graph.cluster_submit._instantiate_obj
'
,
side_effect
=
_generate_obj
)
mocker
.
patch
(
'
autocnet.graph.cluster_submit._instantiate_obj
'
,
side_effect
=
_generate_obj
)
mocker
.
patch
(
'
autocnet.graph.network.NetworkCandidateGraph.Session
'
,
return_value
=
True
)
mocker
.
patch
(
'
autocnet.graph.network.NetworkCandidateGraph.Session
'
,
return_value
=
True
)
mocker
.
patch
(
'
autocnet.graph.network.NetworkCandidateGraph.config_from_dict
'
)
mocker
.
patch
(
'
autocnet.graph.network.NetworkCandidateGraph.config_from_dict
'
)
_do_something
()
assert
not
cluster_submit
.
_instantiate_row
.
called
assert
not
cluster_submit
.
_instantiate_row
.
called
assert
not
cluster_submit
.
_instantiate_obj
.
called
assert
not
cluster_submit
.
_instantiate_obj
.
called
...
...
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