]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add permissions support to cgsnapshot parsing
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 3 Feb 2021 17:46:23 +0000 (10:46 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 3 Feb 2021 22:13:17 +0000 (22:13 +0000)
In a container cgsnapshot doesn't report owner/group
permissions, but on a bare-metal setup, it does.  Add
support to parse the permissions fields.

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

index 947cbbe940ecd3a102ec10a4e36069a65e6a303e..269657549d3104b27919dabcf79c095adc98d4f9 100644 (file)
@@ -227,7 +227,7 @@ class Cgroup(object):
         if config.args.container:
             ret = config.container.run(cmd)
         else:
-            ret = Run.run(cmd)
+            ret = Run.run(cmd).decode('ascii')
 
         return ret
 
@@ -265,6 +265,9 @@ class Cgroup(object):
             GROUP = 1
             CONTROLLER = 2
             SETTING = 3
+            PERM = 4
+            ADMIN = 5
+            TASK = 6
 
         mode = parsemode.UNKNOWN
 
@@ -287,7 +290,9 @@ class Cgroup(object):
                     mode = parsemode.GROUP
 
             elif mode == parsemode.GROUP:
-                if line.endswith("{"):
+                if line.startswith("perm {"):
+                    mode = parsemode.PERM
+                elif line.endswith("{"):
                     ctrl_name = line.split()[0]
                     cg.controllers[ctrl_name] = Controller(ctrl_name)
 
@@ -327,6 +332,19 @@ class Cgroup(object):
                 else:
                     value += "{}\n".format(line)
 
+            elif mode == parsemode.PERM:
+                if line.startswith("admin {"):
+                    mode = parsemode.ADMIN
+                elif line.startswith("task {"):
+                    mode = parsemode.TASK
+                elif line.endswith("}"):
+                    mode = parsemode.GROUP
+
+            elif mode == parsemode.ADMIN or mode == parsemode.TASK:
+                # todo - handle these modes
+                if line.endswith("}"):
+                    mode = parsemode.PERM
+
         return cgdict
 
     @staticmethod
@@ -345,7 +363,7 @@ class Cgroup(object):
         if config.args.container:
             res = config.container.run(cmd)
         else:
-            res = Run.run(cmd)
+            res = Run.run(cmd).decode('ascii')
 
         # convert the cgsnapshot stdout to a dict of cgroup objects
         return Cgroup.snapshot_to_dict(res)