]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tests/ftest: use string filter() to concatenation cause
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 23 Feb 2023 13:45:54 +0000 (13:45 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 23 Feb 2023 17:27:56 +0000 (10:27 -0700)
if, then, else construction is used to concatenate the 'cause' string,
that appends the reason for the test failures.  The reason to use the
checks to TypeError that occurs while concatenating None and str type.
Replace them with a one-liner string.filter(), across the test sources.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 5d4bd5c2532a7ffdbf0bab333dee4a9be4cb17ba)

tests/ftests/054-sudo-set_uid_gid_v2.py
tests/ftests/055-sudo-set_uid_gid_v1.py
tests/ftests/056-sudo-set_permissions_v2.py
tests/ftests/057-sudo-set_permissions_v1.py
tests/ftests/058-sudo-systemd_create_scope2.py

index 4116f34b72190da60b55828e134635fa3ffac8e8..a3794b8aa18e14fbdb2e18941934e0a9e2b860f3 100755 (executable)
@@ -59,10 +59,7 @@ def test(config):
     if gid != CTRL_GID:
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs group to be {} but it\'s {}'.format(CTRL_GID, gid)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     return result, cause
 
index 159ec50b85ba1c1e6ee2849255f2b5b6355574e9..7bfac3a60c33ad2f8c4df9b22cf9bcdbc0574db2 100755 (executable)
@@ -59,10 +59,7 @@ def test(config):
     if tasks_gid != TASKS_GID:
         result = consts.TEST_FAILED
         tmp_cause = 'Expected tasks group to be {} but it\'s {}'.format(TASKS_GID, tasks_gid)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     ctrl_path = os.path.join(CgroupCli.get_controller_mount_point(CONTROLLER), CGNAME,
                              'cgroup.procs')
@@ -71,10 +68,7 @@ def test(config):
     if ctrl_uid != CTRL_UID:
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs owner to be {} but it\'s {}'.format(CTRL_UID, ctrl_uid)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     ctrl_gid = utils.get_file_owner_gid(config, ctrl_path)
     if ctrl_gid != CTRL_GID:
index 8c21f5ee3e7db1357f4ccea61cb0fdb32035a841..93176f15e5ed063101b0017f201d2daa764e8b54 100755 (executable)
@@ -66,10 +66,7 @@ def test(config):
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs mode to be {} but it\'s {}'.format(
                     format(CTRL_MODE, '03o'), ctrl_mode)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     return result, cause
 
index 54fcb04bb9a33e9ff519d766a737c40073425e02..f87f2476ecb09da8b0e89b24068b62e925c01342 100755 (executable)
@@ -66,10 +66,7 @@ def test(config):
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs mode to be {} but it\'s {}'.format(
                     format(CTRL_MODE, '03o'), ctrl_mode)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     task_path = os.path.join(CgroupCli.get_controller_mount_point(CONTROLLER), CGNAME,
                              'tasks')
@@ -79,10 +76,7 @@ def test(config):
         result = consts.TEST_FAILED
         tmp_cause = 'Expected tasks mode to be {} but it\'s {}'.format(
                     format(TASK_MODE, '03o'), task_mode)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     return result, cause
 
index 247621b67e3378cb89ceb6bdc79c2d5031973dd7..1eee76d1c456e9e6f36fa29583ec71164a2d81cf 100755 (executable)
@@ -83,10 +83,7 @@ def test(config):
     if not CgroupCli.is_controller_enabled(config, CGNAME, CONTROLLER):
         result = consts.TEST_FAILED
         tmp_cause = 'Controller {} is not enabled in the parent cgroup'.format(CONTROLLER)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     dir_path = os.path.join(CgroupCli.get_controller_mount_point(CONTROLLER), CGNAME)
 
@@ -95,10 +92,7 @@ def test(config):
         result = consts.TEST_FAILED
         tmp_cause = 'Expected directory mode to be {} but it\'s {}'.format(
                     format(DIR_MODE, '03o'), dir_mode)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     ctrl_path = os.path.join(CgroupCli.get_controller_mount_point(CONTROLLER), CGNAME,
                              'cgroup.procs')
@@ -108,28 +102,19 @@ def test(config):
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs mode to be {} but it\'s {}'.format(
                     format(CTRL_MODE, '03o'), ctrl_mode)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     uid = utils.get_file_owner_uid(config, ctrl_path)
     if uid != CTRL_UID:
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs owner to be {} but it\'s {}'.format(CTRL_UID, uid)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     gid = utils.get_file_owner_gid(config, ctrl_path)
     if gid != CTRL_GID:
         result = consts.TEST_FAILED
         tmp_cause = 'Expected cgroup.procs group to be {} but it\'s {}'.format(CTRL_GID, gid)
-        if not cause:
-            cause = tmp_cause
-        else:
-            cause = '{}\n{}'.format(cause, tmp_cause)
+        cause = '\n'.join(filter(None, [cause, tmp_cause]))
 
     return result, cause