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
fb6f53aa
Verified
Commit
fb6f53aa
authored
6 months ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Set container name when running Ponos tasks via RQ
parent
0272d42f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2439
Set container name when running Ponos tasks via RQ
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/ponos/tasks.py
+10
-0
10 additions, 0 deletions
arkindex/ponos/tasks.py
arkindex/ponos/tests/test_rq_tasks.py
+31
-0
31 additions, 0 deletions
arkindex/ponos/tests/test_rq_tasks.py
with
41 additions
and
0 deletions
arkindex/ponos/tasks.py
+
10
−
0
View file @
fb6f53aa
...
...
@@ -162,6 +162,15 @@ def run_docker_task(client, task, temp_dir):
return
# 4. Do run the container asynchronously
container_name
=
f
"
ponos-
{
task
.
id
}
"
try
:
client
.
containers
.
get
(
container_name
)
except
docker
.
errors
.
NotFound
:
# No container exists with the name, carry on
pass
else
:
raise
ValueError
(
f
"
A Docker container named
{
container_name
}
already exists
"
)
logger
.
debug
(
"
Running container
"
)
kwargs
=
{
"
environment
"
:
{
...
...
@@ -171,6 +180,7 @@ def run_docker_task(client, task, temp_dir):
"
detach
"
:
True
,
"
network
"
:
"
host
"
,
"
volumes
"
:
{
str
(
temp_dir
):
{
"
bind
"
:
str
(
settings
.
PONOS_DATA_DIR
),
"
mode
"
:
"
rw
"
}},
"
name
"
:
container_name
,
}
artifacts_dir
=
temp_dir
/
str
(
task
.
id
)
artifacts_dir
.
mkdir
()
...
...
This diff is collapsed.
Click to expand it.
arkindex/ponos/tests/test_rq_tasks.py
+
31
−
0
View file @
fb6f53aa
...
...
@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, PropertyMock, call, patch, seal
from
django.test
import
override_settings
import
docker
from
arkindex.ponos.models
import
Farm
,
State
,
Task
from
arkindex.ponos.tasks
import
run_docker_task
from
arkindex.process.models
import
ProcessMode
,
WorkerVersion
...
...
@@ -97,6 +98,7 @@ class TestModels(FixtureAPITestCase):
seal
(
sleep_mock
)
client_mock
.
images
.
pull
.
return_value
=
None
client_mock
.
containers
.
get
.
side_effect
=
docker
.
errors
.
NotFound
(
"
Not found.
"
)
container
.
reload
.
return_value
=
None
container
.
stop
.
return_value
=
None
# Sealing is not friendly with PropertyMocks, so we put a placeholder first
...
...
@@ -120,6 +122,8 @@ class TestModels(FixtureAPITestCase):
self
.
assertEqual
(
client_mock
.
images
.
pull
.
call_count
,
1
)
self
.
assertEqual
(
client_mock
.
images
.
pull
.
call_args
,
call
(
"
image
"
))
self
.
assertEqual
(
client_mock
.
containers
.
get
.
call_count
,
1
)
self
.
assertEqual
(
client_mock
.
containers
.
get
.
call_args
,
call
(
f
"
ponos-
{
task
.
id
}
"
))
self
.
assertEqual
(
client_mock
.
containers
.
run
.
call_count
,
1
)
self
.
assertEqual
(
client_mock
.
containers
.
run
.
call_args
,
call
(
"
image
"
,
...
...
@@ -127,6 +131,7 @@ class TestModels(FixtureAPITestCase):
detach
=
True
,
network
=
"
host
"
,
volumes
=
{
temp_dir
:
{
"
bind
"
:
"
/data
"
,
"
mode
"
:
"
rw
"
}},
name
=
f
"
ponos-
{
task
.
id
}
"
,
))
self
.
assertEqual
(
container
.
reload
.
call_count
,
2
)
...
...
@@ -141,3 +146,29 @@ class TestModels(FixtureAPITestCase):
self
.
assertEqual
(
sleep_mock
.
call_count
,
1
)
self
.
assertEqual
(
sleep_mock
.
call_args
,
call
(
1
))
@override_settings
(
PONOS_RQ_EXECUTION
=
True
)
def
test_run_docker_task_conflict
(
self
):
task
=
self
.
process
.
tasks
.
create
(
slug
=
"
something
"
,
image
=
"
image
"
,
run
=
0
,
depth
=
0
,
state
=
State
.
Pending
,
)
client_mock
=
MagicMock
()
client_mock
.
images
.
pull
.
return_value
=
None
client_mock
.
containers
.
get
.
return_value
=
None
seal
(
client_mock
)
with
(
tempfile
.
TemporaryDirectory
()
as
temp_dir
,
self
.
assertRaisesMessage
(
ValueError
,
f
"
A Docker container named ponos-
{
task
.
id
}
already exists
"
),
):
run_docker_task
(
client_mock
,
task
,
Path
(
temp_dir
))
self
.
assertEqual
(
client_mock
.
images
.
pull
.
call_count
,
1
)
self
.
assertEqual
(
client_mock
.
images
.
pull
.
call_args
,
call
(
"
image
"
))
self
.
assertEqual
(
client_mock
.
containers
.
get
.
call_count
,
1
)
self
.
assertEqual
(
client_mock
.
containers
.
get
.
call_args
,
call
(
f
"
ponos-
{
task
.
id
}
"
))
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