From e56eb733b30f154aeb2fa2a7c64135f6561061bc Mon Sep 17 00:00:00 2001 From: Phil Henderson Date: Wed, 11 Sep 2024 10:12:33 -0400 Subject: [PATCH] DAOS-16460 test: Improve get_service_file() (#15116) Handle unexpected output when parsing the systemctl service file. Signed-off-by: Phil Henderson --- src/tests/ftest/util/systemctl_utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tests/ftest/util/systemctl_utils.py b/src/tests/ftest/util/systemctl_utils.py index 848b7dc6d31..9ee809a1143 100644 --- a/src/tests/ftest/util/systemctl_utils.py +++ b/src/tests/ftest/util/systemctl_utils.py @@ -6,6 +6,7 @@ import getpass import os +import re import tempfile from ClusterShell.NodeSet import NodeSet @@ -151,17 +152,18 @@ def get_service_file(logger, hosts, service, user, verbose=True, timeout=120): str: the service file """ command = ' | '.join([ - get_systemctl_command("status", service, user), - "grep 'Loaded:'", - "grep -oE '/.*service'", - "xargs sh -c '[ -e \"$0\" ] && echo \"$0\"'" + get_systemctl_command("show", service, user), + "grep 'FragmentPath='", ]) result = run_remote(logger, hosts, command, verbose, timeout) if not result.passed: raise SystemctlFailure("Error obtaining the service file path") if not result.homogeneous: raise SystemctlFailure("Error obtaining a homogeneous service file path") - return list(result.all_stdout.values())[0].strip() + try: + return re.findall(r'FragmentPath=(.+)', result.joined_stdout)[0] + except IndexError as error: + raise SystemctlFailure("Error parsing the service file path") from error def create_override_config(logger, hosts, service, user, service_command, service_config, path,