]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add support for lists in Cgroup.exists()
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 7 Apr 2023 22:18:30 +0000 (16:18 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 20 Apr 2023 20:17:30 +0000 (14:17 -0600)
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 <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 1e721f1fbe095933b2087ed362ff1e6d1099dcfe)

tests/ftests/cgroup.py

index 2d3d31672069d8ca1260bae2dcb235931c138afd..b08d1f9f26070150ced3fa719870e61705255f90 100644 (file)
@@ -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):