]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add recursive cgdelete function test on shared mount
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 24 Jan 2023 19:43:20 +0000 (12:43 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 24 Jan 2023 19:43:30 +0000 (12:43 -0700)
Add a test that tries deleting non-existing cgroups on shared mount
mount shared by controllers on cgroup v1.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Jan 23 09:21:48
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                                  Time (sec)
        ----------------------------------------------------------------
        setup                                                       0.00
        098-cgdelete-non-existing-shared-mnt-cgroup-v1.py           0.03
        teardown                                                    0.00
        ----------------------------------------------------------------
        Total Run Time                                              0.03

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Fix minor variable name typo.  Also, add the new test to the EXTRA
     DIST list in Makefile.am
(cherry picked from commit 01fc4107de92ea2818de82399cae41ded527addf)

tests/ftests/098-cgdelete-non-existing-shared-mnt-cgroup-v1.py [new file with mode: 0755]
tests/ftests/Makefile.am

diff --git a/tests/ftests/098-cgdelete-non-existing-shared-mnt-cgroup-v1.py b/tests/ftests/098-cgdelete-non-existing-shared-mnt-cgroup-v1.py
new file mode 100755 (executable)
index 0000000..7a96905
--- /dev/null
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# Cgroup recursive cgdelete functionality test for shared mount point on cgroup v1
+#
+# Copyright (c) 2023 Oracle and/or its affiliates.
+# Author: Kamalesh Babulal <kamalesh.babulal@oracle.com>
+#
+
+from cgroup import CgroupVersion, Cgroup
+from run import RunError
+import consts
+import ftests
+import sys
+import os
+
+CONTROLLER = 'cpu'
+CGNAME = 'test'
+
+expected_err = "cgdelete: cannot remove group '%s': No such file or directory" % CGNAME
+
+
+def prereqs(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    if CgroupVersion.get_version('cpu') != CgroupVersion.CGROUP_V1:
+        result = consts.TEST_SKIPPED
+        cause = 'This test requires the cgroup v1 cpu controller'
+        return result, cause
+
+    # cpuacct controller is only available on cgroup v1, if an exception
+    # gets raised, then no cgroup v1 controllers are mounted.
+    try:
+        CgroupVersion.get_version('cpuacct')
+    except IndexError:
+        result = consts.TEST_SKIPPED
+        cause = 'This test requires the cgroup v1 cpuacct controller'
+
+    return result, cause
+
+
+def setup(config):
+    return consts.TEST_PASSED, None
+
+
+def test(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    try:
+        Cgroup.delete(config, CONTROLLER, CGNAME)
+    except RunError as re:
+        if expected_err not in re.stderr and re.ret != 82:
+            result = consts.TEST_FAILED
+            cause = 'Expected {}'.format(expected_err)
+            return result, cause
+
+    try:
+        Cgroup.delete(config, CONTROLLER, CGNAME, recursive=True)
+    except RunError as re:
+        if expected_err not in re.stderr and re.ret != 82:
+            result = consts.TEST_FAILED
+            cause = 'Expected {}'.format(expected_err)
+
+    return result, cause
+
+
+def teardown(config):
+    return consts.TEST_PASSED, None
+
+
+def main(config):
+    [result, cause] = prereqs(config)
+    if result != consts.TEST_PASSED:
+        return [result, cause]
+
+    try:
+        result = consts.TEST_FAILED
+        setup(config)
+        [result, cause] = test(config)
+    finally:
+        teardown(config)
+
+    return [result, cause]
+
+
+if __name__ == '__main__':
+    config = ftests.parse_args()
+    # this test was invoked directly.  run only it
+    config.args.num = int(os.path.basename(__file__).split('-')[0])
+    sys.exit(ftests.main(config))
+
+# vim: set et ts=4 sw=4:
index 00eb261057c948fb7d3e39bafb818826f9a4c03b..8e53760a68449434a94c734c26a3423543491e83 100644 (file)
@@ -71,7 +71,8 @@ EXTRA_DIST_PYTHON_TESTS = \
                          048-pybindings-get_cgroup_mode.py \
                          049-sudo-systemd_create_scope.py \
                          050-sudo-systemd_create_scope2.py \
-                         051-sudo-cgroup_get_cgroup.py
+                         051-sudo-cgroup_get_cgroup.py \
+                         098-cgdelete-non-existing-shared-mnt-cgroup-v1.py
 # Intentionally omit the stress test from the extra dist
 # 999-stress-cgroup_init.py