Skip to content
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

Add more autorestart printing #413

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions BlockServer/core/ioc_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
class IocControl:
"""A class for starting, stopping and restarting IOCs"""

def __init__(self, prefix):
def __init__(self, prefix: str) -> None:
"""Constructor.

Args:
prefix (string): The PV prefix for the instrument
"""
self._proc = ProcServWrapper(prefix)

def start_ioc(self, ioc: str, restart_alarm_server: bool = True):
def start_ioc(self, ioc: str, restart_alarm_server: bool = True) -> None:
"""Start an IOC.

Args:
Expand All @@ -48,11 +48,11 @@ def start_ioc(self, ioc: str, restart_alarm_server: bool = True):
except Exception as err:
print_and_log(f"Could not start IOC {ioc}: {err}", "MAJOR")

def restart_ioc(self, ioc: str, force: bool = False, restart_alarm_server: bool = True):
def restart_ioc(self, ioc: str, force: bool = False, restart_alarm_server: bool = True) -> None:
"""Restart an IOC.

Note: restarting an IOC automatically sets the IOC to auto-restart, so it is neccessary to reapply the
previous auto-restart setting
Note: restarting an IOC automatically sets the IOC to auto-restart,
so it is neccessary to reapply the previous auto-restart setting

Args:
ioc (string): The name of the IOC
Expand All @@ -69,7 +69,7 @@ def restart_ioc(self, ioc: str, force: bool = False, restart_alarm_server: bool
except Exception as err:
print_and_log(f"Could not restart IOC {ioc}: {err}", "MAJOR")

def stop_ioc(self, ioc: str, force: bool = False):
def stop_ioc(self, ioc: str, force: bool = False) -> None:
"""Stop an IOC.

Args:
Expand All @@ -86,7 +86,7 @@ def stop_ioc(self, ioc: str, force: bool = False):
except Exception as err:
print_and_log(f"Could not stop IOC {ioc}: {err}", "MAJOR")

def get_ioc_status(self, ioc: str):
def get_ioc_status(self, ioc: str) -> str:
"""Get the running status of an IOC.

Args:
Expand All @@ -97,7 +97,7 @@ def get_ioc_status(self, ioc: str):
"""
return self._proc.get_ioc_status(ioc)

def ioc_restart_pending(self, ioc: str):
def ioc_restart_pending(self, ioc: str) -> bool:
"""Tests if the IOC has a pending restart

Args:
Expand All @@ -108,7 +108,7 @@ def ioc_restart_pending(self, ioc: str):
"""
return self._proc.ioc_restart_pending(ioc)

def start_iocs(self, iocs: List[str]):
def start_iocs(self, iocs: List[str]) -> None:
"""Start a number of IOCs.

Args:
Expand All @@ -117,7 +117,7 @@ def start_iocs(self, iocs: List[str]):
for ioc in iocs:
self.start_ioc(ioc)

def restart_iocs(self, iocs: List[str], reapply_auto: bool = False):
def restart_iocs(self, iocs: List[str], reapply_auto: bool = False) -> None:
"""Restart a number of IOCs.

Args:
Expand All @@ -135,7 +135,7 @@ def restart_iocs(self, iocs: List[str], reapply_auto: bool = False):
self.waitfor_running(ioc)
self.set_autorestart(ioc, auto[ioc])

def stop_iocs(self, iocs: List[str]):
def stop_iocs(self, iocs: List[str]) -> None:
"""Stop a number of IOCs.

Args:
Expand All @@ -156,10 +156,10 @@ def ioc_exists(self, ioc: str) -> bool:
try:
self.get_ioc_status(ioc)
return True
except:
except Exception:
return False

def set_autorestart(self, ioc: str, enable: bool):
def set_autorestart(self, ioc: str, enable: bool) -> None:
"""Used to set the auto-restart property.

Args:
Expand All @@ -172,9 +172,10 @@ def set_autorestart(self, ioc: str, enable: bool):
curr = self._proc.get_autorestart(ioc)
if curr != enable:
# If different to requested then change it
print_and_log(f"Auto-restart for IOC {ioc} not set to {enable}")
self._proc.toggle_autorestart(ioc)
return
print_and_log(f"Auto-restart for IOC {ioc} unchanged as value has not changed")
print_and_log(f"Auto-restart for IOC {ioc} is already {enable}")
else:
print_and_log(f"Auto-restart for IOC {ioc} unchanged as IOC is not running")
except Exception as err:
Expand All @@ -194,7 +195,7 @@ def get_autorestart(self, ioc: str) -> bool:
except Exception as err:
print_and_log(f"Could not get auto-restart setting for IOC {ioc}: {err}", "MAJOR")

def waitfor_running(self, ioc: str, timeout: int = 5):
def waitfor_running(self, ioc: str, timeout: int = 5) -> None:
"""Waits for the IOC to start running.

Args:
Expand Down