Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.core
Commits
7adf8af0
Commit
7adf8af0
authored
Nov 30, 2020
by
André Anjos
💬
Browse files
Merge branch '106_custom_tmpfs_through_label' into 'master'
Custom tmpfs through label Closes
#106
See merge request
!133
parents
44d658b9
b61dc8db
Pipeline
#46180
passed with stages
in 17 minutes and 24 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/core/dock.py
View file @
7adf8af0
...
...
@@ -795,6 +795,17 @@ class Container:
self
.
_entrypoint
=
None
self
.
_temporary_filesystems
=
{
"/tmp"
:
"500k"
,
"/run"
:
"500k"
}
# nosec
client
=
docker
.
from_env
()
docker_image
=
client
.
images
.
get
(
image
)
custom_tmpfs
=
docker_image
.
labels
.
get
(
"beat.env.custom_tmpfs"
)
if
custom_tmpfs
is
not
None
:
# import ipdb; ipdb.set_trace()
custom_tmpfs
=
json
.
loads
(
custom_tmpfs
)
for
path
,
size
in
custom_tmpfs
.
items
():
self
.
_temporary_filesystems
[
path
]
=
size
def
set_name
(
self
,
name
):
""" Set the name to be used by the container in place of the docker
auto generated one.
...
...
beat/core/test/test_docker.py
View file @
7adf8af0
...
...
@@ -107,8 +107,7 @@ class NetworkTest(NoDiscoveryTests):
class
UserTest
(
NoDiscoveryTests
):
@
slow
def
test_user
(
self
):
"""Test that the uid property is correctly used.
"""
"""Test that the uid property is correctly used."""
container
=
self
.
host
.
create_container
(
"debian:8.4"
,
[
"id"
])
container
.
uid
=
10000
...
...
@@ -127,8 +126,7 @@ class UserTest(NoDiscoveryTests):
class
EnvironmentVariableTest
(
NoDiscoveryTests
):
@
slow
def
test_environment_variable
(
self
):
"""Test that the uid property is correctly used.
"""
"""Test that the uid property is correctly used."""
container
=
self
.
host
.
create_container
(
"debian:8.4"
,
[
"env"
])
container
.
add_environment_variable
(
"DOCKER_TEST"
,
"good"
)
...
...
@@ -143,8 +141,7 @@ class EnvironmentVariableTest(NoDiscoveryTests):
class
WorkdirTest
(
NoDiscoveryTests
):
@
slow
def
test_workdir
(
self
):
"""Test that the workdir property is correctly used.
"""
"""Test that the workdir property is correctly used."""
with
TemporaryDirectory
()
as
tmp_folder
:
test_file
=
"test.txt"
...
...
@@ -169,8 +166,7 @@ class WorkdirTest(NoDiscoveryTests):
class
EntrypointTest
(
NoDiscoveryTests
):
@
slow
def
test_entrypoint
(
self
):
"""Test that the entrypoint property is correctly used.
"""
"""Test that the entrypoint property is correctly used."""
container
=
self
.
host
.
create_container
(
"debian:8.4"
,
[
"42"
])
container
.
set_entrypoint
(
"echo"
)
...
...
@@ -187,8 +183,7 @@ class EntrypointTest(NoDiscoveryTests):
class
TmpfsTest
(
NoDiscoveryTests
):
def
test_tmpfs
(
self
):
"""Test that the tmpfs are properly mounted and usable.
"""
"""Test that the tmpfs are properly mounted and usable."""
container
=
self
.
host
.
create_container
(
"debian:8.4"
,
[
"touch"
,
"/dummy/test.txt"
]
...
...
@@ -213,33 +208,6 @@ class TmpfsTest(NoDiscoveryTests):
self
.
assertEqual
(
status
,
0
)
self
.
assertEqual
(
logs
,
""
)
def
test_tmpfs_size
(
self
):
"""Test that the tmpfs are respected.
"""
container
=
self
.
host
.
create_container
(
"debian:8.4"
,
[
"dd"
,
"if=/dev/zero"
,
"of=/dummy/test.txt"
]
)
tmpfs_list
=
container
.
temporary_filesystems
self
.
assertEqual
(
len
(
tmpfs_list
),
2
)
container
.
add_tmpfs
(
"/dummy"
,
"1M"
)
tmpfs_list
=
container
.
temporary_filesystems
self
.
assertEqual
(
len
(
tmpfs_list
),
3
)
self
.
host
.
start
(
container
)
status
=
self
.
host
.
wait
(
container
)
logs
=
self
.
host
.
logs
(
container
)
if
status
!=
0
:
print
(
logs
)
self
.
assertEqual
(
status
,
1
)
self
.
assertTrue
(
"No space left"
in
logs
)
class
AsyncTest
(
NoDiscoveryTests
):
@
slow
...
...
@@ -300,7 +268,7 @@ class AsyncTest(NoDiscoveryTests):
self
.
assertEqual
(
self
.
host
.
logs
(
container
),
""
)
class
AsyncWithEnvironment
Test
(
unittest
.
TestCase
):
class
WithDiscovery
Test
s
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
host
=
Host
(
raise_on_errors
=
False
)
...
...
@@ -314,6 +282,31 @@ class AsyncWithEnvironmentTest(unittest.TestCase):
self
.
host
.
teardown
()
self
.
assertFalse
(
self
.
host
.
containers
)
# All containers are gone
class
TmpfsWithEnvironmentTest
(
WithDiscoveryTests
):
def
test_tmpfs_from_label
(
self
):
"""Test that the tmpfs are respected."""
container
=
self
.
host
.
create_container
(
"Python for tests (1.3.0)"
,
[
"dd"
,
"if=/dev/zero"
,
"of=/custom_tmpfs/test.txt"
],
)
tmpfs_list
=
container
.
temporary_filesystems
self
.
assertEqual
(
len
(
tmpfs_list
),
3
)
print
(
tmpfs_list
)
self
.
host
.
start
(
container
)
status
=
self
.
host
.
wait
(
container
)
logs
=
self
.
host
.
logs
(
container
)
if
status
!=
0
:
print
(
logs
)
self
.
assertEqual
(
status
,
1
)
self
.
assertTrue
(
"No space left"
in
logs
)
class
AsyncWithEnvironmentTest
(
WithDiscoveryTests
):
@
slow
def
test_memory_limit
(
self
):
...
...
beat/core/test/utils.py
View file @
7adf8af0
...
...
@@ -46,10 +46,10 @@ import nose
# Images used for docker-enabled tests within this and other BEAT packages
DOCKER_TEST_IMAGES
=
{
"docker.idiap.ch/beat/beat.env.builder/beat.env.python.tests"
:
"1.3.0r
7
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.db.examples"
:
"1.4.
0r7
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.cxx"
:
"2.0.0r
4
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.cxxdev"
:
"2.0.0r
4
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.python.tests"
:
"1.3.0r
8
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.db.examples"
:
"1.4.
1r1
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.cxx"
:
"2.0.0r
5
"
,
"docker.idiap.ch/beat/beat.env.builder/beat.env.cxxdev"
:
"2.0.0r
5
"
,
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment