Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
cf3b3274
Commit
cf3b3274
authored
3 years ago
by
Robert Rosca
Browse files
Options
Downloads
Patches
Plain Diff
Implement, raise, and catch, migration errors to send mdc messages
parent
f88c96d9
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
tests/test_webservice.py
+38
-2
38 additions, 2 deletions
tests/test_webservice.py
webservice/messages.py
+31
-0
31 additions, 0 deletions
webservice/messages.py
webservice/webservice.py
+25
-13
25 additions, 13 deletions
webservice/webservice.py
with
94 additions
and
15 deletions
tests/test_webservice.py
+
38
−
2
View file @
cf3b3274
...
...
@@ -2,6 +2,7 @@ import os
import
sys
from
pathlib
import
Path
from
unittest
import
mock
from
webservice.messages
import
MigrationError
import
pytest
from
testpath
import
MockCommand
...
...
@@ -81,8 +82,8 @@ def test_parse_config():
"
xattr_list, xattr_get, expected_result
"
,
[
([
"
user.status
"
],
b
"
offline
"
,
True
),
([
"
user.status
"
],
b
"
notmigrated2d2
"
,
Fals
e
),
([
],
b
""
,
Fals
e
),
([
"
user.status
"
],
b
"
tape
"
,
Tru
e
),
([
"
user.status
"
],
b
"
dCache
"
,
Tru
e
),
],
)
async
def
test_wait_on_transfer
(
xattr_list
,
xattr_get
,
expected_result
,
tmp_path
):
...
...
@@ -96,6 +97,41 @@ async def test_wait_on_transfer(xattr_list, xattr_get, expected_result, tmp_path
)
assert
res
is
expected_result
@pytest.mark.asyncio
@pytest.mark.parametrize
(
"
xattr_list, xattr_get, exception_match
"
,
[
([],
b
""
,
r
"
FAILED:.*user.status.*
"
),
([
"
user.status
"
],
b
"
notmigrated2d2
"
,
r
"
FAILED:.*notmigratedr2d2.*
"
),
([
"
user.status
"
],
b
"
foobar
"
,
r
"
FAILED:.*unknown.*
"
),
],
)
async
def
test_wait_on_transfer_exceptions
(
xattr_list
,
xattr_get
,
exception_match
,
tmp_path
):
with
mock
.
patch
.
object
(
os
,
"
listxattr
"
,
lambda
path
:
xattr_list
):
with
mock
.
patch
.
object
(
os
,
"
getxattr
"
,
lambda
path
,
attr
:
xattr_get
):
with
pytest
.
raises
(
MigrationError
,
match
=
exception_match
):
await
wait_on_transfer
(
str
(
tmp_path
),
max_tries_completion
=
1
,
max_tries_attributes
=
1
,
sleep_attributes
=
1
,
)
@pytest.mark.asyncio
async
def
test_wait_on_transfer_timeout
(
tmp_path
):
with
mock
.
patch
.
object
(
os
,
"
listxattr
"
,
lambda
path
:
[
"
user.status
"
]):
with
mock
.
patch
.
object
(
os
,
"
getxattr
"
,
lambda
path
,
attr
:
b
"
migration_in_progress
"
):
with
pytest
.
raises
(
MigrationError
,
match
=
r
"
FAILED:.*progress.*
"
):
await
wait_on_transfer
(
str
(
tmp_path
),
max_tries_completion
=
1
,
max_tries_attributes
=
1
,
sleep_attributes
=
1
,
)
@pytest.mark.asyncio
@pytest.mark.parametrize
(
...
...
This diff is collapsed.
Click to expand it.
webservice/messages.py
+
31
−
0
View file @
cf3b3274
...
...
@@ -16,6 +16,37 @@ class Errors:
OTHER_ERROR
=
"
FAILED: Error {}, please contact det-support@xfel.eu
"
class
MigrationError
(
Exception
):
@classmethod
def
no_user_status_xattr
(
cls
,
run_path
:
str
):
return
cls
(
f
"
FAILED: migration issue for run `
{
run_path
}
`: `user.status` xattr not
"
f
"
present after 5 minutes, migration may have failed, manually restarting
"
f
"
migration may help
"
)
@classmethod
def
migration_failed
(
cls
,
run_path
:
str
):
return
cls
(
f
"
FAILED: migration issue for run `
{
run_path
}
`: migration marked as failed
"
f
"
(`run user.status` set to `notmigratedr2d2`), manually restarting
"
f
"
migration may help
"
)
@classmethod
def
unknown_user_status
(
cls
,
run_path
:
str
,
status
:
str
):
return
cls
(
f
"
FAILED: migration issue for run `
{
run_path
}
`: run has an unknown
"
f
"
`user.status` xattr `
{
status
}
`, manually restarting migration may help
"
)
@classmethod
def
timeout
(
cls
,
run_path
:
str
,
time
:
str
):
return
cls
(
f
"
FAILED: migration issue for run `
{
run_path
}
`: migration still marked as
"
f
"
in progress after
{
time
}
, manually restarting migration may help
"
)
class
MDC
:
MIGRATION_TIMEOUT
=
"
Timeout waiting for migration. Contact it-support@xfel.eu
"
NOTHING_TO_DO
=
"
Nothing to calibrate for this run, copied raw data only
"
...
...
This diff is collapsed.
Click to expand it.
webservice/webservice.py
+
25
−
13
View file @
cf3b3274
...
...
@@ -33,9 +33,9 @@ from metadata_client.metadata_client import MetadataClient
from
.config
import
webservice
as
config
try
:
from
.messages
import
MDC
,
Errors
,
Success
from
.messages
import
MDC
,
Errors
,
Success
,
MigrationError
except
ImportError
:
from
messages
import
MDC
,
Errors
,
Success
from
messages
import
MDC
,
Errors
,
Success
,
MigrationError
def
init_job_db
(
config
):
...
...
@@ -568,7 +568,7 @@ async def wait_on_transfer(
"
Migration may have failed, try triggering migration manually again.
"
)
# TODO: automatically re-trigger migration...?
r
eturn
False
r
aise
MigrationError
.
no_user_status_xattr
(
run_path
)
tries_for_attributes
+=
1
logging
.
warning
(
...
...
@@ -586,12 +586,16 @@ async def wait_on_transfer(
return
True
elif
user_status
==
"
notmigrated2d2
"
:
logging
.
critical
(
f
"
Migration failed for
{
run_path
}
"
)
r
eturn
False
r
aise
MigrationError
.
migration_failed
(
run_path
)
elif
user_status
!=
"
migration_in_progress
"
:
logging
.
critical
(
"
Unknown status: {user_status}
"
)
if
tries_for_completion
>
max_tries_completion
:
raise
MigrationError
.
unknown_user_status
(
run_path
,
user_status
)
if
tries_for_completion
>
max_tries_completion
:
return
False
raise
MigrationError
.
timeout
(
run_path
,
f
"
{
tries_for_completion
*
sleep_completion
}
s
"
)
tries_for_completion
+=
1
await
asyncio
.
sleep
(
sleep_completion
)
...
...
@@ -903,6 +907,10 @@ class ActionsServer:
detectors
[
karabo_id
]
=
thisconf
copy_file_list
=
copy_file_list
.
difference
(
corr_file_list
)
asyncio
.
ensure_future
(
copy_untouched_files
(
copy_file_list
))
except
MigrationError
as
e
:
logging
.
error
(
"
Migration issue
"
,
exc_info
=
e
)
await
update_mdc_status
(
self
.
mdc
,
'
correct
'
,
rid
,
str
(
e
))
return
except
Exception
as
corr_e
:
logging
.
error
(
"
Error during correction
"
,
exc_info
=
corr_e
)
await
update_mdc_status
(
self
.
mdc
,
'
correct
'
,
rid
,
...
...
@@ -985,15 +993,19 @@ class ActionsServer:
async
def
_continue
():
"""
Runs in the background after we reply to the
'
dark_request
'
request
"""
await
update_mdc_status
(
self
.
mdc
,
'
dark_request
'
,
rid
,
queued_msg
)
transfer_complete
=
await
wait_transfers
(
runs
,
in_folder
,
proposal
)
if
not
transfer_complete
:
# Timed out
await
update_mdc_status
(
self
.
mdc
,
'
dark_request
'
,
rid
,
MDC
.
MIGRATION_TIMEOUT
try
:
transfer_complete
=
await
wait_transfers
(
runs
,
in_folder
,
proposal
)
if
not
transfer_complete
:
# Timed out
await
update_mdc_status
(
self
.
mdc
,
'
dark_request
'
,
rid
,
MDC
.
MIGRATION_TIMEOUT
)
return
except
MigrationError
as
e
:
logging
.
error
(
"
Migration issue
"
,
exc_info
=
e
)
await
update_mdc_status
(
self
.
mdc
,
'
dark_request
'
,
rid
,
str
(
e
))
return
# Notebooks require one or three runs, depending on the
...
...
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