From: Tom Hromatka Date: Fri, 21 Jan 2022 22:15:35 +0000 (+0000) Subject: cgroup: Add helper methods to validate get/set X-Git-Tag: v3.1.0~308^2~2^2~109^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d256f221d4f3122fdaeee3beaf01ec31b9459e1;p=thirdparty%2Flibcgroup.git cgroup: Add helper methods to validate get/set 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 Reviewed-by: Kamalesh Babulal --- diff --git a/ftests/cgroup.py b/ftests/cgroup.py index d3a3dfc2..ad1cd388 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -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)