| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Test how ulimits are applied in podman-compose build.""" |
| 5 |
|
| 6 |
import os |
| 7 |
import subprocess |
| 8 |
import unittest |
| 9 |
|
| 10 |
from tests.integration.test_utils import podman_compose_path |
| 11 |
from tests.integration.test_utils import test_path |
| 12 |
|
| 13 |
|
| 14 |
def compose_yaml_path(): |
| 15 |
""" "Returns the path to the compose file used for this test module""" |
| 16 |
return os.path.join(test_path(), "ulimit_build") |
| 17 |
|
| 18 |
|
| 19 |
class TestComposeBuildUlimits(unittest.TestCase): |
| 20 |
def test_build_ulimits_ulimit1(self): |
| 21 |
"""podman build should receive and apply limits when building service ulimit1""" |
| 22 |
|
| 23 |
cmd = ( |
| 24 |
"coverage", |
| 25 |
"run", |
| 26 |
podman_compose_path(), |
| 27 |
"--verbose", |
| 28 |
"-f", |
| 29 |
os.path.join(compose_yaml_path(), "docker-compose.yaml"), |
| 30 |
"build", |
| 31 |
"--no-cache", |
| 32 |
"ulimit1", |
| 33 |
) |
| 34 |
p = subprocess.run( |
| 35 |
cmd, stdout=subprocess.PIPE, check=False, stderr=subprocess.STDOUT, text=True |
| 36 |
) |
| 37 |
|
| 38 |
self.assertEqual(p.returncode, 0) |
| 39 |
self.assertIn("--ulimit nofile=1001", p.stdout) |
| 40 |
self.assertIn("soft nofile limit: 1001", p.stdout) |
| 41 |
self.assertIn("hard nofile limit: 1001", p.stdout) |
| 42 |
|
| 43 |
def test_build_ulimits_ulimit2(self): |
| 44 |
"""podman build should receive and apply limits when building service ulimit2""" |
| 45 |
|
| 46 |
cmd = ( |
| 47 |
"coverage", |
| 48 |
"run", |
| 49 |
podman_compose_path(), |
| 50 |
"--verbose", |
| 51 |
"-f", |
| 52 |
os.path.join(compose_yaml_path(), "docker-compose.yaml"), |
| 53 |
"build", |
| 54 |
"--no-cache", |
| 55 |
"ulimit2", |
| 56 |
) |
| 57 |
p = subprocess.run( |
| 58 |
cmd, stdout=subprocess.PIPE, check=False, stderr=subprocess.STDOUT, text=True |
| 59 |
) |
| 60 |
|
| 61 |
self.assertEqual(p.returncode, 0) |
| 62 |
self.assertIn("--ulimit nofile=1002", p.stdout) |
| 63 |
self.assertIn("--ulimit nproc=1002:2002", p.stdout) |
| 64 |
self.assertIn("soft process limit: 1002", p.stdout) |
| 65 |
self.assertIn("hard process limit: 2002", p.stdout) |
| 66 |
self.assertIn("soft nofile limit: 1002", p.stdout) |
| 67 |
self.assertIn("hard nofile limit: 1002", p.stdout) |
| 68 |
|
| 69 |
def test_build_ulimits_ulimit3(self): |
| 70 |
"""podman build should receive and apply limits when building service ulimit3""" |
| 71 |
|
| 72 |
cmd = ( |
| 73 |
"coverage", |
| 74 |
"run", |
| 75 |
podman_compose_path(), |
| 76 |
"--verbose", |
| 77 |
"-f", |
| 78 |
os.path.join(compose_yaml_path(), "docker-compose.yaml"), |
| 79 |
"build", |
| 80 |
"--no-cache", |
| 81 |
"ulimit3", |
| 82 |
) |
| 83 |
p = subprocess.run( |
| 84 |
cmd, stdout=subprocess.PIPE, check=False, stderr=subprocess.STDOUT, text=True |
| 85 |
) |
| 86 |
|
| 87 |
self.assertEqual(p.returncode, 0) |
| 88 |
self.assertIn("--ulimit nofile=1003", p.stdout) |
| 89 |
self.assertIn("--ulimit nproc=1003:2003", p.stdout) |
| 90 |
self.assertIn("soft process limit: 1003", p.stdout) |
| 91 |
self.assertIn("hard process limit: 2003", p.stdout) |
| 92 |
self.assertIn("soft nofile limit: 1003", p.stdout) |
| 93 |
self.assertIn("hard nofile limit: 1003", p.stdout) |