From: Tom Hromatka Date: Wed, 3 Feb 2021 17:00:52 +0000 (-0700) Subject: ftests: Use sudo for many cgroup commands when not in a container X-Git-Tag: v2.0.3~11^2^2~26^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58f2409932b7fd0531661cb92baebcc0848932dc;p=thirdparty%2Flibcgroup.git ftests: Use sudo for many cgroup commands when not in a container When not running in a container, prepend 'sudo' to the front of cgcreate, cgdelete, cgset, and cgclassify. It would be advantageous to properly utilize permissions within Linux so that we don't need to 'sudo' these commands, but that's more of a kernel/sysfs/cgroups issue than a libcgroup issue. (Yes, libcgroup does allow for setting owners and permissions, so someday we should test this, but that's not a high priority at present.) Signed-off-by: Tom Hromatka --- diff --git a/ftests/cgroup.py b/ftests/cgroup.py index 5906a199..4ff64c6f 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -90,6 +90,9 @@ class Cgroup(object): controller_list = [controller_list] cmd = list() + + if not config.args.container: + cmd.append('sudo') cmd.append(Cgroup.build_cmd_path('cgcreate')) controllers_and_path = '{}:{}'.format( @@ -109,6 +112,9 @@ class Cgroup(object): controller_list = [controller_list] cmd = list() + + if not config.args.container: + cmd.append('sudo') cmd.append(Cgroup.build_cmd_path('cgdelete')) if recursive: @@ -128,6 +134,9 @@ class Cgroup(object): @staticmethod def set(config, cgname, setting, value): cmd = list() + + if not config.args.container: + cmd.append('sudo') cmd.append(Cgroup.build_cmd_path('cgset')) if isinstance(setting, str) and isinstance(value, str): @@ -226,6 +235,9 @@ class Cgroup(object): def classify(config, controller, cgname, pid_list, sticky=False, cancel_sticky=False): cmd = list() + + if not config.args.container: + cmd.append('sudo') cmd.append(Cgroup.build_cmd_path('cgclassify')) cmd.append('-g') cmd.append('{}:{}'.format(controller, cgname))