Skip to content

Commit

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

Skip-test: true
Skip-build: true

Signed-off-by: Phil Henderson <[email protected]>
Signed-off-by: Dalton Bohning <[email protected]>
  • Loading branch information
phender authored and daltonbohning committed Sep 17, 2024
1 parent c2651bc commit f2600a4
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 f2600a4

Please sign in to comment.