Skip to content
Snippets Groups Projects
Commit d82b99a7 authored by Corné Lukken's avatar Corné Lukken
Browse files

L2SS-1741: Prevent bypassing state checks in async devices

parent 5bd0d41f
Branches
No related tags found
1 merge request!846L2SS-1741: Prevent bypassing state checks in async devices
...@@ -45,10 +45,7 @@ from tangostationcontrol.common.lofar_logging import ( ...@@ -45,10 +45,7 @@ from tangostationcontrol.common.lofar_logging import (
device_logging_to_python, device_logging_to_python,
) )
from tangostationcontrol.common.proxy import create_device_proxy from tangostationcontrol.common.proxy import create_device_proxy
from tangostationcontrol.common.states import ( from tangostationcontrol.common.states import DEFAULT_COMMAND_STATES
DEFAULT_COMMAND_STATES,
INITIALISED_STATES,
)
from tangostationcontrol.common.type_checking import sequence_not_str from tangostationcontrol.common.type_checking import sequence_not_str
from tangostationcontrol.devices.base_device_classes.control_hierarchy import ( from tangostationcontrol.devices.base_device_classes.control_hierarchy import (
ControlHierarchyDevice, ControlHierarchyDevice,
...@@ -220,7 +217,7 @@ class LOFARDevice(Device): ...@@ -220,7 +217,7 @@ class LOFARDevice(Device):
def is_attribute_access_allowed(self, req_type: AttReqType): def is_attribute_access_allowed(self, req_type: AttReqType):
"""Returns whether an attribute wrapped by the AttributeWrapper be accessed.""" """Returns whether an attribute wrapped by the AttributeWrapper be accessed."""
return self.get_state() in INITIALISED_STATES return self.get_state() in DEFAULT_COMMAND_STATES
# TODO(Corne): Actually implement locking in L2SS-940 # TODO(Corne): Actually implement locking in L2SS-940
def atomic_read_modify_write_attribute( def atomic_read_modify_write_attribute(
...@@ -405,6 +402,7 @@ class LOFARDevice(Device): ...@@ -405,6 +402,7 @@ class LOFARDevice(Device):
# Commands # Commands
# -------- # --------
@only_in_states([DevState.OFF])
def _Initialise(self): def _Initialise(self):
""" """
Command to ask for initialisation of this device. Can only be called in OFF state. Command to ask for initialisation of this device. Can only be called in OFF state.
...@@ -443,11 +441,11 @@ class LOFARDevice(Device): ...@@ -443,11 +441,11 @@ class LOFARDevice(Device):
@command() @command()
@debugit() @debugit()
@log_exceptions() @log_exceptions()
@only_in_states([DevState.OFF])
@fault_on_error() @fault_on_error()
def Initialise(self): def Initialise(self):
self._Initialise() self._Initialise()
@only_in_states(DEFAULT_COMMAND_STATES)
def _On(self): def _On(self):
if self.get_state() == DevState.ON: if self.get_state() == DevState.ON:
# Already on. Don't complain. # Already on. Don't complain.
...@@ -462,7 +460,6 @@ class LOFARDevice(Device): ...@@ -462,7 +460,6 @@ class LOFARDevice(Device):
@command() @command()
@debugit() @debugit()
@log_exceptions() @log_exceptions()
@only_in_states(INITIALISED_STATES)
@fault_on_error() @fault_on_error()
def On(self): def On(self):
""" """
...@@ -658,7 +655,6 @@ class LOFARDevice(Device): ...@@ -658,7 +655,6 @@ class LOFARDevice(Device):
f"Cannot assign default to attribute {attribute}" f"Cannot assign default to attribute {attribute}"
) from _e ) from _e
@only_in_states(INITIALISED_STATES)
@command() @command()
@debugit() @debugit()
@log_exceptions() @log_exceptions()
...@@ -668,7 +664,6 @@ class LOFARDevice(Device): ...@@ -668,7 +664,6 @@ class LOFARDevice(Device):
# This is just the command version of _prepare_hardware(). # This is just the command version of _prepare_hardware().
self._power_hardware_on() self._power_hardware_on()
@only_in_states(INITIALISED_STATES)
@command() @command()
@debugit() @debugit()
@log_exceptions() @log_exceptions()
...@@ -698,6 +693,7 @@ class LOFARDevice(Device): ...@@ -698,6 +693,7 @@ class LOFARDevice(Device):
restart_python() restart_python()
logger.error("Failed to restart Device Server") logger.error("Failed to restart Device Server")
@only_in_states([DevState.OFF])
def _boot(self): def _boot(self):
# setup connections # setup connections
self._Initialise() self._Initialise()
...@@ -708,7 +704,6 @@ class LOFARDevice(Device): ...@@ -708,7 +704,6 @@ class LOFARDevice(Device):
# make device available # make device available
self._On() self._On()
@only_in_states([DevState.OFF])
@command() @command()
def boot(self): def boot(self):
self._boot() self._boot()
...@@ -720,6 +715,7 @@ class LOFARDevice(Device): ...@@ -720,6 +715,7 @@ class LOFARDevice(Device):
before configuring the hardware.""" before configuring the hardware."""
pass pass
@only_in_states(DEFAULT_COMMAND_STATES)
def _power_hardware_off(self): def _power_hardware_off(self):
"""Override this method to disable any hardware related to the device.""" """Override this method to disable any hardware related to the device."""
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment