From: Tom Hromatka Date: Fri, 27 Jan 2023 20:43:45 +0000 (-0700) Subject: ftests: Add method to determine if a controller is enabled in a cgroup X-Git-Tag: v3.1.0~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=925d381fd0bef9d529fe0b248207c325b1331392;p=thirdparty%2Flibcgroup.git ftests: Add method to determine if a controller is enabled in a cgroup Add a method, is_controller_enabled(), that will determine if a controller is enabled in a cgroup v2 cgroup. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- diff --git a/tests/ftests/cgroup.py b/tests/ftests/cgroup.py index d5fd1d00..9b3ecf58 100644 --- a/tests/ftests/cgroup.py +++ b/tests/ftests/cgroup.py @@ -1005,6 +1005,24 @@ class Cgroup(object): else: raise CgroupError('Unknown cgroup mode') + @staticmethod + def is_controller_enabled(config, cgroup_name, ctrl_name): + ctrl_path = Cgroup.__get_controller_mount_point_v2(ctrl_name) + parent_cgname = os.path.dirname(cgroup_name) + + subtree_path = os.path.join(ctrl_path, parent_cgname, 'cgroup.subtree_control') + cmd = ['cat', subtree_path] + + if config.args.container: + controllers = config.container.run(cmd, shell_bool=True) + else: + controllers = Run.run(cmd, shell_bool=True) + + for controller in controllers.split(): + if controller == ctrl_name: + return True + + return False class CgroupError(Exception): def __init__(self, message):