]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgroup: Add helper methods to validate get/set
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 21 Jan 2022 22:15:35 +0000 (22:15 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 25 Jan 2022 14:53:12 +0000 (07:53 -0700)
Add helper methods, get_and_validate() and set_and_validate().
These methods do not map directly to any libcgroup command
line interfaces, but should be useful in reducing copy/paste
boilerplate code.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
ftests/cgroup.py

index d3a3dfc25e4f7d8e979dacc4f9595cd10d42227c..ad1cd388044b9b36f564008d95054e4522261b82 100644 (file)
@@ -830,3 +830,34 @@ class Cgroup(object):
                     return Run.run(cmd, shell_bool=True)
 
         return None
+
+    @staticmethod
+    def get_and_validate(config, cgname, setting, expected_value):
+        """get the requested setting and validate the value received
+
+        This is a helper method for the functional tests and there is no
+        equivalent libcgroup command line interface.  This method will
+        raise a CgroupError if the comparison fails
+        """
+        value = Cgroup.get(config, controller=None, cgname=cgname,
+                           setting=setting, print_headers=False,
+                           values_only=True)
+
+        if value != expected_value:
+            raise CgroupError("cgget expected {} but received {}".format(
+                              expected_value, value))
+
+    @staticmethod
+    def set_and_validate(config, cgname, setting, value):
+        """set the requested setting and validate the write
+
+        This is a helper method for the functional tests and there is no
+        equivalent libcgroup command line interface.  This method will
+        raise a CgroupError if the comparison fails
+        """
+        Cgroup.set(config, cgname, setting, value)
+        Cgroup.get_and_validate(config, cgname, setting, value)
+
+class CgroupError(Exception):
+    def __init__(self, message):
+        super(CgroupError, self).__init__(message)