Skip to content

Commit

Permalink
DAOS-16460 test: Improve get_service_file() (#15116)
Browse files Browse the repository at this point in the history
Handle unexpected output when parsing the systemctl service file.

Signed-off-by: Phil Henderson <[email protected]>
  • Loading branch information
phender authored Sep 11, 2024
1 parent 226e283 commit e56eb73
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/tests/ftest/util/systemctl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import getpass
import os
import re
import tempfile

from ClusterShell.NodeSet import NodeSet
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e56eb73

Please sign in to comment.