]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: update test to check for ctrl name in scope name
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Sun, 20 Aug 2023 05:42:47 +0000 (11:12 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 30 Aug 2023 20:32:55 +0000 (14:32 -0600)
Update the test case to check for controller names in the scope name.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Aug 18 07:57:32
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                   Time (sec)
        -------------------------------------------------
        setup                                        0.00
        078-sudo-cgcreate_systemd_scope.py           5.28
        teardown                                     0.00
        -------------------------------------------------
        Total Run Time                               5.28

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tests/ftests/078-sudo-cgcreate_systemd_scope.py

index 48897d567b71abc357a96fb8463fff25f7137167..5fc4df3f172a2c406ca3510b6306a04fc47237a5 100755 (executable)
@@ -22,6 +22,7 @@ SLICE = 'libcgroup.slice'
 CGNAME = os.path.join(SLICE, '078cgcreate.scope')
 IN_SCOPE_CHILD_CGNAME = os.path.join(CGNAME, 'in_scope_childcg')
 OUT_OF_SCOPE_CHILD_CGNAME = '078outofscopechild'
+INVAL_CGNAME = os.path.join(SLICE, 'cpu.scope')
 
 
 def prereqs(config):
@@ -66,6 +67,15 @@ def test(config):
     Cgroup.create_and_validate(config, None, IN_SCOPE_CHILD_CGNAME)
     Cgroup.create_and_validate(config, None, OUT_OF_SCOPE_CHILD_CGNAME)
 
+    try:
+        Cgroup.create_and_validate(config, CONTROLLERS, INVAL_CGNAME, create_scope=True)
+    except RunError as re:
+        if 'Invalid scope name, using controller name cpu' not in str(re):
+            raise re
+    else:
+        result = consts.TEST_FAILED
+        cause = 'Erroneously succeeded in creating scope {}', format(INVAL_CGNAME)
+
     return result, cause
 
 
@@ -77,6 +87,14 @@ def teardown(config):
                          print_headers=False, values_only=True, ignore_systemd=True))
     Process.kill(config, pid)
 
+    # try deleting INVAL_CGNAME for the cases, where it was erroneously created.
+    try:
+        pid = int(Cgroup.get(config, None, INVAL_CGNAME, setting='cgroup.procs',
+                             print_headers=False, values_only=True, ignore_systemd=True))
+        Process.kill(config, pid)
+    except RunError:
+        pass
+
     # systemd will automatically remove the cgroup once there are no more pids in
     # the cgroup, so we don't need to delete CGNAME.  But let's try to remove the
     # slice