Skip to content

Commit 493bb1b

Browse files
linux: add systemd_unit_properties method
Allows querying systemd for specific attributes. For each property a systemctl call is issued. This is because some systemd versions mix up the order of the property values which is pretty bad for testing. Signed-off-by: Bastian Krause <[email protected]>
1 parent 6a0c746 commit 493bb1b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

labgridhelper/linux.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,18 @@ def get_hostname(command):
118118
except ExecutionError:
119119
return None
120120
return hostname_string[0]
121+
122+
def systemd_unit_properties(command, unit_properties, unit=''):
123+
"""Yields the values of the properties of a unit
124+
Args:
125+
command (CommandProtocol): An instance of a Driver implementing the CommandProtocol
126+
unit_properties (iterable): Names of the properties of interest
127+
unit (str, optional): The systemd unit of interest, defaults to empty (systemd manager itself)
128+
Yields:
129+
str: Property value of the unit
130+
"""
131+
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
132+
133+
for unit_property in unit_properties:
134+
yield command.run_check('systemctl --property={property} --no-pager --value show {unit}'.format(
135+
property=unit_property, unit=unit))[0]

0 commit comments

Comments
 (0)