Services: Starting and Stopping System Services
SystemdServices provides interface to start,
stop, reload and manage systemd services. The state of the service is
automatically restored when a test is finished. For example if a service was
originally stopped and then started during a test, it is automatically stopped
when the test finishes.
Note
systemd must be used to manage services on the system.
See also
See the API reference of SystemdServices
for more information.
Example: Adding systemd utility to your role
from pytest_mh import MultihostHost
from pytest_mh.utils.services import SystemdServices
class ExampleRole(MultihostHost[ExampleDomain]):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.svc: SystemdServices = SystemdServices(self.host)
"""
Systemd service management.
"""
Example: Starting a systemd service
@pytest.mark.topology(...)
def test_tc(client: ClientRole):
...
client.svc.start("my-service.service")
...
Note
This service is a subclass of MultihostReentrantUtility,
therefore you can safely use it also in MultihostHost
objects, not only in MultihostRole.