Skip to content
Snippets Groups Projects
Unverified Commit 6b507218 authored by SKAJohanVenter's avatar SKAJohanVenter
Browse files

SAR-276 Removed Tango layer allowed checks. Calling is_allowed with...

SAR-276 Removed Tango layer allowed checks. Calling is_allowed with raise_if_disallowed=True if that is in the signature
parent fece502b
No related branches found
No related tags found
No related merge requests found
...@@ -1236,17 +1236,6 @@ class SKABaseDevice(Device): ...@@ -1236,17 +1236,6 @@ class SKABaseDevice(Device):
self.logger.info(message) self.logger.info(message)
return (ResultCode.OK, 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( @command(
dtype_out="DevVarLongStringArray", dtype_out="DevVarLongStringArray",
doc_out="(ReturnType, 'informational message')", doc_out="(ReturnType, 'informational message')",
...@@ -1304,18 +1293,6 @@ class SKABaseDevice(Device): ...@@ -1304,18 +1293,6 @@ class SKABaseDevice(Device):
self.logger.info(message) self.logger.info(message)
return (ResultCode.OK, 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( @command(
dtype_out="DevVarLongStringArray", dtype_out="DevVarLongStringArray",
doc_out="(ReturnType, 'informational message')", doc_out="(ReturnType, 'informational message')",
...@@ -1373,18 +1350,6 @@ class SKABaseDevice(Device): ...@@ -1373,18 +1350,6 @@ class SKABaseDevice(Device):
self.logger.info(message) self.logger.info(message)
return (ResultCode.OK, 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( @command(
dtype_out="DevVarLongStringArray", dtype_out="DevVarLongStringArray",
doc_out="(ReturnType, 'informational message')", doc_out="(ReturnType, 'informational message')",
...@@ -1442,19 +1407,6 @@ class SKABaseDevice(Device): ...@@ -1442,19 +1407,6 @@ class SKABaseDevice(Device):
self.logger.info(message) self.logger.info(message)
return (ResultCode.OK, 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( @command(
dtype_out="DevVarLongStringArray", dtype_out="DevVarLongStringArray",
doc_out="(ReturnType, 'informational message')", doc_out="(ReturnType, 'informational message')",
...@@ -1536,9 +1488,9 @@ class SKABaseDevice(Device): ...@@ -1536,9 +1488,9 @@ class SKABaseDevice(Device):
:param argin: The command ID :param argin: The command ID
:type argin: str :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 :rtype: tuple
(ResultCode.OK, TaskState) (ResultCode.OK, str)
""" """
result = self.target.get_task_state(argin) result = self.target.get_task_state(argin)
return (ResultCode.OK, f"{result}") return (ResultCode.OK, f"{result}")
......
...@@ -116,6 +116,7 @@ from uuid import uuid4 ...@@ -116,6 +116,7 @@ from uuid import uuid4
from queue import Empty, Queue from queue import Empty, Queue
from datetime import datetime from datetime import datetime
from threading import Event from threading import Event
from inspect import signature
from typing import Any, Callable, Dict, Optional, Tuple, Union from typing import Any, Callable, Dict, Optional, Tuple, Union
import tango import tango
...@@ -380,7 +381,12 @@ class QueueManager: ...@@ -380,7 +381,12 @@ class QueueManager:
""" """
try: try:
if hasattr(task, "is_allowed"): 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( return TaskResult(
ResultCode.NOT_ALLOWED, "Command not allowed", unique_id ResultCode.NOT_ALLOWED, "Command not allowed", unique_id
) )
......
...@@ -455,8 +455,12 @@ class TestSKABaseDevice(object): ...@@ -455,8 +455,12 @@ class TestSKABaseDevice(object):
# PROTECTED REGION ID(SKABaseDevice.test_Reset) ENABLED START # # PROTECTED REGION ID(SKABaseDevice.test_Reset) ENABLED START #
# The main test of this command is # The main test of this command is
# TestSKABaseDevice_commands::test_ResetCommand # 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 # PROTECTED REGION END # // SKABaseDevice.test_Reset
def test_On(self, device_under_test, tango_change_event_helper): def test_On(self, device_under_test, tango_change_event_helper):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment