]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add ignore_systemd support to the CLI tools
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 10 Feb 2023 21:51:03 +0000 (14:51 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 10 Feb 2023 21:55:18 +0000 (14:55 -0700)
Add ignore_systemd support (-b flag) to the CLI tools in the functional
tests, so that the functions calling the CLI tools are aware of the
delegated systemd subtree support in the tools and switch between cgroup
controllers root and systemd subtree using -b switch.

[Kamalesh extended the -b flags to some of the CLI tools]
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 7ad92f62b9d1db753f6627cd850f07aacac36645)

tests/ftests/cgroup.py
tests/ftests/process.py

index 8e27d7f25553bcc4bd6a5f2a61b3742adc9b2899..1ff6610dabfc41781cc794a4c9ddded04a9ed061 100644 (file)
@@ -126,7 +126,8 @@ class Cgroup(object):
     @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]
 
@@ -159,6 +160,9 @@ class Cgroup(object):
         if cghelp:
             cmd.append('-h')
 
+        if ignore_systemd:
+            cmd.append('-b')
+
         if controller_list:
             controllers_and_path = '{}:{}'.format(
                 ','.join(controller_list), cgname)
@@ -174,7 +178,7 @@ class Cgroup(object):
             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]
 
@@ -196,6 +200,9 @@ class Cgroup(object):
         cmd.append('-g')
         cmd.append(controllers_and_path)
 
+        if ignore_systemd:
+            cmd.append('-b')
+
         if config.args.container:
             config.container.run(cmd)
         else:
@@ -203,7 +210,7 @@ class Cgroup(object):
 
     @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')
@@ -237,6 +244,9 @@ class Cgroup(object):
                 for cg in cgname:
                     cmd.append(cg)
 
+        if ignore_systemd:
+            cmd.append('-b')
+
         if cghelp:
             cmd.append('-h')
 
@@ -247,7 +257,7 @@ class Cgroup(object):
 
     @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
@@ -269,12 +279,12 @@ class Cgroup(object):
         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()
@@ -291,17 +301,21 @@ class Cgroup(object):
             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
@@ -354,7 +368,7 @@ class Cgroup(object):
     @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:
@@ -380,13 +394,13 @@ class Cgroup(object):
 
         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:
@@ -405,16 +419,20 @@ class Cgroup(object):
 
         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))
 
@@ -903,7 +921,7 @@ class Cgroup(object):
     # 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()
@@ -911,6 +929,10 @@ class Cgroup(object):
         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))
 
@@ -952,7 +974,7 @@ class Cgroup(object):
         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
@@ -961,22 +983,22 @@ class Cgroup(object):
         """
         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):
index c4530d225842706f96cf2ef0132d5f5f0b6bc609..a1015e627eb4dcef6c4273ae8dc0d5f0da6dcf2a 100644 (file)
@@ -51,14 +51,14 @@ class Process(object):
             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.
@@ -113,10 +113,10 @@ class Process(object):
 
     # 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
 
@@ -126,7 +126,7 @@ class Process(object):
             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)
@@ -144,14 +144,14 @@ class Process(object):
             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)