-
Notifications
You must be signed in to change notification settings - Fork 72
Test: Mtl manager fixture #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0f45158
Test: Mtl Manager fixture
81792f5
added blank line
3757513
small fixes
7ad050e
blank lines
b77c90c
Merge branch 'main' into mtlManager
monkuta 35b8f48
Merge branch 'main' into mtlManager
monkuta f660adf
set the autouse parameter to True
bffebb9
Merge branch 'main' into mtlManager
monkuta 8d25829
Merge branch 'main' into mtlManager
KarolinaPomian c56e2e1
Merge branch 'main' into mtlManager
KarolinaPomian e4767c4
Enhance MtlManager stop method for graceful termination and improved …
KarolinaPomian 8cc6881
Refractor
KarolinaPomian d27b461
linter fix
KarolinaPomian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import logging | ||
|
||
from mfd_connect.exceptions import ConnectionCalledProcessError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MtlManager: | ||
""" | ||
Class to manage the lifecycle of the MtlManager process on a remote host. | ||
|
||
Attributes: | ||
host: Host object containing a .connection attribute for remote command execution. | ||
mtl_manager_process: The running MtlManager process object (if started). | ||
""" | ||
|
||
def __init__(self, host): | ||
""" | ||
Initialize the MtlManager with a host object. | ||
:param host: Host object with a .connection attribute. | ||
""" | ||
self.host = host | ||
self.cmd = None | ||
self.mtl_manager_process = None | ||
|
||
def start(self): | ||
""" | ||
Starts the MtlManager process on the remote host using sudo. | ||
Returns True if started successfully, False otherwise. | ||
""" | ||
if not self.mtl_manager_process or not self.mtl_manager_process.running: | ||
connection = self.host.connection | ||
self.cmd = "sudo MtlManager" | ||
try: | ||
logger.info(f"Running command on host {self.host.name}: {self.cmd}") | ||
self.mtl_manager_process = connection.start_process( | ||
self.cmd, stderr_to_stdout=True | ||
) | ||
|
||
if not self.mtl_manager_process.running: | ||
err = self.mtl_manager_process.stderr_text | ||
logger.error(f"MtlManager failed to start. Error output:\n{err}") | ||
return False | ||
logger.info( | ||
f"MtlManager started with PID {self.mtl_manager_process.pid}." | ||
) | ||
return True | ||
except ConnectionCalledProcessError as e: | ||
logger.error(f"Failed to start MtlManager: {e}") | ||
return False | ||
else: | ||
logger.info("MtlManager is already running.") | ||
return True | ||
|
||
def stop(self): | ||
""" | ||
Stops all MtlManager processes on the remote host using sudo pkill. | ||
""" | ||
connection = self.host.connection | ||
try: | ||
logger.info("Stopping MtlManager using sudo pkill MtlManager...") | ||
connection.execute_command("sudo pkill MtlManager") | ||
andremiszcz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logger.info("MtlManager stopped (via pkill).") | ||
except ConnectionCalledProcessError as e: | ||
logger.error(f"Failed to stop MtlManager: {e}") | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.