diff --git a/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py b/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py index 86298311c3247eef342becd6d2679c8cea41e6a8..82b8759b076761aa15e0b553d24356c929742fd9 100644 --- a/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py +++ b/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py @@ -150,7 +150,7 @@ class CustomCollector(object): # obtain extended info about all attributes attr_infos = {attr_info.name: attr_info for attr_info in dev.attribute_list_query()} - if dev.state() not in [DevState.STANDBY, DevState.ON, DevState.ALARM]: + if dev.state() not in [DevState.STANDBY, DevState.ON, DevState.ALARM, DevState.DISABLE]: logger.error(f"Error processing device {device_name}: it is in state {dev.state()}") # at least log state & status diff --git a/tangostationcontrol/docs/source/devices/using.rst b/tangostationcontrol/docs/source/devices/using.rst index 6eff9278eb74fc06a66b0d5b90f09d4f58eb0008..800696473ef7d9dc05c7d3cc895ee0d6b7457317 100644 --- a/tangostationcontrol/docs/source/devices/using.rst +++ b/tangostationcontrol/docs/source/devices/using.rst @@ -22,7 +22,8 @@ The state of a device is then queried with ``device.state()``. Each device can b - ``DevState.STANDBY``: The device is initialised and ready to be configured further, - ``DevState.ON``: The device is operational, - ``DevState.ALARM``: The device is operational, but one or more attributes are in alarm, -- ``DevState.FAULT``: The device is malfunctioning. Functionality cannot be counted on. +- ``DevState.FAULT``: The device is malfunctioning. Functionality cannot be counted on, +- ``DevState.DISABLE``: The device is not operating because its hardware has been shut down. - The ``device.state()`` function can throw an error, if the device cannot be reached at all. For example, because it's docker container is not running. See the :ref:`docker` device on how to start it. @@ -49,6 +50,9 @@ The state of a device is then queried with ``device.state()``. Each device can b alarm -> fault [label = "device", color="green"]; fault -> init [label = "user", color="red"]; fault -> off [label = "user", color="red"]; + standby -> disable [label = "user", color="green"]; + on -> disable [label = "user", color="green"]; + alarm -> disable [label = "user", color="green"]; } @@ -58,6 +62,8 @@ Each device provides the following commands to change the state: :warm_boot(): Turn on the device, but do not change the hardware. Moves from ``OFF`` to ``ON``. +:disable_hardware(): Shut down the hardware related to the device. Moves from ``STANDBY``, ``ON`` or ``ALARN`` to ``DISABLE`` + :off(): Turn the device ``OFF`` from any state. The following procedure is a good way to bring a device to ``ON`` from any state:: diff --git a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py index 0cc6fa0bbdafb6ae9ca6c424b4bee0930b1d3ba2..5f58131c9fce2a41c3cfaa6a2aa0b3fbf1b826e1 100644 --- a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py @@ -44,18 +44,22 @@ class lofar_device(Device, metaclass=DeviceMeta): ON = Device is fully configured, functional, controls the hardware, and is possibly actively running, ALARM = Device is operating but one of its attributes is out of range, FAULT = Device detected an unrecoverable error, and is thus malfunctional, + DISABLE = Device has shut down all its dependant hardware OFF = Device is turned off, drops connection to the hardware, The following state transitions are implemented: - boot -> OFF: Triggered by tango. Device will be instantiated, - OFF -> INIT: Triggered by device. Device will initialise (connect to hardware, other devices), - INIT -> STANDBY: Triggered by device. Device is initialised, and is ready for additional configuration by the user, - STANDBY -> ON: Triggered by user. Device reports to be functional, - ON -> ALARM: Triggered by tango. Device has attribute(s) with value(s) exceeding their alarm treshold, - * -> FAULT: Triggered by device. Device has degraded to malfunctional, for example because the connection to the hardware is lost, - * -> FAULT: Triggered by user. Emulate a forced malfunction for integration testing purposes, - * -> OFF: Triggered by user. Device is turned off. Triggered by the Off() command, - FAULT -> INIT: Triggered by user. Device is reinitialised to recover from an error, + boot -> OFF: Triggered by tango. Device will be instantiated, + OFF -> INIT: Triggered by device. Device will initialise (connect to hardware, other devices), + INIT -> STANDBY: Triggered by device. Device is initialised, and is ready for additional configuration by the user, + STANDBY -> ON: Triggered by user. Device reports to be functional, + STANDBY -> DISABLE: Triggered by user. Device has shut down its hardware. Triggered by the disable_hardware() command, + ON -> DISABLE: Triggered by user. Device has shut down its hardware. Triggered by the disable_hardware() command, + ALARM -> DISABLE: Triggered by user. Device has shut down its hardware. Triggered by the disable_hardware() command, + ON -> ALARM: Triggered by tango. Device has attribute(s) with value(s) exceeding their alarm treshold, + * -> FAULT: Triggered by device. Device has degraded to malfunctional, for example because the connection to the hardware is lost, + * -> FAULT: Triggered by user. Emulate a forced malfunction for integration testing purposes, + * -> OFF: Triggered by user. Device is turned off. Triggered by the Off() command, + FAULT -> INIT: Triggered by user. Device is reinitialised to recover from an error, The user triggers their transitions by the commands reflecting the target state (Initialise(), On(), Fault()). """ @@ -66,7 +70,7 @@ class lofar_device(Device, metaclass=DeviceMeta): # States in which Initialise() has happened, and the hardware # can thus be configured or otherwise interacted with. - INITIALISED_STATES = OPERATIONAL_STATES + [DevState.STANDBY] + INITIALISED_STATES = OPERATIONAL_STATES + [DevState.STANDBY, DevState.DISABLE] # States in which most commands are allowed DEFAULT_COMMAND_STATES = INITIALISED_STATES @@ -348,6 +352,24 @@ class lofar_device(Device, metaclass=DeviceMeta): # This is just the command version of _initialise_hardware(). self._initialise_hardware() + @only_in_states(INITIALISED_STATES) + @fault_on_error() + @command() + @DebugIt() + def disable_hardware(self): + """ Disable the hardware related to the device. """ + + if self.get_state() == DevState.DISABLE: + # Already disabled. + logger.warning("Requested to go to DISABLE state, but am already in DISABLE state.") + return + + self._disable_hardware() + + # Set state to DISABLE + self.set_state(DevState.DISABLE) + self.set_status("Device is in the DISABLE state.") + @only_in_states(DEFAULT_COMMAND_STATES) @command(dtype_out = DevDouble) def max_archiving_load(self): @@ -397,6 +419,10 @@ class lofar_device(Device, metaclass=DeviceMeta): """ Override this method to initialise any hardware after configuring it. """ pass + def _disable_hardware(self): + """ Override this method to disable any hardware related to the device. """ + pass + def read_attribute(self, attr_name): """ Read the value of a certain attribute (directly from the hardware). """ diff --git a/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py b/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py index d97cf7b9ebc6625cf9568fb2db24cab4edd51bc7..38d599f9f780cccd2d506a588ae8a2596f5f5ff8 100644 --- a/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py +++ b/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py @@ -9,6 +9,7 @@ from tango.test_context import DeviceTestContext from tango.server import attribute +from tango import DevState, DevFailed from tangostationcontrol.devices import lofar_device @@ -45,4 +46,23 @@ class TestLofarDevice(device_base.DeviceTestCase): proxy.initialise() self.assertEqual(42.0, proxy.read_attribute_A) self.assertListEqual([42.0, 43.0], proxy.read_attribute_B_array.tolist()) + + def test_disable_state(self): + with DeviceTestContext(lofar_device.lofar_device, process=True, timeout=10) as proxy: + proxy.initialise() + self.assertEqual(DevState.STANDBY, proxy.state()) + proxy.on() + self.assertEqual(DevState.ON, proxy.state()) + proxy.disable_hardware() + self.assertEqual(DevState.DISABLE, proxy.state()) + + def test_disable_state_transitions(self): + with DeviceTestContext(lofar_device.lofar_device, process=True, timeout=10) as proxy: + proxy.off() + with self.assertRaises(DevFailed): + proxy.disable_hardware() + proxy.warm_boot() + proxy.Fault() + with self.assertRaises(DevFailed): + proxy.disable_hardware() diff --git a/tangostationcontrol/tox.ini b/tangostationcontrol/tox.ini index 62b18988c5b4289ae1c12b3283d7e1b4b52fd8f7..79a80d3cca9b6c59db2908f81da1141d9a076268 100644 --- a/tangostationcontrol/tox.ini +++ b/tangostationcontrol/tox.ini @@ -77,5 +77,5 @@ commands = [flake8] filename = *.py,.stestr.conf,.txt -ignore = B014, B019, W291, W293, W391, E111, E114, E121, E122, E123, E124, E126, E127, E128, E131, E201, E201, E202, E203, E221, E222, E225, E226, E231, E241, E251, E252, E261, E262, E265, E271, E301, E302, E303, E305, E306, E401, E402, E501, E502, E701, E712, E721, E731, F403, F523, F541, F841, H301, H306, H401, H403, H404, H405, W503 +ignore = B014, B019, B023, W291, W293, W391, E111, E114, E121, E122, E123, E124, E126, E127, E128, E131, E201, E201, E202, E203, E221, E222, E225, E226, E231, E241, E251, E252, E261, E262, E265, E271, E301, E302, E303, E305, E306, E401, E402, E501, E502, E701, E712, E721, E731, F403, F523, F541, F841, H301, H306, H401, H403, H404, H405, W503 exclude=.tox,.egg-info,libhdbpp-python, SNMP_mib_loading