From 054c66b56879d40221ace4fc0721e85131e02b90 Mon Sep 17 00:00:00 2001 From: Jeremy Visser Date: Fri, 6 Dec 2024 08:19:54 +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 --- newsfragments/device_cgroup_rules.feature | 1 + podman_compose.py | 2 ++ tests/unit/test_container_to_args.py | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 newsfragments/device_cgroup_rules.feature diff --git a/newsfragments/device_cgroup_rules.feature b/newsfragments/device_cgroup_rules.feature new file mode 100644 index 00000000..66420d44 --- /dev/null +++ b/newsfragments/device_cgroup_rules.feature @@ -0,0 +1 @@ +Added support for the "device_cgroup_rules" property in services. 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", + ], + )