From: Kamalesh Babulal Date: Tue, 24 Jan 2023 19:39:11 +0000 (-0700) Subject: ftests: Add recursive cgdelete function test on shared mount X-Git-Tag: v3.1.0~239 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01fc4107de92ea2818de82399cae41ded527addf;p=thirdparty%2Flibcgroup.git ftests: Add recursive cgdelete function test on shared mount 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 Signed-off-by: Tom Hromatka TJH: Fix minor variable name typo. Also, add the new test to the EXTRA DIST list in 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 index 00000000..7a969058 --- /dev/null +++ b/tests/ftests/098-cgdelete-non-existing-shared-mnt-cgroup-v1.py @@ -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 +# + +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: diff --git a/tests/ftests/Makefile.am b/tests/ftests/Makefile.am index 00eb2610..8e53760a 100644 --- a/tests/ftests/Makefile.am +++ b/tests/ftests/Makefile.am @@ -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