From: Tom Hromatka Date: Fri, 7 Apr 2023 22:18:30 +0000 (-0600) Subject: ftests: Add support for lists in Cgroup.exists() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d22e55c20bc32b70f2d07becb0ee699602ab6b37;p=thirdparty%2Flibcgroup.git ftests: Add support for lists in Cgroup.exists() Add support for checking if a cgroup exists when a list of controllers is provided. For example, given: controllers = ['cpu', 'pids'] cgroup_name = 'test_cgroup' Cgroup.exists(config, controllers, cgroup_name) will now work. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal (cherry picked from commit 1e721f1fbe095933b2087ed362ff1e6d1099dcfe) --- diff --git a/tests/ftests/cgroup.py b/tests/ftests/cgroup.py index 2d3d3167..b08d1f9f 100644 --- a/tests/ftests/cgroup.py +++ b/tests/ftests/cgroup.py @@ -1105,11 +1105,8 @@ class Cgroup(object): return False - # This function builds absolute path of the cgroup, using the default - # systemd path and checks if the cgroup exists. The function can build - # path for all three cgroup setup modes, including empty cgroup v2. @staticmethod - def exists(config, ctrl_name, cgroup_name, ignore_systemd=False): + def __exists(config, ctrl_name, cgroup_name, ignore_systemd): ctrl_mnt = Cgroup.get_controller_mount_point(ctrl_name) if (ignore_systemd): @@ -1140,6 +1137,24 @@ class Cgroup(object): return True + # This function builds absolute path of the cgroup, using the default + # systemd path and checks if the cgroup exists. The function can build + # path for all three cgroup setup modes, including empty cgroup v2. + @staticmethod + def exists(config, ctrl_name, cgroup_name, ignore_systemd=False): + if ctrl_name is None or type(ctrl_name) == str: + return Cgroup.__exists(config, ctrl_name, cgroup_name, ignore_systemd) + elif type(ctrl_name) == list: + for ctrl in ctrl_name: + if not Cgroup.__exists(config, ctrl, cgroup_name, ignore_systemd): + # if any of the controllers don't exist, fail the check + return False + + # all of the controllers exist, Yippee + return True + else: + raise ValueError("Unsupported type: {}".format(type(ctrl_name))) + # Method to enable or disable controllers in the subtree control file @staticmethod def subtree_control(config, cgname, controllers, enable=True, ignore_systemd=False):