Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
4ed20e7a
Commit
4ed20e7a
authored
May 28, 2021
by
Markus Scheidgen
Browse files
Merge branch 'bugfixes' into 'v0.10.4'
Added tasks_status parameters to uploads reset CLI command. See merge request
!347
parents
11663f16
ad793848
Pipeline
#102428
passed with stages
in 24 minutes and 12 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nomad/cli/admin/uploads.py
View file @
4ed20e7a
...
...
@@ -267,8 +267,10 @@ def chown(ctx, username, uploads):
@
uploads
.
command
(
help
=
'Reset the processing state.'
)
@
click
.
argument
(
'UPLOADS'
,
nargs
=-
1
)
@
click
.
option
(
'--with-calcs'
,
is_flag
=
True
,
help
=
'Also reset all calculations.'
)
@
click
.
option
(
'--success'
,
is_flag
=
True
,
help
=
'Set the tasks status to success instead of pending'
)
@
click
.
option
(
'--failure'
,
is_flag
=
True
,
help
=
'Set the tasks status to failure instead of pending.'
)
@
click
.
pass_context
def
reset
(
ctx
,
uploads
,
with_calcs
):
def
reset
(
ctx
,
uploads
,
with_calcs
,
success
,
failure
):
_
,
uploads
=
query_uploads
(
ctx
,
uploads
)
uploads_count
=
uploads
.
count
()
...
...
@@ -276,12 +278,22 @@ def reset(ctx, uploads, with_calcs):
i
=
0
for
upload
in
uploads
:
proc
.
Calc
.
_get_collection
().
update_many
(
dict
(
upload_id
=
upload
.
upload_id
),
{
'$set'
:
proc
.
Calc
.
reset_pymongo_update
()})
if
with_calcs
:
calc_update
=
proc
.
Calc
.
reset_pymongo_update
()
if
success
:
calc_update
[
'tasks_status'
]
=
proc
.
SUCCESS
if
failure
:
calc_update
[
'tasks_status'
]
=
proc
.
FAILURE
proc
.
Calc
.
_get_collection
().
update_many
(
dict
(
upload_id
=
upload
.
upload_id
),
{
'$set'
:
calc_update
})
upload
.
process_status
=
None
upload
.
reset
()
if
success
:
upload
.
tasks_status
=
proc
.
SUCCESS
if
failure
:
upload
.
tasks_status
=
proc
.
FAILURE
upload
.
save
()
i
+=
1
print
(
'resetted %d of %d uploads'
%
(
i
,
uploads_count
))
...
...
tests/test_cli.py
View file @
4ed20e7a
...
...
@@ -307,19 +307,39 @@ class TestAdminUploads:
perform_test
(
True
,
False
)
perform_test
(
True
,
True
)
def
test_reset
(
self
,
non_empty_processed
):
@
pytest
.
mark
.
parametrize
(
'with_calcs,success,failure'
,
[
(
True
,
False
,
False
),
(
False
,
False
,
False
),
(
True
,
True
,
False
),
(
False
,
False
,
True
)])
def
test_reset
(
self
,
non_empty_processed
,
with_calcs
,
success
,
failure
):
upload_id
=
non_empty_processed
.
upload_id
result
=
click
.
testing
.
CliRunner
().
invoke
(
cli
,
[
'admin'
,
'uploads'
,
'reset'
,
'--with-calcs'
,
upload_id
],
catch_exceptions
=
False
)
upload
=
Upload
.
objects
(
upload_id
=
upload_id
).
first
()
calc
=
Calc
.
objects
(
upload_id
=
upload_id
).
first
()
assert
upload
.
tasks_status
==
proc
.
SUCCESS
assert
calc
.
tasks_status
==
proc
.
SUCCESS
args
=
[
'admin'
,
'uploads'
,
'reset'
]
if
with_calcs
:
args
.
append
(
'--with-calcs'
)
if
success
:
args
.
append
(
'--success'
)
if
failure
:
args
.
append
(
'--failure'
)
args
.
append
(
upload_id
)
result
=
click
.
testing
.
CliRunner
().
invoke
(
cli
,
args
,
catch_exceptions
=
False
)
assert
result
.
exit_code
==
0
assert
'reset'
in
result
.
stdout
upload
=
Upload
.
objects
(
upload_id
=
upload_id
).
first
()
calc
=
Calc
.
objects
(
upload_id
=
upload_id
).
first
()
assert
upload
.
tasks_status
==
proc
.
PENDING
assert
calc
.
tasks_status
==
proc
.
PENDING
expected_state
=
proc
.
PENDING
if
success
:
expected_state
=
proc
.
SUCCESS
if
failure
:
expected_state
=
proc
.
FAILURE
assert
upload
.
tasks_status
==
expected_state
if
not
with_calcs
:
assert
calc
.
tasks_status
==
proc
.
SUCCESS
else
:
assert
calc
.
tasks_status
==
expected_state
@
pytest
.
mark
.
usefixtures
(
'reset_config'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment