From 42e9e82af5406f77f2260e2fee01fc091cff439a Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 26 Oct 2022 10:18:04 -0600 Subject: [PATCH] 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 --- tests/ftests/systemd.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/ftests/systemd.py 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 -- 2.47.2