Commit 7adf8af0 authored by André Anjos's avatar 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
...@@ -795,6 +795,17 @@ class Container: ...@@ -795,6 +795,17 @@ class Container:
self._entrypoint = None self._entrypoint = None
self._temporary_filesystems = {"/tmp": "500k", "/run": "500k"} # nosec 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): def set_name(self, name):
""" Set the name to be used by the container in place of the docker """ Set the name to be used by the container in place of the docker
auto generated one. auto generated one.
......
...@@ -107,8 +107,7 @@ class NetworkTest(NoDiscoveryTests): ...@@ -107,8 +107,7 @@ class NetworkTest(NoDiscoveryTests):
class UserTest(NoDiscoveryTests): class UserTest(NoDiscoveryTests):
@slow @slow
def test_user(self): 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 = self.host.create_container("debian:8.4", ["id"])
container.uid = 10000 container.uid = 10000
...@@ -127,8 +126,7 @@ class UserTest(NoDiscoveryTests): ...@@ -127,8 +126,7 @@ class UserTest(NoDiscoveryTests):
class EnvironmentVariableTest(NoDiscoveryTests): class EnvironmentVariableTest(NoDiscoveryTests):
@slow @slow
def test_environment_variable(self): 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 = self.host.create_container("debian:8.4", ["env"])
container.add_environment_variable("DOCKER_TEST", "good") container.add_environment_variable("DOCKER_TEST", "good")
...@@ -143,8 +141,7 @@ class EnvironmentVariableTest(NoDiscoveryTests): ...@@ -143,8 +141,7 @@ class EnvironmentVariableTest(NoDiscoveryTests):
class WorkdirTest(NoDiscoveryTests): class WorkdirTest(NoDiscoveryTests):
@slow @slow
def test_workdir(self): 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: with TemporaryDirectory() as tmp_folder:
test_file = "test.txt" test_file = "test.txt"
...@@ -169,8 +166,7 @@ class WorkdirTest(NoDiscoveryTests): ...@@ -169,8 +166,7 @@ class WorkdirTest(NoDiscoveryTests):
class EntrypointTest(NoDiscoveryTests): class EntrypointTest(NoDiscoveryTests):
@slow @slow
def test_entrypoint(self): 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 = self.host.create_container("debian:8.4", ["42"])
container.set_entrypoint("echo") container.set_entrypoint("echo")
...@@ -187,8 +183,7 @@ class EntrypointTest(NoDiscoveryTests): ...@@ -187,8 +183,7 @@ class EntrypointTest(NoDiscoveryTests):
class TmpfsTest(NoDiscoveryTests): class TmpfsTest(NoDiscoveryTests):
def test_tmpfs(self): 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( container = self.host.create_container(
"debian:8.4", ["touch", "/dummy/test.txt"] "debian:8.4", ["touch", "/dummy/test.txt"]
...@@ -213,33 +208,6 @@ class TmpfsTest(NoDiscoveryTests): ...@@ -213,33 +208,6 @@ class TmpfsTest(NoDiscoveryTests):
self.assertEqual(status, 0) self.assertEqual(status, 0)
self.assertEqual(logs, "") 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): class AsyncTest(NoDiscoveryTests):
@slow @slow
...@@ -300,7 +268,7 @@ class AsyncTest(NoDiscoveryTests): ...@@ -300,7 +268,7 @@ class AsyncTest(NoDiscoveryTests):
self.assertEqual(self.host.logs(container), "") self.assertEqual(self.host.logs(container), "")
class AsyncWithEnvironmentTest(unittest.TestCase): class WithDiscoveryTests(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.host = Host(raise_on_errors=False) cls.host = Host(raise_on_errors=False)
...@@ -314,6 +282,31 @@ class AsyncWithEnvironmentTest(unittest.TestCase): ...@@ -314,6 +282,31 @@ class AsyncWithEnvironmentTest(unittest.TestCase):
self.host.teardown() self.host.teardown()
self.assertFalse(self.host.containers) # All containers are gone 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 @slow
def test_memory_limit(self): def test_memory_limit(self):
......
...@@ -46,10 +46,10 @@ import nose ...@@ -46,10 +46,10 @@ import nose
# Images used for docker-enabled tests within this and other BEAT packages # Images used for docker-enabled tests within this and other BEAT packages
DOCKER_TEST_IMAGES = { DOCKER_TEST_IMAGES = {
"docker.idiap.ch/beat/beat.env.builder/beat.env.python.tests": "1.3.0r7", "docker.idiap.ch/beat/beat.env.builder/beat.env.python.tests": "1.3.0r8",
"docker.idiap.ch/beat/beat.env.builder/beat.env.db.examples": "1.4.0r7", "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.0r4", "docker.idiap.ch/beat/beat.env.builder/beat.env.cxx": "2.0.0r5",
"docker.idiap.ch/beat/beat.env.builder/beat.env.cxxdev": "2.0.0r4", "docker.idiap.ch/beat/beat.env.builder/beat.env.cxxdev": "2.0.0r5",
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment