From: Tom Hromatka Date: Thu, 17 Dec 2020 21:54:13 +0000 (-0700) Subject: ftests: Make the Cgroup class instantiable X-Git-Tag: v2.0.3~11^2^2~29^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e347dcf5716efc361c5da92bc2c9daab633b2475;p=thirdparty%2Flibcgroup.git ftests: Make the Cgroup class instantiable 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 --- diff --git a/ftests/cgroup.py b/ftests/cgroup.py index 146ced71..9e1d46c9 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -20,9 +20,11 @@ # 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: