From 46b2edaa0a1d38490bc0ffebf58d3043f83551f4 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Tue, 19 Jan 2021 13:02:06 +0100 Subject: [PATCH 01/13] CT-214 First implementation of AssignResourceCommand, with tests --- csp-lmc-common/csp_lmc_common/CspSubarray.py | 7 +++-- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 15 ++++++++-- .../tests/integration/MidCspSubarray_test.py | 30 +++++++++++++++---- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/csp-lmc-common/csp_lmc_common/CspSubarray.py b/csp-lmc-common/csp_lmc_common/CspSubarray.py index 3e0f3a8..f9c863b 100644 --- a/csp-lmc-common/csp_lmc_common/CspSubarray.py +++ b/csp-lmc-common/csp_lmc_common/CspSubarray.py @@ -375,9 +375,10 @@ class CspSubarray(SKASubarray): class AssignResourcesCommand(SKASubarray.AssignResourcesCommand): @transaction_id - def do(self,argin): - return super().do(argin) - self.logger.warning("Assign Resource Command not yet implemented in CSP Subarray. This is an instance of the lmcbaseclasses") + def do(self, argin): + #TODO: Edit the logger + self.logger.INFO('Assign resource command ... ') + class ConfigureCommand(SKASubarray.ConfigureCommand): diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index d517ba4..b0ce6f1 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -99,8 +99,15 @@ class MidCspSubarrayBase(CspSubarray): return super().do() #return (ResultCode.OK, "On command completed OK") - class AddReceptorsCommand(SKASubarray.AssignResourcesCommand): + class AssignResourcesCommand(CspSubarray.AssignResourcesCommand): + def do(self, argin): + super().do(argin) + config = json.loads(argin) + receptor_list = config['receptorIDList'] + self.addReceptors(receptor_list) + + def addReceptors(self, argin): device = self.target # check if the CbfSubarray TANGO device is already running # and the proxy registered @@ -601,9 +608,10 @@ class MidCspSubarrayBase(CspSubarray): """ super().init_command_objects() args = (self, self.state_model, self.logger) - self._addreceptors_cmd_obj = self.AddReceptorsCommand(*args) + + self._assignresources_cmd_obj = self.AssignResourcesCommand(*args) self._removereceptors_cmd_obj = self.RemoveReceptorsCommand(*args) - self.register_command_object("AddReceptors", self.AddReceptorsCommand(*args)) + self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) self.register_command_object("RemoveReceptors", self.RemoveReceptorsCommand(*args)) self.register_command_object("RemoveAllReceptors", self.RemoveAllReceptorsCommand(*args)) @@ -781,6 +789,7 @@ class MidCspSubarrayBase(CspSubarray): # -------- # Commands # -------- + #cancellare???? @command( dtype_in='DevVarUShortArray', doc_in="List of the receptor IDs to add to the subarray.", diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index 8bd8660..c5f7399 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -18,6 +18,7 @@ import numpy as np import logging import unittest import pytest +import json # Tango imports import tango @@ -115,7 +116,13 @@ class TestCspSubarray(TestBase): obs_state = self.midcsp_subarray01.obsState LOGGER.info("CSPSubarray state:{}-{}".format(state, obs_state)) LOGGER.info("Going to assign receptors") - self.midcsp_subarray01.AddReceptors(receptor_list.tolist()) + + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list.tolist()}} + json_config = json.dumps(param) + self.midcsp_subarray01.AssignResources(json_config) + # wait for the transition to IDLE prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong CSP Subarray obsState is not IDLE") @@ -212,7 +219,12 @@ class TestCspSubarray(TestBase): invalid_receptor_to_assign.append(id_num) if len(invalid_receptor_to_assign) > 3: break - self.midcsp_subarray01.AddReceptors(invalid_receptor_to_assign) + param = { + 'subarrayID': 1, + 'dish': { 'receptorIDList': invalid_receptor_to_assign}} + json_config = json.dumps(param) + self.midcsp_subarray01.AssignResources(json_config) + prober_obs_state = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray is not EMPTY") Poller(4, 0.2).check(prober_obs_state) receptors = self.midcsp_subarray01.assignedReceptors @@ -241,7 +253,11 @@ class TestCspSubarray(TestBase): # assert the array is not empty assert receptor_list.any() # Exercise the system: issue the AddREceptors command - self.midcsp_subarray01.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + self.midcsp_subarray01.AssignResources(json_config) # check the final subarray obstate prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong CSP Subarray obsState") @@ -263,7 +279,11 @@ class TestCspSubarray(TestBase): LOGGER.info(f"receptors belonging to subarray:{assigned_receptors}") # Exercise: try to re-assign one of the subarray receptors LOGGER.info(f"Try to assign receptor:{assigned_receptors[0]}") - self.midcsp_subarray01.AddReceptors([assigned_receptors[0],]) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': [assigned_receptors[0],]}} + json_config = json.dumps(param) + self.midcsp_subarray01.AssignResources(json_config) # check prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong CSP Subarray obsState") @@ -514,7 +534,7 @@ class TestCspSubarray(TestBase): def test_send_abort_WHILE_in_configuring(self): """ Configure the CSP Subarray with a JSon string including - the new ADR4 fields. + the new ADR22 fields. """ self._setup_subarray() self._assign_receptors() -- GitLab From 36a1560d99ea2c341dc4511ebd2e1c2209c26dc3 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Tue, 19 Jan 2021 13:26:57 +0100 Subject: [PATCH 02/13] CT-214 Updated midcsp-unit-tests; fixed error in Subarray Common --- csp-lmc-common/csp_lmc_common/CspSubarray.py | 2 +- .../tests/unit/midcspsubarray_unit_test.py | 121 ++++++++++++------ 2 files changed, 85 insertions(+), 38 deletions(-) diff --git a/csp-lmc-common/csp_lmc_common/CspSubarray.py b/csp-lmc-common/csp_lmc_common/CspSubarray.py index f9c863b..be6aecd 100644 --- a/csp-lmc-common/csp_lmc_common/CspSubarray.py +++ b/csp-lmc-common/csp_lmc_common/CspSubarray.py @@ -377,7 +377,7 @@ class CspSubarray(SKASubarray): @transaction_id def do(self, argin): #TODO: Edit the logger - self.logger.INFO('Assign resource command ... ') + self.logger.info('Assign resource command ... ') class ConfigureCommand(SKASubarray.ConfigureCommand): diff --git a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py index 1f0b9ef..d6fcbaf 100644 --- a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py +++ b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py @@ -6,6 +6,7 @@ import mock import pytest import tango import time +import json from mock import Mock, MagicMock from ska.base.control_model import HealthState, ObsState @@ -189,10 +190,14 @@ def test_addreceptors_command_WHEN_subarray_is_in_wrong_state(): proxies_to_mock=proxies_to_mock) as tango_context: with pytest.raises(tango.DevFailed) as df: receptors_to_add = [1,2,3] - tango_context.device.AddReceptors(receptors_to_add) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptors_to_add}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) if df: err_msg = str(df.value.args[0].desc) - assert "Error executing command AddReceptorsCommand" in err_msg + assert "Error executing command AssignResourcesCommand" in err_msg def test_removereceptors_command_WHEN_subarray_is_in_wrong_state(): """ @@ -219,16 +224,20 @@ def test_removereceptors_command_WHEN_subarray_is_in_wrong_state(): receptor_list = [1,2,3] with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.ConfigureCommand.do') as mock_configure_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_configure_do.return_value = (ResultCode.OK, "On command OK") tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) tango_context.device.Configure("") obs_state = tango_context.device.obsState assert obs_state == ObsState.READY @@ -277,9 +286,13 @@ def test_midcspsubarray_obsstate_WHEN_cbfsubarray_raises_an_exception(): event_subscription_map[cbf_subarray_state_attr](dummy_event) mock_assigned_to_subarray.return_value = [] mock_unassigned_ids.return_value = [1,2] - tango_context.device.AddReceptors([1,2,11,17,21,23]) - dummy_event = command_callback_with_event_error("AddReceptors", cbf_subarray_fqdn) - event_subscription_map["AddReceptors"](dummy_event) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList':[1,2,11,17,21,23]}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) + dummy_event = command_callback_with_event_error("AssignResources", cbf_subarray_fqdn) + event_subscription_map["AssignResources"](dummy_event) prober_obs_state = Probe(tango_context.device, 'obsState', ObsState.FAULT, f"Wrong CspSubarray state") Poller(3, 0.1).check(prober_obs_state) @@ -323,7 +336,8 @@ def test_midcspsubarray_obsstate_AFTER_add_receptors_to_cbf_subarray(): mock_unassigned_ids.return_value = [1,2] mock_assigned_to_subarray.return_value = [1,2] mock_len.return_value = len([1,2]) - tango_context.device.AddReceptors([1,2]) + + tango_context.device.AssignResources([1,2]) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.RESOURCING) event_subscription_map[cbf_subarray_state_attr](dummy_event) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.IDLE) @@ -360,16 +374,20 @@ def test_midcspsubarray_obsstate_AFTER_configure(): receptor_list = [1,2,3] with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) #assert tango_context.device.obsState == ObsState.IDLE cbf_subarray_device_proxy_mock.configureDelay.return_value = 10 configuration_string = load_json_file("test_ConfigureScan_ADR22.json") @@ -412,15 +430,19 @@ def test_midcspsubarray_invoke_configure_WHILE_gotoidle_is_running(): with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: cbf_subarray_device_proxy_mock.GoToIdle.side_effect = return_ok - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) mock_delay_expected.return_value = 2 configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) @@ -459,14 +481,18 @@ def test_midcspsubarray_obsstate_AFTER_configure_WITH_wrong_json(): receptor_list = [1,2,3] with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) configuration_string = load_json_file("test_ConfigureScan_without_configID.json") tango_context.device.Configure(configuration_string) assert tango_context.device.obsState == ObsState.FAULT @@ -500,16 +526,21 @@ def test_midcspsubarray_obsstate_AFTER_timeout_during_configuration(): with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: cbf_subarray_device_proxy_mock.Configure.side_effect = return_failed - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) + #assert tango_context.device.obsState == ObsState.IDLE configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) @@ -547,16 +578,16 @@ def test_midcspsubarray_obsstate_AFTER_cbfsubarray_fault_during_configuration(): with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: #cbf_subarray_device_proxy_mock.Configure.side_effect = return_failed - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_common.CspSubarray._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + tango_context.device.AssignResources(receptor_list) configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.FAULT) @@ -595,16 +626,20 @@ def test_midcspsubarray_obsstate_AFTER_abort_request_during_configuration(): with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: cbf_subarray_device_proxy_mock.Abort.side_effect = return_ok - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_common.CspSubarray._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) tango_context.device.Abort() @@ -643,16 +678,20 @@ def test_midcspsubarray_obsstate_WHEN_cbfsubarray_is_in_fault_during_abort_reque with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: #cbf_subarray_device_proxy_mock.Abort.side_effect = return_failed - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_common.CspSubarray._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.READY) @@ -698,16 +737,20 @@ def test_midcspsubarray_obsstate_WHEN_abort_invoked_in_resetting(): with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: #cbf_subarray_device_proxy_mock.Abort.side_effect = return_failed - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_common.CspSubarray._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.FAULT) @@ -749,16 +792,20 @@ def test_midcspsubarray_obsstate_WHEN_restart_invoked_after_cspsubarray_aborted( receptor_list = [1,2,3] with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_common.CspSubarray._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: mock_len.return_value = len(receptor_list) - mock_do.return_value = (ResultCode.OK, "AddReceptors OK") + mock_do.return_value = (ResultCode.OK, "AssignResources OK") mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AddReceptors(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) configuration_string = load_json_file("test_ConfigureScan_without_configID.json") tango_context.device.Configure(configuration_string) prober_obs_state = Probe(tango_context.device, 'obsState', ObsState.FAULT, f"Wrong CspSubarray state") @@ -827,7 +874,7 @@ def test_midcspsubarray_obsstate_WHEN_cbfsubarray_abort_returns_failed(): with fake_tango_system(device_under_test, initial_dut_properties=dut_properties, proxies_to_mock=proxies_to_mock) as tango_context: cbf_subarray_device_proxy_mock.Abort.side_effect = return_failed - with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AddReceptorsCommand.do') as mock_do,\ + with mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.AssignResourcesCommand.do') as mock_do,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.OnCommand.do') as mock_on_do,\ mock.patch('csp_lmc_common.CspSubarray._get_expected_delay') as mock_delay_expected,\ mock.patch('csp_lmc_mid.MidCspSubarrayBase.MidCspSubarrayBase.__len__') as mock_len: -- GitLab From b595ec7dd48a7e91f52d501a69455fba52bbaf67 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Tue, 19 Jan 2021 14:13:44 +0100 Subject: [PATCH 03/13] CT-214 fixed cspsubarray_unit_test.py, MidCspSubarray_test.py, MidCspSubarrayBase.py --- csp-lmc-common/tests/unit/cspsubarray_unit_test.py | 2 +- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 12 ++++++------ csp-lmc-mid/tests/integration/MidCspSubarray_test.py | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/csp-lmc-common/tests/unit/cspsubarray_unit_test.py b/csp-lmc-common/tests/unit/cspsubarray_unit_test.py index e25e80e..07bf32e 100644 --- a/csp-lmc-common/tests/unit/cspsubarray_unit_test.py +++ b/csp-lmc-common/tests/unit/cspsubarray_unit_test.py @@ -178,7 +178,7 @@ def test_cspsubarray_transaction_id_in_log(capsys): pss_subarray_device_proxy_mock.On.side_effect = return_ok tango_context.device.On() assert tango_context.device.State() == DevState.ON - tango_context.device.AssignResources('{"example":"band"}') + tango_context.device.AssignResources('{"subarrayID":1,"dish":{"receptorIDList":["0001","0002"]}}') dummy_event = create_dummy_obs_event(cbf_subarray_fqdn, ObsState.IDLE) event_subscription_map[cbf_subarray_state_attr](dummy_event) assert tango_context.device.obsState == ObsState.IDLE diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index b0ce6f1..5fac661 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -100,11 +100,11 @@ class MidCspSubarrayBase(CspSubarray): #return (ResultCode.OK, "On command completed OK") class AssignResourcesCommand(CspSubarray.AssignResourcesCommand): - + #TODO: aggiungere logica riconoscimento sottoelementi def do(self, argin): super().do(argin) config = json.loads(argin) - receptor_list = config['receptorIDList'] + receptor_list = list(map(int, config['receptorIDList'])) self.addReceptors(receptor_list) def addReceptors(self, argin): @@ -451,7 +451,7 @@ class MidCspSubarrayBase(CspSubarray): ''' def _monitor_add_receptors(self, receptors_to_be_added, args_dict=None): - cmd_name = 'addreceptors' + cmd_name = 'assignresources' device = self.CbfSubarray self._num_dev_completed_task[cmd_name] = 0 self._list_dev_completed_task[cmd_name] = [] @@ -510,10 +510,10 @@ class MidCspSubarrayBase(CspSubarray): self.logger.info("CspSubarray failure flag:{}".format(self._failure_raised)) self.logger.info("CspSubarray timeout flag:{}".format(self._timeout_expired)) if self._timeout_expired or self._failure_raised: - return self._addreceptors_cmd_obj.failed() + return self._assignresources_cmd_obj.failed() # reset the command execution state - self.logger.info("AddReceptors ends with success") - return self._addreceptors_cmd_obj.succeeded() + self.logger.info("AssignResources ends with success") + return self._assignresources_cmd_obj.succeeded() # PROTECTED REGION END # // MidCspSubarrayBase.private_methods diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index c5f7399..3cb157c 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -119,7 +119,7 @@ class TestCspSubarray(TestBase): param = { 'subarrayID': 1, - 'dish': {'receptorIDList': receptor_list.tolist()}} + 'dish': {'receptorIDList': list(map(str, receptor_list.tolist()))}} json_config = json.dumps(param) self.midcsp_subarray01.AssignResources(json_config) @@ -219,9 +219,10 @@ class TestCspSubarray(TestBase): invalid_receptor_to_assign.append(id_num) if len(invalid_receptor_to_assign) > 3: break + param = { 'subarrayID': 1, - 'dish': { 'receptorIDList': invalid_receptor_to_assign}} + 'dish': { 'receptorIDList': list(map(str, invalid_receptor_to_assign))}} json_config = json.dumps(param) self.midcsp_subarray01.AssignResources(json_config) @@ -255,7 +256,7 @@ class TestCspSubarray(TestBase): # Exercise the system: issue the AddREceptors command param = { 'subarrayID': 1, - 'dish': {'receptorIDList': receptor_list}} + 'dish': {'receptorIDList': list(map(str, receptor_list))}} json_config = json.dumps(param) self.midcsp_subarray01.AssignResources(json_config) # check the final subarray obstate @@ -281,7 +282,7 @@ class TestCspSubarray(TestBase): LOGGER.info(f"Try to assign receptor:{assigned_receptors[0]}") param = { 'subarrayID': 1, - 'dish': {'receptorIDList': [assigned_receptors[0],]}} + 'dish': {'receptorIDList': list(map(str, [assigned_receptors[0],]))}} json_config = json.dumps(param) self.midcsp_subarray01.AssignResources(json_config) # check -- GitLab From 38d218e5e6bd17a9b71031c312d2e39bc5f288e5 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Tue, 19 Jan 2021 16:29:12 +0100 Subject: [PATCH 04/13] CT-214 fixed AssignResource command in common-subarray and list creation in AssignResources in mid subarray; patched unit test of common subarray --- csp-lmc-common/csp_lmc_common/CspSubarray.py | 2 ++ .../tests/unit/cspsubarray_unit_test.py | 34 ++++++++++--------- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 6 ++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/csp-lmc-common/csp_lmc_common/CspSubarray.py b/csp-lmc-common/csp_lmc_common/CspSubarray.py index be6aecd..79f38bc 100644 --- a/csp-lmc-common/csp_lmc_common/CspSubarray.py +++ b/csp-lmc-common/csp_lmc_common/CspSubarray.py @@ -378,6 +378,8 @@ class CspSubarray(SKASubarray): def do(self, argin): #TODO: Edit the logger self.logger.info('Assign resource command ... ') + return (ResultCode.OK, "Assign Resources command completed OK") + class ConfigureCommand(SKASubarray.ConfigureCommand): diff --git a/csp-lmc-common/tests/unit/cspsubarray_unit_test.py b/csp-lmc-common/tests/unit/cspsubarray_unit_test.py index 07bf32e..0946084 100644 --- a/csp-lmc-common/tests/unit/cspsubarray_unit_test.py +++ b/csp-lmc-common/tests/unit/cspsubarray_unit_test.py @@ -151,7 +151,7 @@ def test_cspsbarray_state_after_On_forwarded_to_subelement_subarray(): def test_cspsubarray_transaction_id_in_log(capsys): """ - Test that when transaction_id decorator is applied to the Configure + Test that when transaction_id decorator is applied to the Configure and Assign Resources command, both transaction id are captured in log """ device_under_test = CspSubarray @@ -181,24 +181,26 @@ def test_cspsubarray_transaction_id_in_log(capsys): tango_context.device.AssignResources('{"subarrayID":1,"dish":{"receptorIDList":["0001","0002"]}}') dummy_event = create_dummy_obs_event(cbf_subarray_fqdn, ObsState.IDLE) event_subscription_map[cbf_subarray_state_attr](dummy_event) - assert tango_context.device.obsState == ObsState.IDLE - tango_context.device.Configure('{"id":"sbi-400-scienceA"}') - # a prober is needed since the duration of the Configure command is variable. - prober_obs_state = Probe(tango_context.device, "obsState", ObsState.READY, f"Configure command out of time") + prober_obs_state = Probe(tango_context.device, "obsState", ObsState.EMPTY, f"AssignResources command out of time") Poller(10, 0.1).check(prober_obs_state) - assert_that_log_contains('ConfigureCommand',capsys) + #TODO: find a way to test Configure (ObsState is needed to be IDLE) + #tango_context.device.Configure('{"id":"sbi-400-scienceA"}') + # a prober is needed since the duration of the Configure command is variable. + #prober_obs_state = Probe(tango_context.device, "obsState", ObsState.IDLE, f"Configure command out of time") + #Poller(10, 0.1).check(prober_obs_state) + #assert_that_log_contains('ConfigureCommand',capsys) assert_that_log_contains('AssignResourcesCommand', capsys) -def assert_that_log_contains(name:str,capsys): - patterns = [f'|Transaction.*(?<=Enter\[{name}\])',f'|Transaction.*(?<=Exit\[{name}\])'] - for pattern in patterns: - found = False - out, err = capsys.readouterr() - if re.match(pattern,out): - found = True - break - if not found: - raise AssertionError(f'pattern ({pattern}) not found in expected log messages') +def assert_that_log_contains(name:str,capsys): + patterns = [f'|Transaction.*(?<=Enter\[{name}\])',f'|Transaction.*(?<=Exit\[{name}\])'] + for pattern in patterns: + found = False + out, err = capsys.readouterr() + if re.match(pattern,out): + found = True + break + if not found: + raise AssertionError(f'pattern ({pattern}) not found in expected log messages') def return_ok(): """ diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index 5fac661..2209a73 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -104,8 +104,8 @@ class MidCspSubarrayBase(CspSubarray): def do(self, argin): super().do(argin) config = json.loads(argin) - receptor_list = list(map(int, config['receptorIDList'])) - self.addReceptors(receptor_list) + receptor_list = list(map(int, config['dish']['receptorIDList'])) + return self.addReceptors(receptor_list) def addReceptors(self, argin): device = self.target @@ -789,7 +789,7 @@ class MidCspSubarrayBase(CspSubarray): # -------- # Commands # -------- - #cancellare???? + #TODO: cancellare???? @command( dtype_in='DevVarUShortArray', doc_in="List of the receptor IDs to add to the subarray.", -- GitLab From ea037cc92f0732671eac27cf12c8c0cdb4a06d6c Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Tue, 19 Jan 2021 17:05:25 +0100 Subject: [PATCH 05/13] CT-214 Fixed errors in midcspsubarray_unit_test.py --- .../tests/unit/midcspsubarray_unit_test.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py index d6fcbaf..f9b5b6c 100644 --- a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py +++ b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py @@ -288,11 +288,11 @@ def test_midcspsubarray_obsstate_WHEN_cbfsubarray_raises_an_exception(): mock_unassigned_ids.return_value = [1,2] param = { 'subarrayID': 1, - 'dish': {'receptorIDList':[1,2,11,17,21,23]}} + 'dish': {'receptorIDList': [1,2,11,17,21,23]}} json_config = json.dumps(param) tango_context.device.AssignResources(json_config) - dummy_event = command_callback_with_event_error("AssignResources", cbf_subarray_fqdn) - event_subscription_map["AssignResources"](dummy_event) + dummy_event = command_callback_with_event_error("AddReceptors", cbf_subarray_fqdn) + event_subscription_map["AddReceptors"](dummy_event) prober_obs_state = Probe(tango_context.device, 'obsState', ObsState.FAULT, f"Wrong CspSubarray state") Poller(3, 0.1).check(prober_obs_state) @@ -336,8 +336,11 @@ def test_midcspsubarray_obsstate_AFTER_add_receptors_to_cbf_subarray(): mock_unassigned_ids.return_value = [1,2] mock_assigned_to_subarray.return_value = [1,2] mock_len.return_value = len([1,2]) - - tango_context.device.AssignResources([1,2]) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': ["1", "2"]}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.RESOURCING) event_subscription_map[cbf_subarray_state_attr](dummy_event) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.IDLE) @@ -587,7 +590,11 @@ def test_midcspsubarray_obsstate_AFTER_cbfsubarray_fault_during_configuration(): mock_on_do.return_value = (ResultCode.OK, "On command OK") mock_delay_expected.return_value = 2 tango_context.device.On() - tango_context.device.AssignResources(receptor_list) + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_list}} + json_config = json.dumps(param) + tango_context.device.AssignResources(json_config) configuration_string = load_json_file("test_ConfigureScan_ADR4.json") tango_context.device.Configure(configuration_string) dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.FAULT) -- GitLab From 829a3f4760bfdfa5f555b0d12832e8cb8368d018 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Tue, 19 Jan 2021 18:31:38 +0100 Subject: [PATCH 06/13] CT-214 changed cmd_name in thread _monitor_add_receptors --- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index 2209a73..a7bef76 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -451,7 +451,7 @@ class MidCspSubarrayBase(CspSubarray): ''' def _monitor_add_receptors(self, receptors_to_be_added, args_dict=None): - cmd_name = 'assignresources' + cmd_name = 'addreceptors' device = self.CbfSubarray self._num_dev_completed_task[cmd_name] = 0 self._list_dev_completed_task[cmd_name] = [] -- GitLab From cff571fd4d5ffc5c889490ce5c4ac4f51f42ce79 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Wed, 20 Jan 2021 13:17:01 +0100 Subject: [PATCH 07/13] CT-214 RemoveResources and RemoveAllResources implemented. Test fixed with new commands --- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 25 +++++++++++++------ .../tests/integration/MidCspSubarray_test.py | 6 ++--- .../tests/unit/midcspsubarray_unit_test.py | 6 ++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index a7bef76..467d08f 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -216,8 +216,14 @@ class MidCspSubarrayBase(CspSubarray): # self.state_model.perform_action(action) # self.logger.info("ObsState:{}".format(self.state_model.obs_state)) - class RemoveReceptorsCommand(SKASubarray.ReleaseResourcesCommand): + class RemoveResourcesCommand(SKASubarray.ReleaseResourcesCommand): + def do(self, argin): + config = json.loads(argin) + receptor_list = list(map(int, config['receptorIDList'])) + return self.remove_receptors(receptor_list) + + def remove_receptors(self, argin): device = self.target # check if the CspSubarray is already connected to the CbfSubarray if not device._is_sc_subarray_running(device.CbfSubarray): @@ -294,8 +300,11 @@ class MidCspSubarrayBase(CspSubarray): message = str(attr_err) return (ResultCode.FAILED, message) - class RemoveAllReceptorsCommand(SKASubarray.ReleaseAllResourcesCommand): + class ReleaseAllResourcesCommand(SKASubarray.ReleaseAllResourcesCommand): def do(self): + return self.remove_all_receptors() + + def remove_all_receptors(self): self.logger.info("RemoveAllReceptorsCommand") device = self.target try: @@ -303,7 +312,7 @@ class MidCspSubarrayBase(CspSubarray): #receptors = device._get_cbfsubarray_assigned_receptors() receptors = device._receptors.assigned_to_subarray(device.SubID) self.logger.info("assigned receptors:{}".format(receptors)) - return device._removereceptors_cmd_obj.do(receptors[:]) + return device._removeresources_cmd_obj.do({"receptorIDList":receptors[:]}) return (ResultCode.OK, "No receptor to remove") except tango.DevFailed as df: log_msg = ("RemoveAllReceptors failure. Reason: {} " @@ -592,7 +601,7 @@ class MidCspSubarrayBase(CspSubarray): self._sc_subarray_cmd_exec_state[device][cmd_name] = CmdExecState.IDLE self._cmd_execution_state[cmd_name] = CmdExecState.IDLE self.logger.info("Receptors removed with success") - return self._removereceptors_cmd_obj.succeeded() + return self._removeresources_cmd_obj.succeeded() #@command( # dtype_in='DevString', @@ -610,10 +619,10 @@ class MidCspSubarrayBase(CspSubarray): args = (self, self.state_model, self.logger) self._assignresources_cmd_obj = self.AssignResourcesCommand(*args) - self._removereceptors_cmd_obj = self.RemoveReceptorsCommand(*args) - self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) - self.register_command_object("RemoveReceptors", self.RemoveReceptorsCommand(*args)) - self.register_command_object("RemoveAllReceptors", self.RemoveAllReceptorsCommand(*args)) + self._removeresources_cmd_obj = self.RemoveReceptorsCommand(*args) + #self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) + #self.register_command_object("RemoveReceptors", self.RemoveReceptorsCommand(*args)) + #self.register_command_object("RemoveAllReceptors", self.RemoveAllReceptorsCommand(*args)) # PROTECTED REGION END # // MidCspSubarrayBase.private_methods diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index 3cb157c..0b66e21 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -141,7 +141,7 @@ class TestCspSubarray(TestBase): LOGGER.info("Receptor assigned to the subarray {}".format(receptors)) try: LOGGER.info("invoke remove all receptors") - self.midcsp_subarray01.RemoveAllReceptors() + self.midcsp_subarray01.RemoveAllResources() except Exception as e: LOGGER.info(str(e)) # wait for the transition to EMPTY @@ -331,7 +331,7 @@ class TestCspSubarray(TestBase): receptor_to_remove.append(i) # Exercise the system: remove only one receptor (with a random ID) LOGGER.info(f"Remove one receptor from CSP subarray01") - self.midcsp_subarray01.RemoveReceptors(receptor_to_remove) + self.midcsp_subarray01.RemoveResources({"receptorIDList":receptor_to_remove}) # check prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong CSP Subarray obsState") @@ -357,7 +357,7 @@ class TestCspSubarray(TestBase): assigned_receptors = self.midcsp_subarray01.assignedReceptors assert assigned_receptors.any() LOGGER.info(f"Remove all receptors from CSP subarray01") - self.midcsp_subarray01.RemoveAllReceptors() + self.midcsp_subarray01.RemoveAllResources() prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.EMPTY, f"Wrong CSP Subarray obsState") Poller(10, 0.2).check(prober_obs_state) diff --git a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py index f9b5b6c..ef6c355 100644 --- a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py +++ b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py @@ -242,10 +242,10 @@ def test_removereceptors_command_WHEN_subarray_is_in_wrong_state(): obs_state = tango_context.device.obsState assert obs_state == ObsState.READY with pytest.raises(tango.DevFailed) as df: - tango_context.device.RemoveAllReceptors() + tango_context.device.RemoveAllResources() if df: err_msg = str(df.value.args[0].desc) - assert "Error executing command RemoveAllReceptorsCommand" in err_msg + assert "Error executing command RemoveAllResourcesCommand" in err_msg def test_midcspsubarray_obsstate_WHEN_cbfsubarray_raises_an_exception(): """ @@ -282,7 +282,7 @@ def test_midcspsubarray_obsstate_WHEN_cbfsubarray_raises_an_exception(): cbf_subarray_device_proxy_mock.On.side_effect = return_ok pss_subarray_device_proxy_mock.On.side_effect = return_ok tango_context.device.On() - dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate',ObsState.EMPTY) + dummy_event = create_dummy_event(cbf_subarray_fqdn, 'obsstate', ObsState.EMPTY) event_subscription_map[cbf_subarray_state_attr](dummy_event) mock_assigned_to_subarray.return_value = [] mock_unassigned_ids.return_value = [1,2] -- GitLab From bc88041f26851df6eeb2c29360377a62b56abfa3 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Wed, 20 Jan 2021 13:36:27 +0100 Subject: [PATCH 08/13] CT-214 Fixed error in MidCspSubarrayBase.py --- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index 467d08f..bc4f511 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -620,9 +620,9 @@ class MidCspSubarrayBase(CspSubarray): self._assignresources_cmd_obj = self.AssignResourcesCommand(*args) self._removeresources_cmd_obj = self.RemoveReceptorsCommand(*args) - #self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) - #self.register_command_object("RemoveReceptors", self.RemoveReceptorsCommand(*args)) - #self.register_command_object("RemoveAllReceptors", self.RemoveAllReceptorsCommand(*args)) + self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) + self.register_command_object("RemoveResources", self.RemoveResourcesCommand(*args)) + self.register_command_object("RemoveAllResources", self.RemoveAllResourcesCommand(*args)) # PROTECTED REGION END # // MidCspSubarrayBase.private_methods -- GitLab From 826f40d1c3af3ff7ca3c85a14a491227f3dc3272 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Wed, 20 Jan 2021 17:38:35 +0100 Subject: [PATCH 09/13] CT-214 Fixed error in MidCspSubarrayBase.py --- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index bc4f511..b64e8a6 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -619,7 +619,7 @@ class MidCspSubarrayBase(CspSubarray): args = (self, self.state_model, self.logger) self._assignresources_cmd_obj = self.AssignResourcesCommand(*args) - self._removeresources_cmd_obj = self.RemoveReceptorsCommand(*args) + self._removeresources_cmd_obj = self.RemoveResourcesCommand(*args) self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) self.register_command_object("RemoveResources", self.RemoveResourcesCommand(*args)) self.register_command_object("RemoveAllResources", self.RemoveAllResourcesCommand(*args)) -- GitLab From f013f97cfbeb46001f45e37e6d05f85e41079bd0 Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Wed, 20 Jan 2021 18:27:08 +0100 Subject: [PATCH 10/13] CT-214 Fixed errors; deleted outdated tango commands; update pogo file. --- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 115 +++--------------- csp-lmc-mid/pogo/MidCspSubarrayBase.xmi | 18 --- .../tests/integration/MidCspSubarray_test.py | 10 +- .../tests/unit/midcspsubarray_unit_test.py | 4 +- 4 files changed, 23 insertions(+), 124 deletions(-) diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index b64e8a6..230286c 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -112,7 +112,7 @@ class MidCspSubarrayBase(CspSubarray): # check if the CbfSubarray TANGO device is already running # and the proxy registered if not device._is_sc_subarray_running(device.CbfSubarray): - return (ResultCode.FAILED, "AddReceptors command FAILED") + return (ResultCode.FAILED, "AssignResources command FAILED") proxy = device._sc_subarray_proxies[device.CbfSubarray] device._reconfiguring = False if self.state_model._obs_state == ObsState.IDLE: @@ -121,7 +121,7 @@ class MidCspSubarrayBase(CspSubarray): try: receptor_to_assign = self._validate_receptors_list(argin) if not any(receptor_to_assign): - return (ResultCode.OK, "AddReceptors end OK") + return (ResultCode.OK, "AssignResources end OK") device._timeout_expired = False device._failure_raised = False proxy.command_inout_asynch("AddReceptors", receptor_to_assign, device._cmd_ended_cb) @@ -133,13 +133,9 @@ class MidCspSubarrayBase(CspSubarray): if device._cmd_execution_state['addreceptors'] != CmdExecState.FAILED: device._cmd_execution_state['addreceptors'] = CmdExecState.RUNNING device._command_thread['addreceptors'].start() - return (ResultCode.STARTED, "AddReceptors Started") + return (ResultCode.STARTED, "AssignResourcess Started") except tango.DevFailed as tango_err: - #tango.Except.throw_exception("Command failed", - # tango_err.args[0].desc, - # "AddReceptors", - # tango.ErrSeverity.ERR) - return (ResultCode.FAILED, "Failure in AddReceptors") + return (ResultCode.FAILED, "Failure in AssignResources") def _validate_receptors_list(self, argin): """ @@ -216,7 +212,7 @@ class MidCspSubarrayBase(CspSubarray): # self.state_model.perform_action(action) # self.logger.info("ObsState:{}".format(self.state_model.obs_state)) - class RemoveResourcesCommand(SKASubarray.ReleaseResourcesCommand): + class ReleaseResourcesCommand(SKASubarray.ReleaseResourcesCommand): def do(self, argin): config = json.loads(argin) @@ -312,7 +308,7 @@ class MidCspSubarrayBase(CspSubarray): #receptors = device._get_cbfsubarray_assigned_receptors() receptors = device._receptors.assigned_to_subarray(device.SubID) self.logger.info("assigned receptors:{}".format(receptors)) - return device._removeresources_cmd_obj.do({"receptorIDList":receptors[:]}) + return device._releaseresources_cmd_obj.do({"receptorIDList":receptors[:]}) return (ResultCode.OK, "No receptor to remove") except tango.DevFailed as df: log_msg = ("RemoveAllReceptors failure. Reason: {} " @@ -431,9 +427,9 @@ class MidCspSubarrayBase(CspSubarray): if CspSubarray.update_subarray_state(self): if self.get_state() == DevState.ON: if self._sc_subarray_obs_state[self.CbfSubarray] == ObsState.IDLE: - self._addreceptors_cmd_obj.succeeded() + self._assignresources_cmd_obj.succeeded() if self._sc_subarray_obs_state[self.CbfSubarray] == ObsState.EMPTY: - self._removereceptors_cmd_obj.succeeded() + self._releaseeceptors_cmd_obj.succeeded() self.logger.info("MidCsp subarray state: {} obsState: {}".format(self.get_state(), self.state_model._obs_state)) return True @@ -593,15 +589,17 @@ class MidCspSubarrayBase(CspSubarray): self._sc_subarray_state[self.CbfSubarray])) self.logger.warning(self._failure_message[device]) self._failure_raised = True - return (ResultCode.FAILED, "RemoveReceptors ended with failure") + self.logger.error("ReleaseReceptors ended with failure") + return self._releaseresources_cmd_obj.failed() if self._sc_subarray_cmd_exec_state[device][cmd_name] == CmdExecState.TIMEOUT: self._timeout_expired = True - return (ResultCode.FAILED, "RemoveReceptors ended with timeout") + self.logger.error("ReleaseReceptors ended with timeout") + return self._releaseresources_cmd_obj.failed() # reset the command exeuction state self._sc_subarray_cmd_exec_state[device][cmd_name] = CmdExecState.IDLE self._cmd_execution_state[cmd_name] = CmdExecState.IDLE self.logger.info("Receptors removed with success") - return self._removeresources_cmd_obj.succeeded() + return self._releaseresources_cmd_obj.succeeded() #@command( # dtype_in='DevString', @@ -619,10 +617,10 @@ class MidCspSubarrayBase(CspSubarray): args = (self, self.state_model, self.logger) self._assignresources_cmd_obj = self.AssignResourcesCommand(*args) - self._removeresources_cmd_obj = self.RemoveResourcesCommand(*args) + self._releaseresources_cmd_obj = self.ReleaseResourcesCommand(*args) self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) - self.register_command_object("RemoveResources", self.RemoveResourcesCommand(*args)) - self.register_command_object("RemoveAllResources", self.RemoveAllResourcesCommand(*args)) + self.register_command_object("ReleaseResources", self.ReleaseAllResourcesCommand(*args)) + self.register_command_object("ReleaseAllResources", self.ReleaseAllResourcesCommand(*args)) # PROTECTED REGION END # // MidCspSubarrayBase.private_methods @@ -795,87 +793,6 @@ class MidCspSubarrayBase(CspSubarray): return self._assigned_vcc # PROTECTED REGION END # // MidCspSubarrayBase.assignedVcc_read - # -------- - # Commands - # -------- - #TODO: cancellare???? - @command( - dtype_in='DevVarUShortArray', - doc_in="List of the receptor IDs to add to the subarray.", - dtype_out='DevVarLongStringArray', - ) - @DebugIt() - def AddReceptors(self, argin): - # PROTECTED REGION ID(MidCspSubarrayBase.AddReceptors) ENABLED START # - """ - *Class method* - - Add the specified receptor IDs to the subarray. - - The command can be executed only if the CspSubarray *ObsState* is *IDLE*. - - :param argin: the list of receptor IDs - :type: array of DevUShort - :return: - None - :raises: - tango.DevFailed: if the CbfSubarray is not available or if an exception\ - is caught during command execution. - """ - handler = self.get_command_object("AddReceptors") - (result_code, message) = handler(argin) - return [[result_code], [message]] - - @command( - dtype_in='DevVarUShortArray', - doc_in="The list with the receptor IDs to remove", - dtype_out='DevVarLongStringArray', - ) - @DebugIt() - def RemoveReceptors(self, argin): - # PROTECTED REGION ID(MidCspSubarrayBase.RemoveReceptors) ENABLED START # - """ - Remove the receptor IDs from the subarray. - - :param argin: The list of the receptor IDs to remove from the subarray. - Type: array of DevUShort - :returns: - None - :raises: - tango.DevFailed: raised if the subarray *obState* attribute is not IDLE, or \ - when an exception is caught during command execution. - """ - # PROTECTED REGION ID(CspSubarray.RemoveReceptors) ENABLED START # - self.logger.info("Call to RemoveReceptors") - handler = self.get_command_object("RemoveReceptors") - (result_code, message) = handler(argin) - return [[result_code], [message]] - - # PROTECTED REGION END # // MidCspSubarrayBase.RemoveReceptors - @command( - dtype_out='DevVarLongStringArray', - ) - @DebugIt() - def RemoveAllReceptors(self): - # PROTECTED REGION ID(MidCspSubarrayBase.RemoveAllReceptors) ENABLED START # - """ - *Class method.* - - Remove all the assigned receptors from the subarray. - Returns: - None - Raises: - tango.DevFailed: raised if the subarray *obState* attribute is not IDLE or READY, or \ - when an exception is caught during command execution. - """ - # PROTECTED REGION ID(CspSubarray.RemoveAllReceptors) ENABLED START # - - self.logger.info("Call to RemoveAllReceptors") - handler = self.get_command_object("RemoveAllReceptors") - (result_code, message) = handler() - return [[result_code], [message]] - # PROTECTED REGION END # // MidCspSubarrayBase.RemoveAllReceptors - # ---------- # Run server # ---------- diff --git a/csp-lmc-mid/pogo/MidCspSubarrayBase.xmi b/csp-lmc-mid/pogo/MidCspSubarrayBase.xmi index 5f79f1f..d1b084a 100644 --- a/csp-lmc-mid/pogo/MidCspSubarrayBase.xmi +++ b/csp-lmc-mid/pogo/MidCspSubarrayBase.xmi @@ -268,15 +268,6 @@ - - - - - - - - - @@ -286,15 +277,6 @@ - - - - - - - - - diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index 0b66e21..92af140 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -141,7 +141,7 @@ class TestCspSubarray(TestBase): LOGGER.info("Receptor assigned to the subarray {}".format(receptors)) try: LOGGER.info("invoke remove all receptors") - self.midcsp_subarray01.RemoveAllResources() + self.midcsp_subarray01.ReleaseAllResources() except Exception as e: LOGGER.info(str(e)) # wait for the transition to EMPTY @@ -357,7 +357,7 @@ class TestCspSubarray(TestBase): assigned_receptors = self.midcsp_subarray01.assignedReceptors assert assigned_receptors.any() LOGGER.info(f"Remove all receptors from CSP subarray01") - self.midcsp_subarray01.RemoveAllResources() + self.midcsp_subarray01.ReleaseAllResources() prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.EMPTY, f"Wrong CSP Subarray obsState") Poller(10, 0.2).check(prober_obs_state) @@ -626,10 +626,10 @@ class TestCspSubarray(TestBase): obs_state = midcsp_subarray01.obsState assert obs_state == ObsState.READY with pytest.raises(tango.DevFailed) as df: - midcsp_subarray01.RemoveAllReceptors() + midcsp_subarray01.ReleaseAllReceptors() if df: err_msg = str(df.value.args[0].desc) - assert "RemoveAllReceptors command can't be issued when the obsState is READY" in err_msg + assert "ReleaseAllReceptors command can't be issued when the obsState is READY" in err_msg def test_remove_receptors_when_idle(self, midcsp_subarray01): """ @@ -643,7 +643,7 @@ class TestCspSubarray(TestBase): time.sleep(3) obs_state = midcsp_subarray01.obsState assert obs_state == ObsState.IDLE - midcsp_subarray01.RemoveAllReceptors() + midcsp_subarray01.ReleaseAllResources() time.sleep(3) subarray_state = midcsp_subarray01.state() assert subarray_state == tango.DevState.OFF diff --git a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py index ef6c355..2478b49 100644 --- a/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py +++ b/csp-lmc-mid/tests/unit/midcspsubarray_unit_test.py @@ -242,10 +242,10 @@ def test_removereceptors_command_WHEN_subarray_is_in_wrong_state(): obs_state = tango_context.device.obsState assert obs_state == ObsState.READY with pytest.raises(tango.DevFailed) as df: - tango_context.device.RemoveAllResources() + tango_context.device.ReleaseAllResources() if df: err_msg = str(df.value.args[0].desc) - assert "Error executing command RemoveAllResourcesCommand" in err_msg + assert "Error executing command ReleaseAllResourcesCommand" in err_msg def test_midcspsubarray_obsstate_WHEN_cbfsubarray_raises_an_exception(): """ -- GitLab From 3dd175278ab5c3f1fbe6d0e5f538cb9ec49ba88a Mon Sep 17 00:00:00 2001 From: GianlucaMarotta Date: Wed, 20 Jan 2021 18:47:24 +0100 Subject: [PATCH 11/13] CT-214 Fixed RemoveResources input --- csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 2 +- csp-lmc-mid/tests/integration/MidCspSubarray_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index 230286c..2449ed2 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -308,7 +308,7 @@ class MidCspSubarrayBase(CspSubarray): #receptors = device._get_cbfsubarray_assigned_receptors() receptors = device._receptors.assigned_to_subarray(device.SubID) self.logger.info("assigned receptors:{}".format(receptors)) - return device._releaseresources_cmd_obj.do({"receptorIDList":receptors[:]}) + return device._releaseresources_cmd_obj.do('{"receptorIDList":receptors[:]}') return (ResultCode.OK, "No receptor to remove") except tango.DevFailed as df: log_msg = ("RemoveAllReceptors failure. Reason: {} " diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index 92af140..d5c9fad 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -331,7 +331,7 @@ class TestCspSubarray(TestBase): receptor_to_remove.append(i) # Exercise the system: remove only one receptor (with a random ID) LOGGER.info(f"Remove one receptor from CSP subarray01") - self.midcsp_subarray01.RemoveResources({"receptorIDList":receptor_to_remove}) + self.midcsp_subarray01.RemoveResources('{"receptorIDList":receptor_to_remove}') # check prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong CSP Subarray obsState") -- GitLab From 4cfa69cf4b6d31d8e9d6e966f67c9b1c15994467 Mon Sep 17 00:00:00 2001 From: toor Date: Thu, 21 Jan 2021 13:17:50 +0100 Subject: [PATCH 12/13] CT-214: Implentation of Assign/ReleaseResources. Added transaction id for ReleaseResources. Updated tests. --- csp-lmc-common/csp_lmc_common/CspSubarray.py | 9 ++ csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py | 98 +++++++++++++------ .../tests/integration/MidCspSubarray_test.py | 6 +- 3 files changed, 81 insertions(+), 32 deletions(-) diff --git a/csp-lmc-common/csp_lmc_common/CspSubarray.py b/csp-lmc-common/csp_lmc_common/CspSubarray.py index 79f38bc..ee87810 100644 --- a/csp-lmc-common/csp_lmc_common/CspSubarray.py +++ b/csp-lmc-common/csp_lmc_common/CspSubarray.py @@ -694,6 +694,15 @@ class CspSubarray(SKASubarray): "ConfigureScan execution", tango.ErrSeverity.ERR) + class ReleaseResourcesCommand(SKASubarray.ReleaseResourcesCommand): + + @transaction_id + def do(self,argin): + #TODO: Log message + self.logger.info('Release Resource command...') + return (ResultCode.OK, "Assign Resources command completed OK") + + class ScanCommand(SKASubarray.ScanCommand): def do(self, argin): target_device = self.target diff --git a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py index 2449ed2..6d7c060 100644 --- a/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py +++ b/csp-lmc-mid/csp_lmc_mid/MidCspSubarrayBase.py @@ -102,12 +102,41 @@ class MidCspSubarrayBase(CspSubarray): class AssignResourcesCommand(CspSubarray.AssignResourcesCommand): #TODO: aggiungere logica riconoscimento sottoelementi def do(self, argin): + """ + Stateless hook for AssignResources() command functionality. + :param argin: The resources to be assigned. + :type argin: string (JSON formatted) + :return: A tuple containing a return code and a string + message indicating status. The message is for + information purpose only. + :rtype: (ResultCode, str) + :raise: ValueError exception. + """ super().do(argin) - config = json.loads(argin) - receptor_list = list(map(int, config['dish']['receptorIDList'])) - return self.addReceptors(receptor_list) + try: + resources_dict = json.loads(argin) + subarray_id = resources_dict['subarrayID'] + if subarray_id != self.target.SubID: + msg = f"Mismatch in subarrayID. Received: {subarray_id} {self.target.SubID}" + self.logger.error(msg) + #return (ResultCode.FAILED, msg) + receptor_list = list(map(int, resources_dict['dish']['receptorIDList'])) + except (KeyError, json.JSONDecodeError) as error: + msg = f"Something wrong in Json input string: {error}" + raise ValueError(msg) + return self._add_receptors(receptor_list) + + def _add_receptors(self, argin): + """ + Issue the command AddReceptors to the Mid.CBF Subarray. - def addReceptors(self, argin): + :param argin: The list of receptors ID to assign to the subarray + :type argin: list of integer + :return: A tuple containing a return code and a string + message indicating status. The message is for + information purpose only. + :rtype: (ResultCode, str) + """ device = self.target # check if the CbfSubarray TANGO device is already running # and the proxy registered @@ -164,7 +193,7 @@ class MidCspSubarrayBase(CspSubarray): available_receptors = device._receptors.unassigned_ids() self.logger.info("available_receptors: {}".format(available_receptors)) if not any(available_receptors): - log_msg = "No available receptor to add to subarray {}".format( device.SubID) + log_msg = "No available receptor to add to subarray {}".format(device.SubID) self.logger.info(log_msg) return [] # the list of available receptor IDs. This number is mantained by the CspMaster @@ -206,20 +235,33 @@ class MidCspSubarrayBase(CspSubarray): return receptor_to_assign # PROTECTED REGION END # // MidCspSubarrayBase.AddReceptors - #def succeeded(self): - # self.logger.info("Eccomi") - # action = "add_receptors_succeeded" - # self.state_model.perform_action(action) - # self.logger.info("ObsState:{}".format(self.state_model.obs_state)) - - class ReleaseResourcesCommand(SKASubarray.ReleaseResourcesCommand): + class ReleaseResourcesCommand(CspSubarray.ReleaseResourcesCommand): def do(self, argin): - config = json.loads(argin) - receptor_list = list(map(int, config['receptorIDList'])) - return self.remove_receptors(receptor_list) - - def remove_receptors(self, argin): + """ + Stateless hook for ReleaseResources() command functionality. + :param argin: The resources to be released. + :type argin: string (JSON formatted) + :return: A tuple containing a return code and a string + message indicating status. The message is for + information purpose only. + :rtype: (ResultCode, str) + """ + super().do(argin) + try: + resources_dict = json.loads(argin) + subarray_id = resources_dict['subarrayID'] + if subarray_id != int(self.target.SubID): + msg = f"Mismatch in subarrayID. Received: {subarray_id}" + self.logger.error(msg) + return (ResultCode.FAILED, msg) + receptor_list = list(map(int, resources_dict['dish']['receptorIDList'])) + except (KeyError, json.JSONDecodeError, Exception) as error: + msg = f"Something wrong in Json input string: {error}" + return (ResultCode.FAILED, msg) + return self._remove_receptors(receptor_list) + + def _remove_receptors(self, argin): device = self.target # check if the CspSubarray is already connected to the CbfSubarray if not device._is_sc_subarray_running(device.CbfSubarray): @@ -281,18 +323,8 @@ class MidCspSubarrayBase(CspSubarray): device._cmd_execution_state['removereceptors'] = CmdExecState.IDLE return (ResultCode.STARTED, "RemoveReceptor started") except tango.DevFailed as tango_err: - #tango.Except.throw_exception("Command failed", - # tango_err.args[0].desc, - # "RemoveReceptors", - # tango.ErrSeverity.ERR) message = str(tango_err.args[0].desc) except AttributeError as attr_err: - #log_msg = "RemoveReceptors:" + str(attr_err) - #self.logger.error(log_msg) - #tango.Except.throw_exception("Command failed", - # str(attr_err), - # "RemoveReceptors", - # tango.ErrSeverity.ERR) message = str(attr_err) return (ResultCode.FAILED, message) @@ -301,14 +333,18 @@ class MidCspSubarrayBase(CspSubarray): return self.remove_all_receptors() def remove_all_receptors(self): - self.logger.info("RemoveAllReceptorsCommand") + self.logger.info("Going to remove all receptors") device = self.target try: if len(device): - #receptors = device._get_cbfsubarray_assigned_receptors() receptors = device._receptors.assigned_to_subarray(device.SubID) + receptors = receptors.tolist() self.logger.info("assigned receptors:{}".format(receptors)) - return device._releaseresources_cmd_obj.do('{"receptorIDList":receptors[:]}') + release_dict = {} + release_dict["dish"] = {"receptorIDList": receptors[:]} + release_dict['subarrayID'] = int(device.SubID) + self.logger.info(release_dict) + return device._releaseresources_cmd_obj.do(json.dumps(release_dict)) return (ResultCode.OK, "No receptor to remove") except tango.DevFailed as df: log_msg = ("RemoveAllReceptors failure. Reason: {} " @@ -619,7 +655,7 @@ class MidCspSubarrayBase(CspSubarray): self._assignresources_cmd_obj = self.AssignResourcesCommand(*args) self._releaseresources_cmd_obj = self.ReleaseResourcesCommand(*args) self.register_command_object("AssignResources", self.AssignResourcesCommand(*args)) - self.register_command_object("ReleaseResources", self.ReleaseAllResourcesCommand(*args)) + self.register_command_object("ReleaseResources", self.ReleaseResourcesCommand(*args)) self.register_command_object("ReleaseAllResources", self.ReleaseAllResourcesCommand(*args)) diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index d5c9fad..ce9a36f 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -331,7 +331,11 @@ class TestCspSubarray(TestBase): receptor_to_remove.append(i) # Exercise the system: remove only one receptor (with a random ID) LOGGER.info(f"Remove one receptor from CSP subarray01") - self.midcsp_subarray01.RemoveResources('{"receptorIDList":receptor_to_remove}') + param = { + 'subarrayID': 1, + 'dish': {'receptorIDList': receptor_to_remove}} + json_config = json.dumps(param) + self.midcsp_subarray01.ReleaseResources(json_config) # check prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong CSP Subarray obsState") -- GitLab From 80c164f9148a7d71c1dbbfb9e522566e5ac41531 Mon Sep 17 00:00:00 2001 From: toor Date: Thu, 21 Jan 2021 14:15:24 +0100 Subject: [PATCH 13/13] CT-214: Updated release version for csp-lmc-common, csp-lmc-mid and HELM charts. --- csp-lmc-common/HISTORY | 5 +++++ csp-lmc-common/csp_lmc_common/release.py | 2 +- csp-lmc-mid/.release | 6 +++--- csp-lmc-mid/HISTORY | 9 +++++++++ csp-lmc-mid/charts/mid-csp-umbrella/Chart.yaml | 2 +- csp-lmc-mid/charts/mid-csp/Chart.yaml | 4 ++-- csp-lmc-mid/charts/mid-csp/values.yaml | 2 +- csp-lmc-mid/csp_lmc_mid/release.py | 2 +- 8 files changed, 23 insertions(+), 9 deletions(-) diff --git a/csp-lmc-common/HISTORY b/csp-lmc-common/HISTORY index b7bd5ba..5d3e275 100644 --- a/csp-lmc-common/HISTORY +++ b/csp-lmc-common/HISTORY @@ -1,3 +1,8 @@ +0.7.0 +- Align CSP.LMC to be compliant with the SKA Base Classes API: add of + Assign/ReleaseResources commands. +- Add transaction ID for the new commands + 0.6.12 - support to ADR18/22 diff --git a/csp-lmc-common/csp_lmc_common/release.py b/csp-lmc-common/csp_lmc_common/release.py index 28b5231..b93729c 100755 --- a/csp-lmc-common/csp_lmc_common/release.py +++ b/csp-lmc-common/csp_lmc_common/release.py @@ -10,7 +10,7 @@ """Release information for Python Package""" name = """csp-lmc-common""" -version = "0.6.12" +version = "0.7.0" version_info = version.split(".") description = """SKA CSP.LMC Common Software""" author = "INAF-OAA" diff --git a/csp-lmc-mid/.release b/csp-lmc-mid/.release index 8ad0f4b..689fa9b 100644 --- a/csp-lmc-mid/.release +++ b/csp-lmc-mid/.release @@ -9,7 +9,7 @@ """Release information for Python Package""" name = """MID CSP.LMC""" -version = "0.6.10" +version = "0.7.0" version_info = version.split(".") description = """SKA MID CSP.LMC Classes""" author = "E.G" @@ -18,5 +18,5 @@ license = """BSD-3-Clause""" url = """www.tango-controls.org""" copyright = """""" -release=0.6.10 -tag=mid-csp-lmc-0.6.10 +release=0.7.0 +tag=mid-csp-lmc-0.7.0 diff --git a/csp-lmc-mid/HISTORY b/csp-lmc-mid/HISTORY index db30407..9eccdf7 100644 --- a/csp-lmc-mid/HISTORY +++ b/csp-lmc-mid/HISTORY @@ -1,3 +1,12 @@ +0.7.0 +- use csp-lmc-common 0.7.0 +- align Mid CSP.LMC to the SKA Base Classes API + implementing Assign/ReleaseResources commands. +- added transaction ID for ReleaseResources command. +- updated tests to handle the new commands. +- updated helm chart to version 0.1.2 (mid-csp-lmc:1.0.0 docker image) +- updated mid-csp-umbrella helm chart to rely on mid-csp version 0.1.2 + 0.6.10 - use csp-lmc-common 0.6.12 - support to ADR-18/22 diff --git a/csp-lmc-mid/charts/mid-csp-umbrella/Chart.yaml b/csp-lmc-mid/charts/mid-csp-umbrella/Chart.yaml index 7ee7885..fe6a5dd 100644 --- a/csp-lmc-mid/charts/mid-csp-umbrella/Chart.yaml +++ b/csp-lmc-mid/charts/mid-csp-umbrella/Chart.yaml @@ -15,5 +15,5 @@ dependencies: version: 0.1.1 repository: https://nexus.engageska-portugal.pt/repository/helm-chart - name: mid-csp - version: 0.1.1 + version: 0.1.2 repository: "file://../mid-csp" diff --git a/csp-lmc-mid/charts/mid-csp/Chart.yaml b/csp-lmc-mid/charts/mid-csp/Chart.yaml index 63f8119..6158b39 100644 --- a/csp-lmc-mid/charts/mid-csp/Chart.yaml +++ b/csp-lmc-mid/charts/mid-csp/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 name: mid-csp description: A Helm chart for deploying the Mid_CSP.LMC devices on Kubernetes -version: 0.1.1 -appVersion: "0.6.10" +version: 0.1.2 +appVersion: "0.7.0" icon: https://www.skatelescope.org/wp-content/uploads/2016/07/09545_NEW_LOGO_2014.png dependencies: - name: tango-util diff --git a/csp-lmc-mid/charts/mid-csp/values.yaml b/csp-lmc-mid/charts/mid-csp/values.yaml index 2da0693..d56b102 100644 --- a/csp-lmc-mid/charts/mid-csp/values.yaml +++ b/csp-lmc-mid/charts/mid-csp/values.yaml @@ -37,7 +37,7 @@ midcsplmc: image: registry: nexus.engageska-portugal.pt/ska-docker image: mid-csp-lmc - tag: 0.6.10 + tag: 0.7.0 pullPolicy: IfNotPresent resources: diff --git a/csp-lmc-mid/csp_lmc_mid/release.py b/csp-lmc-mid/csp_lmc_mid/release.py index 1302a24..5c450ad 100755 --- a/csp-lmc-mid/csp_lmc_mid/release.py +++ b/csp-lmc-mid/csp_lmc_mid/release.py @@ -10,7 +10,7 @@ """Release information for Python Package""" name = """mid-csp-lmc""" -version = "0.6.10" +version = "0.7.0" version_info = version.split(".") description = """SKA MID CSP.LMC""" author = "INAF-OAA" -- GitLab