From: Tom Hromatka Date: Wed, 26 Oct 2022 16:18:04 +0000 (-0600) Subject: ftests: Add systemd class X-Git-Tag: v3.1.0~270 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42e9e82af5406f77f2260e2fee01fc091cff439a;p=thirdparty%2Flibcgroup.git ftests: Add systemd class 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 Reviewed-by: Kamalesh Babulal --- diff --git a/tests/ftests/systemd.py b/tests/ftests/systemd.py new file mode 100644 index 00000000..e2388c9d --- /dev/null +++ b/tests/ftests/systemd.py @@ -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 +# + +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