]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Add systemd class
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 26 Oct 2022 16:18:04 +0000 (10:18 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 1 Nov 2022 21:21:00 +0000 (15:21 -0600)
Add a class for managing interactions with systemd.  Currently it
only has a method for determining whether a scope is delegated or
not.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
tests/ftests/systemd.py [new file with mode: 0644]

diff --git a/tests/ftests/systemd.py b/tests/ftests/systemd.py
new file mode 100644 (file)
index 0000000..e2388c9
--- /dev/null
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# Systemd class for the libcgroup functional tests
+#
+# Copyright (c) 2022 Oracle and/or its affiliates.
+# Author: Tom Hromatka <tom.hromatka@oracle.com>
+#
+
+from run import Run, RunError
+
+
+class Systemd(object):
+    @staticmethod
+    def is_delegated(config, scope_name):
+        cmd = ['systemctl', 'show', '-P', 'Delegate', scope_name]
+        try:
+            out = Run.run(cmd, shell_bool=True)
+
+            if out == 'yes':
+                return True
+            else:
+                return False
+        except RunError as re:
+            if re.stderr.find('invalid option') >= 0:
+                # This version of systemd is too old for the '-P' flag.  At this time, I don't
+                # think there's a way to verify the scope is delegated.  Lie and return true
+                # until we figure out something better :(
+                return True
+            raise re