@staticmethod
def create(config, controller_list, cgname, user_name=None,
group_name=None, dperm=None, fperm=None, tperm=None,
- tasks_user_name=None, tasks_group_name=None, cghelp=False):
+ tasks_user_name=None, tasks_group_name=None, cghelp=False,
+ ignore_systemd=False):
if isinstance(controller_list, str):
controller_list = [controller_list]
if cghelp:
cmd.append('-h')
+ if ignore_systemd:
+ cmd.append('-b')
+
if controller_list:
controllers_and_path = '{}:{}'.format(
','.join(controller_list), cgname)
Run.run(cmd)
@staticmethod
- def delete(config, controller_list, cgname, recursive=False):
+ def delete(config, controller_list, cgname, recursive=False, ignore_systemd=False):
if isinstance(controller_list, str):
controller_list = [controller_list]
cmd.append('-g')
cmd.append(controllers_and_path)
+ if ignore_systemd:
+ cmd.append('-b')
+
if config.args.container:
config.container.run(cmd)
else:
@staticmethod
def __set(config, cmd, cgname=None, setting=None, value=None,
- copy_from=None, cghelp=False):
+ copy_from=None, cghelp=False, ignore_systemd=False):
if setting is not None or value is not None:
if isinstance(setting, str) and isinstance(value, str):
cmd.append('-r')
for cg in cgname:
cmd.append(cg)
+ if ignore_systemd:
+ cmd.append('-b')
+
if cghelp:
cmd.append('-h')
@staticmethod
def set(config, cgname=None, setting=None, value=None, copy_from=None,
- cghelp=False):
+ cghelp=False, ignore_systemd=False):
"""cgset equivalent method
The following variants of cgset are being tested by the
cmd.append(Cgroup.build_cmd_path('cgset'))
return Cgroup.__set(config, cmd, cgname, setting, value, copy_from,
- cghelp)
+ cghelp, ignore_systemd)
@staticmethod
def xset(config, cgname=None, setting=None, value=None, copy_from=None,
version=CgroupVersion.CGROUP_UNK, cghelp=False,
- ignore_unmappable=False):
+ ignore_unmappable=False, ignore_systemd=False):
"""cgxset equivalent method
"""
cmd = list()
cmd.append('-i')
return Cgroup.__set(config, cmd, cgname, setting, value, copy_from,
- cghelp)
+ cghelp, ignore_systemd)
@staticmethod
def __get(config, cmd, controller=None, cgname=None, setting=None,
print_headers=True, values_only=False,
- all_controllers=False, cghelp=False):
+ all_controllers=False, cghelp=False, ignore_systemd=False):
if not print_headers:
cmd.append('-n')
+
if values_only:
cmd.append('-v')
+ if ignore_systemd:
+ cmd.append('-b')
+
if setting is not None:
if isinstance(setting, str):
# the user provided a simple string. use it as is
@staticmethod
def get(config, controller=None, cgname=None, setting=None,
print_headers=True, values_only=False,
- all_controllers=False, cghelp=False):
+ all_controllers=False, cghelp=False, ignore_systemd=False):
"""cgget equivalent method
Returns:
return Cgroup.__get(config, cmd, controller, cgname, setting,
print_headers, values_only, all_controllers,
- cghelp)
+ cghelp, ignore_systemd)
@staticmethod
def xget(config, controller=None, cgname=None, setting=None,
print_headers=True, values_only=False,
all_controllers=False, version=CgroupVersion.CGROUP_UNK,
- cghelp=False, ignore_unmappable=False):
+ cghelp=False, ignore_unmappable=False, ignore_systemd=False):
"""cgxget equivalent method
Returns:
return Cgroup.__get(config, cmd, controller, cgname, setting,
print_headers, values_only, all_controllers,
- cghelp)
+ cghelp, ignore_systemd)
@staticmethod
def classify(config, controller, cgname, pid_list, sticky=False,
- cancel_sticky=False):
+ cancel_sticky=False, ignore_systemd=False):
cmd = list()
if not config.args.container:
cmd.append('sudo')
cmd.append(Cgroup.build_cmd_path('cgclassify'))
+
+ if ignore_systemd:
+ cmd.append('-b')
+
cmd.append('-g')
cmd.append('{}:{}'.format(controller, cgname))
# exec is a keyword in python, so let's name this function cgexec
@staticmethod
def cgexec(config, controller, cgname, cmdline, sticky=False,
- cghelp=False):
+ cghelp=False, ignore_systemd=False):
"""cgexec equivalent method
"""
cmd = list()
if not config.args.container:
cmd.append('sudo')
cmd.append(Cgroup.build_cmd_path('cgexec'))
+
+ if (ignore_systemd):
+ cmd.append('-b')
+
cmd.append('-g')
cmd.append('{}:{}'.format(controller, cgname))
return None
@staticmethod
- def get_and_validate(config, cgname, setting, expected_value):
+ def get_and_validate(config, cgname, setting, expected_value, ignore_systemd=False):
"""get the requested setting and validate the value received
This is a helper method for the functional tests and there is no
"""
value = Cgroup.get(config, controller=None, cgname=cgname,
setting=setting, print_headers=False,
- values_only=True)
+ values_only=True, ignore_systemd=ignore_systemd)
if value != expected_value:
raise CgroupError('cgget expected {} but received {}'.format(
expected_value, value))
@staticmethod
- def set_and_validate(config, cgname, setting, value):
+ def set_and_validate(config, cgname, setting, value, ignore_systemd=False):
"""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)
+ Cgroup.set(config, cgname, setting, value, ignore_systemd=ignore_systemd)
+ Cgroup.get_and_validate(config, cgname, setting, value, ignore_systemd=ignore_systemd)
@staticmethod
def get_cgroup_mode(config):
pass
@staticmethod
- def __cgexec_infinite_loop(config, controller, cgname, sleep_time=1):
+ def __cgexec_infinite_loop(config, controller, cgname, sleep_time=1, ignore_systemd=False):
cmd = ["/usr/bin/perl",
"-e",
"'while(1){{sleep({})}};'".format(sleep_time)
]
try:
- Cgroup.cgexec(config, controller, cgname, cmd)
+ Cgroup.cgexec(config, controller, cgname, cmd, ignore_systemd=ignore_systemd)
except RunError:
# When this process is killed, it will throw a run error.
# Ignore it.
# Create a simple process in the requested cgroup
def create_process_in_cgroup(self, config, controller, cgname,
- cgclassify=True):
+ cgclassify=True, ignore_systemd=False):
if cgclassify:
child_pid = self.create_process(config)
- Cgroup.classify(config, controller, cgname, child_pid)
+ Cgroup.classify(config, controller, cgname, child_pid, ignore_systemd=ignore_systemd)
else:
# use cgexec
sleep_time = len(self.children) + 1
p = mp.Process(target=Process.__cgexec_infinite_loop,
- args=(config, controller, cgname, sleep_time, ))
+ args=(config, controller, cgname, sleep_time, ignore_systemd, ))
p.start()
self.children.append(p)
thread.start()
def create_threaded_process_in_cgroup(self, config, controller, cgname,
- threads=2, cgclassify=True):
+ threads=2, cgclassify=True, ignore_systemd=False):
p = mp.Process(target=self.create_threaded_process,
args=(config, threads, ))
p.start()
if cgclassify:
- Cgroup.classify(config, controller, cgname, p.pid)
+ Cgroup.classify(config, controller, cgname, p.pid, ignore_systemd=ignore_systemd)
self.children.append(p)
self.children_pids.append(p.pid)