# along with this library; if not, see <http://www.gnu.org/licenses>.
#
-from cgroup import Cgroup
+from cgroup import Cgroup, CgroupVersion
import consts
import ftests
import os
result = consts.TEST_PASSED
cause = None
- # This test was written for a cgroup v1 cpu controller only
- if Cgroup.version('cpu') != Cgroup.CGROUP_V1:
+ if CgroupVersion.get_version('cpu') != CgroupVersion.CGROUP_V1:
result = consts.TEST_SKIPPED
cause = "This test requires the cgroup v1 cpu controller"
# along with this library; if not, see <http://www.gnu.org/licenses>.
#
-from cgroup import Cgroup
+from cgroup import Cgroup, CgroupVersion
import consts
import ftests
import os
Cgroup.create(config, CONTROLLER, os.path.join(PARENT, CHILD))
Cgroup.create(config, CONTROLLER, os.path.join(PARENT, CHILD, GRANDCHILD))
- version = Cgroup.version(CONTROLLER)
- if version == Cgroup.CGROUP_V1:
+ version = CgroupVersion.get_version(CONTROLLER)
+ if version == CgroupVersion.CGROUP_V1:
# cgdelete in a cgroup v1 controller should be able to move a process
# from a child cgroup to its parent.
#
# along with this library; if not, see <http://www.gnu.org/licenses>.
#
-from cgroup import Cgroup
+from cgroup import Cgroup, CgroupVersion
import consts
import ftests
import os
result = consts.TEST_PASSED
cause = None
- if Cgroup.version('cpuset') != Cgroup.CGROUP_V2:
+ if CgroupVersion.get_version('cpuset') != CgroupVersion.CGROUP_V2:
result = consts.TEST_SKIPPED
cause = "This test requires the cgroup v2 cpuset controller"
import os
from run import Run
-class Cgroup(Enum):
+class CgroupVersion(Enum):
CGROUP_UNK = 0
CGROUP_V1 = 1
CGROUP_V2 = 2
+ # given a controller name, get the cgroup version of the controller
+ @staticmethod
+ def get_version(controller):
+ with open('/proc/mounts', 'r') as mntf:
+ for line in mntf.readlines():
+ mnt_path = line.split()[1]
+
+ if line.split()[0] == 'cgroup':
+ for option in line.split()[3].split(','):
+ if option == controller:
+ return CgroupVersion.CGROUP_V1
+ elif line.split()[0] == 'cgroup2':
+ with open(os.path.join(mnt_path, 'cgroup.controllers'), 'r') as ctrlf:
+ controllers = ctrlf.readline()
+ for ctrl in controllers.split():
+ if ctrl == controller:
+ return CgroupVersion.CGROUP_V2
+
+ return CgroupVersion.CGROUP_UNK
+
+class Cgroup(object):
@staticmethod
def build_cmd_path(in_container, cmd):
if in_container:
return ret
- @staticmethod
- def version(controller):
- with open('/proc/mounts', 'r') as mntf:
- for line in mntf.readlines():
- mnt_path = line.split()[1]
-
- if line.split()[0] == 'cgroup':
- for option in line.split()[3].split(','):
- if option == controller:
- return Cgroup.CGROUP_V1
- elif line.split()[0] == 'cgroup2':
- with open(os.path.join(mnt_path, 'cgroup.controllers'), 'r') as ctrlf:
- controllers = ctrlf.readline()
- for ctrl in controllers.split():
- if ctrl == controller:
- return Cgroup.CGROUP_V2
-
- return Cgroup.CGROUP_UNK
-
@staticmethod
def classify(config, controller, cgname, pid_list, sticky=False,
cancel_sticky=False, in_container=True):