From: Kamalesh Babulal Date: Tue, 15 Feb 2022 06:59:47 +0000 (+0530) Subject: test-006: make it PEP8 compliant X-Git-Tag: v3.1.0~308^2~2^2~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e496fa739c985da81e107e385a8e76ced03529e7;p=thirdparty%2Flibcgroup.git test-006: make it PEP8 compliant Make test 006-cgrules-basic_cgrules_v1.py PEP-8 compliant. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/ftests/006-cgrules-basic_cgrules_v1.py b/ftests/006-cgrules-basic_cgrules_v1.py index bf1f9388..e18186ad 100755 --- a/ftests/006-cgrules-basic_cgrules_v1.py +++ b/ftests/006-cgrules-basic_cgrules_v1.py @@ -21,45 +21,52 @@ # from cgroup import Cgroup, CgroupVersion +from process import Process import consts import ftests -import os -from process import Process import sys +import os -CONTROLLER='cpu' -PARENT_CGNAME='006cgrules' -CHILD_CGNAME='childcg' +CONTROLLER = 'cpu' +PARENT_CGNAME = '006cgrules' +CHILD_CGNAME = 'childcg' # move all perl processes to the 006cgrules/childcg cgroup in the # cpu controller -CGRULE="*:/usr/bin/perl cpu {}".format(os.path.join(PARENT_CGNAME, CHILD_CGNAME)) +CGRULE = ( + '*:/usr/bin/perl cpu {}' + ''.format(os.path.join(PARENT_CGNAME, CHILD_CGNAME)) + ) cg = Cgroup(os.path.join(PARENT_CGNAME, CHILD_CGNAME)) + def prereqs(config): result = consts.TEST_PASSED cause = None if config.args.container: result = consts.TEST_SKIPPED - cause = "This test cannot be run within a container" + cause = 'This test cannot be run within a container' return result, cause if CgroupVersion.get_version('cpu') != CgroupVersion.CGROUP_V1: result = consts.TEST_SKIPPED - cause = "This test requires the cgroup v1 cpu controller" + cause = 'This test requires the cgroup v1 cpu controller' return result, cause return result, cause + def setup(config): Cgroup.create(config, CONTROLLER, PARENT_CGNAME) - Cgroup.create(config, CONTROLLER, os.path.join(PARENT_CGNAME, CHILD_CGNAME)) + Cgroup.create(config, CONTROLLER, + os.path.join(PARENT_CGNAME, CHILD_CGNAME)) Cgroup.set_cgrules_conf(config, CGRULE, append=False) cg.start_cgrules(config) + def test(config): result = consts.TEST_PASSED cause = None @@ -70,17 +77,24 @@ def test(config): # proc/{pid}/cgroup alsways prepends a '/' to the cgroup path if proc_cgroup != os.path.join('/', PARENT_CGNAME, CHILD_CGNAME): result = consts.TEST_FAILED - cause = "PID {} was expected to be in cgroup {} but is in cgroup {}".format( - pid, os.path.join('/', PARENT_CGNAME, CHILD_CGNAME), proc_cgroup) + cause = ( + 'PID {} was expected to be in cgroup {} but is in ' + 'cgroup {}' + ''.format(pid, + os.path.join('/', PARENT_CGNAME, CHILD_CGNAME), + proc_cgroup) + ) return result, cause + def teardown(config): # destroy the child processes config.process.join_children(config) cg.join_children(config) Cgroup.delete(config, CONTROLLER, PARENT_CGNAME, recursive=True) + def main(config): [result, cause] = prereqs(config) if result != consts.TEST_PASSED: @@ -94,6 +108,7 @@ def main(config): return [result, cause] + if __name__ == '__main__': config = ftests.parse_args() # this test was invoked directly. run only it