Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
11811d59
Commit
11811d59
authored
3 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Plain Diff
Merge branch 'update-checks' into 'master'
Update system checks Closes
#890
See merge request
!1533
parents
116effe1
89f372eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1533
Update system checks
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/project/checks.py
+10
-48
10 additions, 48 deletions
arkindex/project/checks.py
arkindex/project/tests/test_checks.py
+11
-55
11 additions, 55 deletions
arkindex/project/tests/test_checks.py
with
21 additions
and
103 deletions
arkindex/project/checks.py
+
10
−
48
View file @
11811d59
import
os.path
import
subprocess
import
yaml
from
django.core.checks
import
Error
,
Warning
,
register
...
...
@@ -44,56 +43,18 @@ def local_imageserver_check(*args, **kwargs):
"""
from
django.conf
import
settings
from
arkindex.images.models
import
ImageServer
errors
=
[]
local_id
=
settings
.
LOCAL_IMAGESERVER_ID
try
:
ImageServer
.
objects
.
get
(
id
=
local_id
)
except
ImageServer
.
DoesNotExist
:
errors
.
append
(
Error
(
'
Local ImageServer with ID {} does not exist
'
.
format
(
local_id
),
hint
=
'
settings.LOCAL_IMAGESERVER_ID = {}
'
.
format
(
local_id
),
id
=
'
arkindex.E004
'
,
))
return
errors
@register
()
def
docker_images_check
(
*
args
,
**
kwargs
):
"""
Check that the Arkindex backend and ML images exist
"""
from
django.conf
import
settings
errors
=
[]
if
settings
.
PONOS_RECIPE
is
None
:
# In a Ponos task
return
[]
images
=
(
(
settings
.
ARKINDEX_TASKS_IMAGE
,
'
ARKINDEX_TASKS_IMAGE
'
),
)
for
image_tag
,
setting_name
in
images
:
try
:
subprocess
.
run
(
[
'
docker
'
,
'
image
'
,
'
inspect
'
,
image_tag
],
check
=
True
,
# Silent output
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
)
except
subprocess
.
CalledProcessError
:
errors
.
append
(
Error
(
'
Docker image with tag
"
{}
"
was not found.
'
.
format
(
image_tag
),
hint
=
'
settings.{} =
"
{}
"'
.
format
(
setting_name
,
image_tag
),
id
=
'
arkindex.E006
'
,
))
except
FileNotFoundError
:
# Docker is not available, ignore check
pass
return
[
Warning
(
f
'
Local ImageServer with ID
{
local_id
}
does not exist
'
,
hint
=
f
'
settings.LOCAL_IMAGESERVER_ID =
{
local_id
}
'
,
id
=
'
arkindex.W009
'
,
)]
return
errors
return
[]
@register
()
...
...
@@ -176,14 +137,15 @@ def s3_check(*args, **kwargs):
'
AWS_SECRET_KEY
'
:
'
AWS secret key
'
,
'
AWS_THUMBNAIL_BUCKET
'
:
'
S3 thumbnails bucket name
'
,
'
AWS_STAGING_BUCKET
'
:
'
S3 staging bucket name
'
,
'
AWS_EXPORT_BUCKET
'
:
'
S3 export bucket name
'
,
}
errors
=
[]
for
name
,
display_name
in
aws_settings
.
items
():
value
=
getattr
(
settings
,
name
,
None
)
if
not
value
:
errors
.
append
(
Error
(
'
{} is missing; all S3-related features will fail.
'
.
format
(
display_name
)
,
hint
=
'
settings.{} = {
}
'
.
format
(
name
,
repr
(
value
))
,
f
'
{
display_name
}
is missing; all S3-related features will fail.
'
,
hint
=
f
'
settings.
{
name
}
=
{
value
!r}
'
,
id
=
'
arkindex.E011
'
,
))
...
...
@@ -198,6 +160,6 @@ def public_hostname_check(*args, **kwargs):
return
[
Warning
(
'
The public_hostname setting is missing; absolute URLs may not be correctly generated.
'
,
hint
=
'
settings.PUBLIC_HOSTNAME
'
,
id
=
'
arkindex.W00
7
'
,
id
=
'
arkindex.W00
8
'
,
)]
return
[]
This diff is collapsed.
Click to expand it.
arkindex/project/tests/test_checks.py
+
11
−
55
View file @
11811d59
import
subprocess
from
pathlib
import
Path
from
subprocess
import
CalledProcessError
from
unittest.mock
import
call
,
patch
from
unittest.mock
import
patch
from
django.conf
import
settings
from
django.core.checks
import
Error
,
Warning
...
...
@@ -47,10 +45,10 @@ class ChecksTestCase(TestCase):
with
self
.
settings
(
LOCAL_IMAGESERVER_ID
=
42
):
self
.
assertListEqual
(
local_imageserver_check
(),
[
Error
(
Warning
(
'
Local ImageServer with ID 42 does not exist
'
,
hint
=
'
settings.LOCAL_IMAGESERVER_ID = 42
'
,
id
=
'
arkindex.
E
00
4
'
,
id
=
'
arkindex.
W
00
9
'
,
),
])
...
...
@@ -61,55 +59,6 @@ class ChecksTestCase(TestCase):
srv
.
delete
()
@patch
(
'
arkindex.project.checks.subprocess.run
'
)
@override_settings
(
ARKINDEX_TASKS_IMAGE
=
'
nuh
'
,
)
def
test_docker_images_check
(
self
,
run_mock
):
from
arkindex.project.checks
import
docker_images_check
expected_calls
=
[
call
(
[
'
docker
'
,
'
image
'
,
'
inspect
'
,
'
nuh
'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
check
=
True
,
),
]
run_mock
.
side_effect
=
CalledProcessError
(
1
,
''
)
self
.
assertListEqual
(
docker_images_check
(),
[
Error
(
'
Docker image with tag
"
nuh
"
was not found.
'
,
hint
=
'
settings.ARKINDEX_TASKS_IMAGE =
"
nuh
"'
,
id
=
'
arkindex.E006
'
,
)
])
self
.
assertEqual
(
run_mock
.
call_count
,
1
)
self
.
assertEqual
(
run_mock
.
call_args_list
,
expected_calls
)
@patch
(
'
arkindex.project.checks.subprocess.run
'
)
def
test_docker_images_check_missing_client
(
self
,
run_mock
):
"""
Test the Docker images check does not show errors if the Docker client is missing
"""
from
arkindex.project.checks
import
docker_images_check
run_mock
.
side_effect
=
FileNotFoundError
with
self
.
settings
(
ARKINDEX_APP_IMAGE
=
'
nope
'
,
ARKINDEX_TASKS_IMAGE
=
'
nuh
'
):
self
.
assertListEqual
(
docker_images_check
(),
[])
self
.
assertEqual
(
run_mock
.
call_count
,
1
)
self
.
assertEqual
(
run_mock
.
call_args_list
,
[
call
(
[
'
docker
'
,
'
image
'
,
'
inspect
'
,
'
nuh
'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
check
=
True
,
),
])
@override_settings
()
@patch
(
'
arkindex.project.checks.parse_recipe
'
)
def
test_ponos_recipe_check
(
self
,
parse_mock
):
...
...
@@ -180,6 +129,7 @@ class ChecksTestCase(TestCase):
del
settings
.
AWS_SECRET_KEY
del
settings
.
AWS_THUMBNAIL_BUCKET
del
settings
.
AWS_STAGING_BUCKET
del
settings
.
AWS_EXPORT_BUCKET
self
.
assertCountEqual
(
s3_check
(),
[
Error
(
'
AWS access key ID is missing; all S3-related features will fail.
'
,
...
...
@@ -201,12 +151,18 @@ class ChecksTestCase(TestCase):
hint
=
'
settings.AWS_STAGING_BUCKET = None
'
,
id
=
'
arkindex.E011
'
,
),
Error
(
'
S3 export bucket name is missing; all S3-related features will fail.
'
,
hint
=
'
settings.AWS_EXPORT_BUCKET = None
'
,
id
=
'
arkindex.E011
'
,
),
])
settings
.
AWS_ACCESS_KEY
=
'
key
'
settings
.
AWS_SECRET_KEY
=
'
s3kr3t
'
settings
.
AWS_THUMBNAIL_BUCKET
=
'
Thumbs.db
'
settings
.
AWS_STAGING_BUCKET
=
'
buckette
'
settings
.
AWS_EXPORT_BUCKET
=
'
devnull
'
self
.
assertListEqual
(
s3_check
(),
[])
@override_settings
()
...
...
@@ -218,7 +174,7 @@ class ChecksTestCase(TestCase):
Warning
(
'
The public_hostname setting is missing; absolute URLs may not be correctly generated.
'
,
hint
=
'
settings.PUBLIC_HOSTNAME
'
,
id
=
'
arkindex.W00
7
'
,
id
=
'
arkindex.W00
8
'
,
)
])
...
...
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