From 6b50721885d913983beca86f131a6b8e8eef879a Mon Sep 17 00:00:00 2001 From: SKAJohanVenter <aventer@ska.ac.za> Date: Tue, 26 Oct 2021 16:26:40 +0200 Subject: [PATCH] SAR-276 Removed Tango layer allowed checks. Calling is_allowed with raise_if_disallowed=True if that is in the signature --- src/ska_tango_base/base/base_device.py | 52 +------------------ src/ska_tango_base/base/task_queue_manager.py | 8 ++- tests/test_base_device.py | 8 ++- 3 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/ska_tango_base/base/base_device.py b/src/ska_tango_base/base/base_device.py index b17afb58..093a7ecd 100644 --- a/src/ska_tango_base/base/base_device.py +++ b/src/ska_tango_base/base/base_device.py @@ -1236,17 +1236,6 @@ class SKABaseDevice(Device): self.logger.info(message) return (ResultCode.OK, message) - def is_Reset_allowed(self): - """ - Whether the ``Reset()`` command is allowed to be run in the current state. - - :returns: whether the ``Reset()`` command is allowed to be run in the - current state - :rtype: boolean - """ - command = self.get_command_object("Reset") - return command.is_allowed(raise_if_disallowed=True) - @command( dtype_out="DevVarLongStringArray", doc_out="(ReturnType, 'informational message')", @@ -1304,18 +1293,6 @@ class SKABaseDevice(Device): self.logger.info(message) return (ResultCode.OK, message) - def is_Standby_allowed(self): - """ - Check if command Standby is allowed in the current device state. - - :raises :py:exc:`CommandError`: if the command is not allowed - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("Standby") - return command.is_allowed(raise_if_disallowed=True) - @command( dtype_out="DevVarLongStringArray", doc_out="(ReturnType, 'informational message')", @@ -1373,18 +1350,6 @@ class SKABaseDevice(Device): self.logger.info(message) return (ResultCode.OK, message) - def is_Off_allowed(self): - """ - Check if command `Off` is allowed in the current device state. - - :raises :py:exc:`CommandError`: if the command is not allowed - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("Off") - return command.is_allowed(raise_if_disallowed=True) - @command( dtype_out="DevVarLongStringArray", doc_out="(ReturnType, 'informational message')", @@ -1442,19 +1407,6 @@ class SKABaseDevice(Device): self.logger.info(message) return (ResultCode.OK, message) - def is_On_allowed(self): - """ - Check if command `On` is allowed in the current device state. - - :raises :py:exc:`CommandError`: if the command is not - allowed - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("On") - return command.is_allowed(raise_if_disallowed=True) - @command( dtype_out="DevVarLongStringArray", doc_out="(ReturnType, 'informational message')", @@ -1536,9 +1488,9 @@ class SKABaseDevice(Device): :param argin: The command ID :type argin: str - :return: The resultcode for this command and the code for the state + :return: The resultcode for this command and the string of the TaskState :rtype: tuple - (ResultCode.OK, TaskState) + (ResultCode.OK, str) """ result = self.target.get_task_state(argin) return (ResultCode.OK, f"{result}") diff --git a/src/ska_tango_base/base/task_queue_manager.py b/src/ska_tango_base/base/task_queue_manager.py index 6ea0d5fb..dc4a3849 100644 --- a/src/ska_tango_base/base/task_queue_manager.py +++ b/src/ska_tango_base/base/task_queue_manager.py @@ -116,6 +116,7 @@ from uuid import uuid4 from queue import Empty, Queue from datetime import datetime from threading import Event +from inspect import signature from typing import Any, Callable, Dict, Optional, Tuple, Union import tango @@ -380,7 +381,12 @@ class QueueManager: """ try: if hasattr(task, "is_allowed"): - if not task.is_allowed(): + is_allowed_signature = signature(task.is_allowed) + if "raise_if_disallowed" in is_allowed_signature.parameters: + is_task_allowed = task.is_allowed(raise_if_disallowed=True) + else: + is_task_allowed = task.is_allowed() + if not is_task_allowed: return TaskResult( ResultCode.NOT_ALLOWED, "Command not allowed", unique_id ) diff --git a/tests/test_base_device.py b/tests/test_base_device.py index c16219c5..9a328bd5 100644 --- a/tests/test_base_device.py +++ b/tests/test_base_device.py @@ -455,8 +455,12 @@ class TestSKABaseDevice(object): # PROTECTED REGION ID(SKABaseDevice.test_Reset) ENABLED START # # The main test of this command is # TestSKABaseDevice_commands::test_ResetCommand - with pytest.raises(DevFailed): - device_under_test.Reset() + device_under_test.Reset() + assert f"{ResultCode.FAILED}" == device_under_test.longRunningCommandResult[1] + assert ( + "Action reset_invoked is not allowed in op_state OFF" + in device_under_test.longRunningCommandResult[2] + ) # PROTECTED REGION END # // SKABaseDevice.test_Reset def test_On(self, device_under_test, tango_change_event_helper): -- GitLab