mirror of
https://github.com/containers/podman-compose.git
synced 2024-11-22 16:03:16 +01:00
a9c335bf82
- Add support to handle sysctls maps. - Directly raise an error if sysctls is neither an array nor map instead of letting podman fail with an unhelpful message. Support for sysctls arrays was added in #261. Fixes #754: sysctls only works with arrays, not maps Signed-off-by: lemmi <lemmi@nerd2nerd.org>
133 lines
3.4 KiB
Python
133 lines
3.4 KiB
Python
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from podman_compose import container_to_args
|
|
|
|
|
|
def create_compose_mock():
|
|
compose = mock.Mock()
|
|
compose.project_name = "test_project_name"
|
|
compose.dirname = "test_dirname"
|
|
compose.container_names_by_service.get = mock.Mock(return_value=None)
|
|
compose.prefer_volume_over_mount = False
|
|
compose.default_net = None
|
|
compose.networks = {}
|
|
return compose
|
|
|
|
|
|
def get_minimal_container():
|
|
return {
|
|
"name": "project_name_service_name1",
|
|
"service_name": "service_name",
|
|
"image": "busybox",
|
|
}
|
|
|
|
|
|
class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|
async def test_minimal(self):
|
|
c = create_compose_mock()
|
|
|
|
cnt = get_minimal_container()
|
|
|
|
args = await container_to_args(c, cnt)
|
|
self.assertEqual(
|
|
args,
|
|
[
|
|
"--name=project_name_service_name1",
|
|
"-d",
|
|
"--net",
|
|
"",
|
|
"--network-alias",
|
|
"service_name",
|
|
"busybox",
|
|
],
|
|
)
|
|
|
|
async def test_runtime(self):
|
|
c = create_compose_mock()
|
|
|
|
cnt = get_minimal_container()
|
|
cnt["runtime"] = "runsc"
|
|
|
|
args = await container_to_args(c, cnt)
|
|
self.assertEqual(
|
|
args,
|
|
[
|
|
"--name=project_name_service_name1",
|
|
"-d",
|
|
"--net",
|
|
"",
|
|
"--network-alias",
|
|
"service_name",
|
|
"--runtime",
|
|
"runsc",
|
|
"busybox",
|
|
],
|
|
)
|
|
|
|
async def test_sysctl_list(self):
|
|
c = create_compose_mock()
|
|
|
|
cnt = get_minimal_container()
|
|
cnt["sysctls"] = [
|
|
"net.core.somaxconn=1024",
|
|
"net.ipv4.tcp_syncookies=0",
|
|
]
|
|
|
|
args = await container_to_args(c, cnt)
|
|
self.assertEqual(
|
|
args,
|
|
[
|
|
"--name=project_name_service_name1",
|
|
"-d",
|
|
"--net",
|
|
"",
|
|
"--network-alias",
|
|
"service_name",
|
|
"--sysctl",
|
|
"net.core.somaxconn=1024",
|
|
"--sysctl",
|
|
"net.ipv4.tcp_syncookies=0",
|
|
"busybox",
|
|
],
|
|
)
|
|
|
|
async def test_sysctl_map(self):
|
|
c = create_compose_mock()
|
|
|
|
cnt = get_minimal_container()
|
|
cnt["sysctls"] = {
|
|
"net.core.somaxconn": 1024,
|
|
"net.ipv4.tcp_syncookies": 0,
|
|
}
|
|
|
|
args = await container_to_args(c, cnt)
|
|
self.assertEqual(
|
|
args,
|
|
[
|
|
"--name=project_name_service_name1",
|
|
"-d",
|
|
"--net",
|
|
"",
|
|
"--network-alias",
|
|
"service_name",
|
|
"--sysctl",
|
|
"net.core.somaxconn=1024",
|
|
"--sysctl",
|
|
"net.ipv4.tcp_syncookies=0",
|
|
"busybox",
|
|
],
|
|
)
|
|
|
|
async def test_sysctl_wrong_type(self):
|
|
c = create_compose_mock()
|
|
cnt = get_minimal_container()
|
|
|
|
# check whether wrong types are correctly rejected
|
|
for wrong_type in [True, 0, 0.0, "wrong", ()]:
|
|
with self.assertRaises(TypeError):
|
|
cnt["sysctls"] = wrong_type
|
|
await container_to_args(c, cnt)
|