Skip to content

Commit

Permalink
Extend list of valid suffixes for systemd units
Browse files Browse the repository at this point in the history
The old implementation limits the usage of SystemdService.is_valid() to
".service" units. This implementation allows checking all types of unit
files with is_valid() (systemd-analyze verify <unitname.suffix>).
  • Loading branch information
CarstenGrohmann authored and philpep committed Nov 13, 2023
1 parent 2f78038 commit 5d5c51f
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions testinfra/modules/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,32 @@ def is_enabled(self):


class SystemdService(SysvService):
suffix_list = [
"service",
"socket",
"device",
"mount",
"automount",
"swap",
"target",
"path",
"timer",
"slice",
"scope",
]
"""
List of valid suffixes for systemd unit files
See systemd.unit(5) for more details
"""

def _has_systemd_suffix(self):
"""
Check if service name has a known systemd unit suffix
"""
unit_suffix = self.name.split(".")[-1]
return unit_suffix in self.suffix_list

@property
def is_running(self):
out = self.run_expect([0, 1, 3], "systemctl is-active %s", self.name)
Expand All @@ -164,8 +190,8 @@ def is_enabled(self):

@property
def is_valid(self):
# systemd-analyze requires a full path.
if self.name.endswith(".service"):
# systemd-analyze requires a full unit name.
if self._has_systemd_suffix():
name = self.name
else:
name = self.name + ".service"
Expand Down

0 comments on commit 5d5c51f

Please sign in to comment.