From 2e3a4c15397676897c18e9f658d0aa0282d38b70 Mon Sep 17 00:00:00 2001 From: Jeremy Visser Date: Thu, 5 Dec 2024 20:40:59 +1100 Subject: [PATCH] Add device_cgroup_rules support "device_cgroup_rules: []" is defined in the Compose file specification, and corresponds to "podman run --device-cgroup-rule=" Signed-off-by: Jeremy Visser --- podman_compose.py | 2 ++ tests/unit/test_container_to_args.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/podman_compose.py b/podman_compose.py index b1d21cfc..81dcba39 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1074,6 +1074,8 @@ async def container_to_args(compose, cnt, detached=True): podman_args.extend(["--group-add", item]) for item in cnt.get("devices", []): podman_args.extend(["--device", item]) + for item in cnt.get("device_cgroup_rules", []): + podman_args.extend(["--device-cgroup-rule", item]) for item in norm_as_list(cnt.get("dns")): podman_args.extend(["--dns", item]) for item in norm_as_list(cnt.get("dns_opt")): diff --git a/tests/unit/test_container_to_args.py b/tests/unit/test_container_to_args.py index e27ce622..b556b237 100644 --- a/tests/unit/test_container_to_args.py +++ b/tests/unit/test_container_to_args.py @@ -611,3 +611,26 @@ async def test_network_default_name(self, name, is_compat, project_name, expecte "busybox", ], ) + + async def test_device(self): + c = create_compose_mock() + cnt = get_minimal_container() + + cnt['devices'] = ['/dev/ttyS0'] + cnt['device_cgroup_rules'] = ['c 100:200 rwm'] + + args = await container_to_args(c, cnt) + self.assertEqual( + args, + [ + "--name=project_name_service_name1", + "-d", + "--device", + "/dev/ttyS0", + "--device-cgroup-rule", + "c 100:200 rwm", + "--network=bridge", + "--network-alias=service_name", + "busybox", + ], + )