diff --git a/src/ska_tango_base/subarray/subarray_device.py b/src/ska_tango_base/subarray/subarray_device.py index 20e09ea9f9b26e6b99b29eb7504fe178cc0bb0f8..b24e5060bebf901c84678c22244abd04a5e98bb2 100644 --- a/src/ska_tango_base/subarray/subarray_device.py +++ b/src/ska_tango_base/subarray/subarray_device.py @@ -641,7 +641,7 @@ class SKASubarray(SKAObsDevice): dtype_in="DevString", doc_in="JSON-encoded string with the resources to add to subarray", dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def AssignResources(self, argin): @@ -654,31 +654,19 @@ class SKASubarray(SKAObsDevice): :param argin: the resources to be assigned :type argin: list of str - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ handler = self.get_command_object("AssignResources") args = json.loads(argin) unique_id, return_code = self.component_manager.enqueue(handler, args) - return [[return_code], [unique_id]] - - def is_ReleaseResources_allowed(self): - """ - Check if command `ReleaseResources` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("ReleaseResources") - return command.is_allowed(raise_if_disallowed=True) + return ([return_code], [unique_id]) @command( dtype_in="DevString", doc_in="JSON-encoded string with the resources to remove from the subarray", dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def ReleaseResources(self, argin): @@ -691,29 +679,17 @@ class SKASubarray(SKAObsDevice): :param argin: the resources to be released :type argin: list of str - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("ReleaseResources") + handler = self.get_command_object("ReleaseResources") args = json.loads(argin) - (return_code, message) = command(args) - return [[return_code], [message]] - - def is_ReleaseAllResources_allowed(self): - """ - Check if command `ReleaseAllResources` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("ReleaseAllResources") - return command.is_allowed(raise_if_disallowed=True) + unique_id, return_code = self.component_manager.enqueue(handler, args) + return ([return_code], [unique_id]) @command( dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def ReleaseAllResources(self): @@ -723,30 +699,18 @@ class SKASubarray(SKAObsDevice): To modify behaviour for this command, modify the do() method of the command class. - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) - """ - command = self.get_command_object("ReleaseAllResources") - (return_code, message) = command() - return [[return_code], [message]] - - def is_Configure_allowed(self): - """ - Check if command `Configure` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("Configure") - return command.is_allowed(raise_if_disallowed=True) + handler = self.get_command_object("ReleaseAllResources") + unique_id, return_code = self.component_manager.enqueue(handler) + return ([return_code], [unique_id]) @command( dtype_in="DevString", doc_in="JSON-encoded string with the scan configuration", dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def Configure(self, argin): @@ -759,31 +723,19 @@ class SKASubarray(SKAObsDevice): :param argin: configuration specification :type argin: string - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("Configure") + handler = self.get_command_object("Configure") args = json.loads(argin) - (return_code, message) = command(args) - return [[return_code], [message]] - - def is_Scan_allowed(self): - """ - Check if command `Scan` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("Scan") - return command.is_allowed(raise_if_disallowed=True) + unique_id, return_code = self.component_manager.enqueue(handler, args) + return ([return_code], [unique_id]) @command( dtype_in="DevString", doc_in="JSON-encoded string with the per-scan configuration", dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def Scan(self, argin): @@ -796,29 +748,17 @@ class SKASubarray(SKAObsDevice): :param argin: Information about the scan :type argin: Array of str - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("Scan") + handler = self.get_command_object("Scan") args = json.loads(argin) - (return_code, message) = command(args) - return [[return_code], [message]] - - def is_EndScan_allowed(self): - """ - Check if command `EndScan` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("EndScan") - return command.is_allowed(raise_if_disallowed=True) + unique_id, return_code = self.component_manager.enqueue(handler, args) + return ([return_code], [unique_id]) @command( dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def EndScan(self): @@ -828,28 +768,16 @@ class SKASubarray(SKAObsDevice): To modify behaviour for this command, modify the do() method of the command class. - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) - """ - command = self.get_command_object("EndScan") - (return_code, message) = command() - return [[return_code], [message]] - - def is_End_allowed(self): + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - Check if command `End` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("End") - return command.is_allowed(raise_if_disallowed=True) + handler = self.get_command_object("EndScan") + unique_id, return_code = self.component_manager.enqueue(handler) + return ([return_code], [unique_id]) @command( dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def End(self): @@ -860,28 +788,16 @@ class SKASubarray(SKAObsDevice): To modify behaviour for this command, modify the do() method of the command class. - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("End") - (return_code, message) = command() - return [[return_code], [message]] - - def is_Abort_allowed(self): - """ - Check if command `Abort` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean - """ - command = self.get_command_object("Abort") - return command.is_allowed(raise_if_disallowed=True) + handler = self.get_command_object("End") + unique_id, return_code = self.component_manager.enqueue(handler) + return ([return_code], [unique_id]) @command( dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def Abort(self): @@ -891,28 +807,16 @@ class SKASubarray(SKAObsDevice): To modify behaviour for this command, modify the do() method of the command class. - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) - """ - command = self.get_command_object("Abort") - (return_code, message) = command() - return [[return_code], [message]] - - def is_ObsReset_allowed(self): - """ - Check if command `ObsReset` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("ObsReset") - return command.is_allowed(raise_if_disallowed=True) + handler = self.get_command_object("Abort") + unique_id, return_code = self.component_manager.enqueue(handler) + return ([return_code], [unique_id]) @command( dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def ObsReset(self): @@ -922,28 +826,16 @@ class SKASubarray(SKAObsDevice): To modify behaviour for this command, modify the do() method of the command class. - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) - """ - command = self.get_command_object("ObsReset") - (return_code, message) = command() - return [[return_code], [message]] - - def is_Restart_allowed(self): - """ - Check if command `Restart` is allowed in the current device state. - - :return: ``True`` if the command is allowed - :rtype: boolean + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("Restart") - return command.is_allowed(raise_if_disallowed=True) + handler = self.get_command_object("ObsReset") + unique_id, return_code = self.component_manager.enqueue(handler) + return ([return_code], [unique_id]) @command( dtype_out="DevVarLongStringArray", - doc_out="(ReturnType, 'informational message')", + doc_out="([Command ResultCode], [Unique ID of the command])", ) @DebugIt() def Restart(self): @@ -953,14 +845,12 @@ class SKASubarray(SKAObsDevice): To modify behaviour for this command, modify the do() method of the command class. - :return: A tuple containing a return code and a string - message indicating status. The message is for - information purpose only. - :rtype: (ResultCode, str) + :return: A tuple containing a result code and the unique ID of the command + :rtype: ([ResultCode], [str]) """ - command = self.get_command_object("Restart") - (return_code, message) = command() - return [[return_code], [message]] + handler = self.get_command_object("Restart") + unique_id, return_code = self.component_manager.enqueue(handler) + return ([return_code], [unique_id]) # ---------- diff --git a/tests/test_subarray_device.py b/tests/test_subarray_device.py index c331816a1d6feb7dea9a4278b94e2dd730d126c5..95c69ed97440d29f2867cd8d9ab68eea439b2a44 100644 --- a/tests/test_subarray_device.py +++ b/tests/test_subarray_device.py @@ -96,15 +96,19 @@ class TestSKASubarray: result_callback.wait_for_lrc_id(on_tr.unique_id) result_callback.wait_for_lrc_id(assign_tr.unique_id) - device_under_test.Configure('{"BAND1": 2}') + conf_tr = device_under_test.Configure('{"BAND1": 2}') + result_callback.wait_for_lrc_id(conf_tr.unique_id) obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.READY) - assert device_under_test.Abort() == [ - [ResultCode.OK], - ["Abort command completed OK"], - ] + abort_tr = device_under_test.Abort() + result_callback.wait_for_lrc_id(abort_tr.unique_id) + assert ( + device_under_test.longRunningCommandResult[2] + == "Abort command completed OK" + ) + assert int(device_under_test.longRunningCommandResult[1]) == ResultCode.OK obs_state_callback.assert_calls([ObsState.ABORTING, ObsState.ABORTED]) # PROTECTED REGION END # // SKASubarray.test_Abort @@ -125,7 +129,8 @@ class TestSKASubarray: obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.IDLE) - device_under_test.Configure('{"BAND1": 2}') + conf_tr = device_under_test.Configure('{"BAND1": 2}') + result_callback.wait_for_lrc_id(conf_tr.unique_id) obs_state_callback.assert_calls([ObsState.CONFIGURING, ObsState.READY]) assert device_under_test.obsState == ObsState.READY @@ -192,7 +197,8 @@ class TestSKASubarray: assert device_under_test.ObsState == ObsState.IDLE assert list(device_under_test.assignedResources) == resources_to_assign - device_under_test.ReleaseAllResources() + release_tr = device_under_test.ReleaseAllResources() + result_callback.wait_for_lrc_id(release_tr.unique_id) obs_state_callback.assert_calls([ObsState.RESOURCING, ObsState.EMPTY]) assert device_under_test.ObsState == ObsState.EMPTY @@ -214,15 +220,19 @@ class TestSKASubarray: result_callback.wait_for_lrc_id(on_tr.unique_id) result_callback.wait_for_lrc_id(assign_tr.unique_id) - device_under_test.Configure('{"BAND1": 2}') + conf_tr = device_under_test.Configure('{"BAND1": 2}') + result_callback.wait_for_lrc_id(conf_tr.unique_id) obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.READY) - assert device_under_test.End() == [ - [ResultCode.OK], - ["End command completed OK"], - ] + end_tr = device_under_test.End() + result_callback.wait_for_lrc_id(end_tr.unique_id) + assert ( + device_under_test.longRunningCommandResult[2] == "End command completed OK" + ) + assert int(device_under_test.longRunningCommandResult[1]) == ResultCode.OK + obs_state_callback.assert_call(ObsState.IDLE) # PROTECTED REGION END # // SKASubarray.test_EndSB @@ -238,19 +248,24 @@ class TestSKASubarray: on_tr = device_under_test.On() assign_tr = device_under_test.AssignResources(json.dumps(["BAND1"])) + conf_tr = device_under_test.Configure('{"BAND1": 2}') + scan_tr = device_under_test.Scan('{"id": 123}') + result_callback.wait_for_lrc_id(on_tr.unique_id) result_callback.wait_for_lrc_id(assign_tr.unique_id) - - device_under_test.Configure('{"BAND1": 2}') - device_under_test.Scan('{"id": 123}') + result_callback.wait_for_lrc_id(conf_tr.unique_id) + result_callback.wait_for_lrc_id(scan_tr.unique_id) obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.SCANNING) - assert device_under_test.EndScan() == [ - [ResultCode.OK], - ["EndScan command completed OK"], - ] + endscan_tr = device_under_test.EndScan() + result_callback.wait_for_lrc_id(endscan_tr.unique_id) + assert ( + device_under_test.longRunningCommandResult[2] + == "EndScan command completed OK" + ) + assert int(device_under_test.longRunningCommandResult[1]) == ResultCode.OK obs_state_callback.assert_call(ObsState.READY) @@ -274,7 +289,8 @@ class TestSKASubarray: obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.IDLE) - device_under_test.ReleaseAllResources() + release_tr = device_under_test.ReleaseAllResources() + result_callback.wait_for_lrc_id(release_tr.unique_id) obs_state_callback.assert_calls([ObsState.RESOURCING, ObsState.EMPTY]) assert device_under_test.assignedResources is None @@ -297,7 +313,8 @@ class TestSKASubarray: obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.IDLE) - device_under_test.ReleaseResources(json.dumps(["BAND1"])) + release_tr = device_under_test.ReleaseResources(json.dumps(["BAND1"])) + result_callback.wait_for_lrc_id(release_tr.unique_id) obs_state_callback.assert_calls([ObsState.RESOURCING, ObsState.IDLE]) assert device_under_test.ObsState == ObsState.IDLE @@ -318,16 +335,22 @@ class TestSKASubarray: result_callback.wait_for_lrc_id(on_tr.unique_id) result_callback.wait_for_lrc_id(assign_tr.unique_id) - device_under_test.Configure('{"BAND1": 2}') - device_under_test.Abort() + conf_tr = device_under_test.Configure('{"BAND1": 2}') + result_callback.wait_for_lrc_id(conf_tr.unique_id) + abort_tr = device_under_test.Abort() + result_callback.wait_for_lrc_id(abort_tr.unique_id) obs_state_callback = tango_change_event_helper.subscribe("obsState") + obs_state_callback.assert_call(ObsState.ABORTED) - assert device_under_test.ObsReset() == [ - [ResultCode.OK], - ["ObsReset command completed OK"], - ] + obs_reset_tr = device_under_test.ObsReset() + result_callback.wait_for_lrc_id(obs_reset_tr.unique_id) + assert ( + device_under_test.longRunningCommandResult[2] + == "ObsReset command completed OK" + ) + assert int(device_under_test.longRunningCommandResult[1]) == ResultCode.OK obs_state_callback.assert_calls([ObsState.RESETTING, ObsState.IDLE]) assert device_under_test.obsState == ObsState.IDLE @@ -347,20 +370,23 @@ class TestSKASubarray: result_callback.wait_for_lrc_id(on_tr.unique_id) result_callback.wait_for_lrc_id(assign_tr.unique_id) - device_under_test.Configure('{"BAND1": 2}') + conf_tr = device_under_test.Configure('{"BAND1": 2}') + result_callback.wait_for_lrc_id(conf_tr.unique_id) obs_state_callback = tango_change_event_helper.subscribe("obsState") obs_state_callback.assert_call(ObsState.READY) - assert device_under_test.Scan('{"id": 123}') == [ - [ResultCode.STARTED], - ["Scan command started"], - ] + scan_tr = device_under_test.Scan('{"id": 123}') + result_callback.wait_for_lrc_id(scan_tr.unique_id) + assert device_under_test.longRunningCommandResult[2] == "Scan command started" + assert int(device_under_test.longRunningCommandResult[1]) == ResultCode.STARTED obs_state_callback.assert_call(ObsState.SCANNING) assert device_under_test.obsState == ObsState.SCANNING - device_under_test.EndScan() + endscan_tr = device_under_test.EndScan() + result_callback.wait_for_lrc_id(endscan_tr.unique_id) + with pytest.raises(DevFailed): device_under_test.Scan("Invalid JSON") # PROTECTED REGION END # // SKASubarray.test_Scan