Skip to content

Commit 43db55f

Browse files
monkutaYour NameKarolinaPomian
authored
Test: Mtl Manager fixture (#408)
* Test: Mtl Manager fixture * removed unnecessary pass * set the autouse parameter to True --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: KarolinaPomian <[email protected]>
1 parent 3a46b35 commit 43db55f

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

tests/validation/common/mtl_manager/__init__.py

Whitespace-only changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import logging
2+
3+
from mfd_connect.exceptions import ConnectionCalledProcessError
4+
5+
logger = logging.getLogger(__name__)
6+
7+
8+
class MtlManager:
9+
"""
10+
Class to manage the lifecycle of the MtlManager process on a remote host.
11+
12+
Attributes:
13+
host: Host object containing a .connection attribute for remote command execution.
14+
mtl_manager_process: The running MtlManager process object (if started).
15+
"""
16+
17+
def __init__(self, host):
18+
"""
19+
Initialize the MtlManager with a host object.
20+
:param host: Host object with a .connection attribute.
21+
"""
22+
self.host = host
23+
self.cmd = "sudo MtlManager"
24+
self.mtl_manager_process = None
25+
26+
def start(self):
27+
"""
28+
Starts the MtlManager process on the remote host using sudo.
29+
Returns True if started successfully, False otherwise.
30+
"""
31+
if not self.mtl_manager_process or not self.mtl_manager_process.running:
32+
connection = self.host.connection
33+
try:
34+
logger.info(f"Running command on host {self.host.name}: {self.cmd}")
35+
self.mtl_manager_process = connection.start_process(
36+
self.cmd, stderr_to_stdout=True
37+
)
38+
39+
if not self.mtl_manager_process.running:
40+
err = self.mtl_manager_process.stderr_text
41+
logger.error(f"MtlManager failed to start. Error output:\n{err}")
42+
return False
43+
logger.info(
44+
f"MtlManager started with PID {self.mtl_manager_process.pid}."
45+
)
46+
return True
47+
except ConnectionCalledProcessError as e:
48+
logger.error(f"Failed to start MtlManager: {e}")
49+
return False
50+
else:
51+
logger.info("MtlManager is already running.")
52+
return True
53+
54+
def stop(self):
55+
"""
56+
Stops all MtlManager processes on the remote host using sudo pkill.
57+
"""
58+
connection = self.host.connection
59+
try:
60+
logger.info("Stopping MtlManager using sudo pkill MtlManager...")
61+
connection.execute_command("sudo pkill MtlManager")
62+
logger.info("MtlManager stopped (via pkill).")
63+
except ConnectionCalledProcessError as e:
64+
logger.error(f"Failed to stop MtlManager: {e}")

tests/validation/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
import pytest
1717

18+
from common.mtl_manager.mtlManager import MtlManager
1819
from common.nicctl import Nicctl
1920
from Engine.const import (
2021
ALLOWED_FFMPEG_VERSIONS,
@@ -280,6 +281,22 @@ def media_config(hosts: dict) -> None:
280281
)
281282

282283

284+
@pytest.fixture(scope="session", autouse=True)
285+
def mtl_manager(hosts):
286+
"""
287+
Automatically start MtlManager on all hosts at the beginning of the test session,
288+
and stop it at the end.
289+
"""
290+
managers = {}
291+
for host in hosts.values():
292+
mgr = MtlManager(host)
293+
mgr.start()
294+
managers[host.name] = mgr
295+
yield managers
296+
for mgr in managers.values():
297+
mgr.stop()
298+
299+
283300
@pytest.fixture(scope="session", autouse=True)
284301
def cleanup_processes(hosts: dict) -> None:
285302
"""

0 commit comments

Comments
 (0)