Skip to content

Commit

Permalink
Add rust_log option to service related classes
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jan 31, 2024
1 parent fdceaa9 commit 8a31d50
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/client-dbus/tests/udev/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ class _Service:
"""

# pylint: disable=consider-using-with
def start_service(self):
def start_service(self, *, rust_log=None):
"""
Starts the stratisd service if it is not already started. Verifies
that it has not exited at the time the method returns. Verifies that
the D-Bus service is available.
:param rust_log: value for RUST_LOG environment variable
:type rust_log: str or NoneType
"""

settle()
Expand All @@ -252,6 +255,7 @@ def start_service(self):

service = subprocess.Popen(
[x for x in _STRATISD.split(" ") if x != ""],
env={} if rust_log is None else {"RUST_LOG": rust_log} | os.environ,
text=True,
)

Expand Down Expand Up @@ -359,11 +363,12 @@ class ServiceContextManager:
A context manager for starting and stopping the daemon.
"""

def __init__(self):
def __init__(self, *, rust_log=None):
self._service = _Service()
self._rust_log = rust_log

def __enter__(self):
self._service.start_service()
self._service.start_service(rust_log=self._rust_log)

def __exit__(self, exc_type, exc_val, exc_tb):
self._service.stop_service()
Expand All @@ -376,13 +381,15 @@ class OptionalKeyServiceContextManager:
A service context manager that accepts an optional key
"""

def __init__(self, *, key_spec=None):
def __init__(self, *, key_spec=None, rust_log=None):
"""
Initialize a context manager with an optional list of keys
:param key_spec: Key description and data for kernel keys to be added
:type key_spec: list of (str, str) or NoneType
:param rust_log: value for RUST_LOG environment variable
:type rust_log: str or NoneType
"""
self._ctxt_manager = ServiceContextManager()
self._ctxt_manager = ServiceContextManager(rust_log=rust_log)
self._keys = KernelKey([]) if key_spec is None else KernelKey(key_spec)

def __enter__(self):
Expand Down

0 comments on commit 8a31d50

Please sign in to comment.