]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Make the Cgroup class instantiable
authorTom Hromatka <tom.hromatka@oracle.com>
Thu, 17 Dec 2020 21:54:13 +0000 (14:54 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 17 Dec 2020 22:01:45 +0000 (15:01 -0700)
Add logic to the functional test's Cgroup class to
make it analogous to libcgroup's struct cgroup.
By adding  __init__(), __str__(), and __eq__() methods,
the cgroup class can very closely mirror struct cgroup.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests/cgroup.py

index 146ced711a46e2532640642dea58626759268334..9e1d46c9b955b4052b6c187556d99dcd70d24f96 100644 (file)
 #
 
 import consts
+from controller import Controller
 from enum import Enum
 import os
 from run import Run
+import utils
 
 class CgroupVersion(Enum):
     CGROUP_UNK = 0
@@ -50,6 +52,32 @@ class CgroupVersion(Enum):
         return CgroupVersion.CGROUP_UNK
 
 class Cgroup(object):
+    # This class is analogous to libcgroup's struct cgroup
+    def __init__(self, name):
+        self.name = name
+        # self.controllers maps to
+        # struct cgroup_controller *controller[CG_CONTROLLER_MAX];
+        self.controllers = dict()
+
+    def __str__(self):
+        out_str = "Cgroup {}\n".format(self.name)
+        for ctrl_key in self.controllers:
+            out_str += utils.indent(str(self.controllers[ctrl_key]), 4)
+
+        return out_str
+
+    def __eq__(self, other):
+        if not isinstance(other, Cgroup):
+            return False
+
+        if not self.name == other.name:
+            return False
+
+        if self.controllers != other.controllers:
+            return False
+
+        return True
+
     @staticmethod
     def build_cmd_path(in_container, cmd):
         if in_container: