]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add ability to enable/disable controllers in the subtree control file
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 8 Mar 2023 19:44:56 +0000 (12:44 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 28 Mar 2023 17:08:35 +0000 (11:08 -0600)
Add a method to the functional tests that can enable/disable controllers
in the cgroup.subtree_control file.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 5a331e5f20a05ae4bf0c95bc68f62670612546f8)

tests/ftests/cgroup.py

index 948eedbb1c8e2f1aad38cca221a471e22c765bed..557db8311af7d82e71c0fe78870189e381dfb382 100644 (file)
@@ -1113,6 +1113,25 @@ class Cgroup(object):
 
         return True
 
+    # Method to enable or disable controllers in the subtree control file
+    @staticmethod
+    def subtree_control(config, cgname, controllers, enable=True, ignore_systemd=False):
+        if isinstance(controllers, str):
+            controllers = [controllers]
+        elif isinstance(controllers, list):
+            pass
+        else:
+            raise ValueError('Unsupported controller value')
+
+        if enable:
+            enable_char = '+'
+        else:
+            enable_char = '-'
+
+        for ctrl in controllers:
+            Cgroup.set(config, cgname, 'cgroup.subtree_control',
+                       '{}{}'.format(enable_char, ctrl), ignore_systemd=ignore_systemd)
+
 
 class CgroupError(Exception):
     def __init__(self, message):