diff --git a/csp-lmc-common/csp_lmc_common/CspSubarray.py b/csp-lmc-common/csp_lmc_common/CspSubarray.py index 3ad5bd7e3ba216d3d061b7d15ddaf427d32aa9eb..dabd9e7589d9b6cc6bc11d4b503c006aff313613 100644 --- a/csp-lmc-common/csp_lmc_common/CspSubarray.py +++ b/csp-lmc-common/csp_lmc_common/CspSubarray.py @@ -573,7 +573,8 @@ class CspSubarray(SKASubarray): self.logger.info("Call Off Command") device = self.target subelement_thr = {} - self.thread_succeeded = {} + device_to_turn_off = [] + self.empty_succeeded = {} off_failed = False # First loop that start the sub-element threads to get the ObsState.EMPTY for fqdn in device._sc_subarray_fqdn: @@ -581,20 +582,25 @@ class CspSubarray(SKASubarray): # requested state if device._sc_subarray_state[fqdn] == tango.DevState.OFF: continue - if device._sc_subarray_obs_state[fqdn] != ObsState.EMPTY: + elif device._sc_subarray_obs_state[fqdn] != ObsState.EMPTY: subelement_thr[fqdn] = threading.Thread(target=self.off_sequence, name="Thread-OffSequence", args=(fqdn,)) subelement_thr[fqdn].start() + device_to_turn_off.append(fqdn) else: - self.logger.info(f'ObsState of device {fqdn} is not EMPTY. ObsState:{device._sc_subarray_obs_state[fqdn]}') + self.logger.info(f'ObsState of device {fqdn} is already EMPTY. ObsState:{device._sc_subarray_obs_state[fqdn]}') + device_to_turn_off.append(fqdn) + self.empty_succeeded[fqdn] = True + # Second loop check if the thread is succeeded and send the Off command to sub-element for fqdn in subelement_thr.keys(): subelement_thr[fqdn].join() - if any(self.thread_succeeded[fqdn] == True for fqdn in subelement_thr.keys()): - for fqdn in subelement_thr.keys(): + if all(self.empty_succeeded[fqdn] for fqdn in device_to_turn_off): + for fqdn in device_to_turn_off: try: + self.logger.info('Sending Off Command...') (result_code, message) = device._sc_subarray_proxies[fqdn].Off() except tango.DevFailed as tango_err: message = str(tango_err.args[0].desc) @@ -644,9 +650,9 @@ class CspSubarray(SKASubarray): # if ObsState is: RESOURCING, ABORTING start again to wait end of the transition if device._sc_subarray_obs_state[fqdn] == ObsState.EMPTY: - self.thread_succeeded[fqdn] = True + self.empty_succeeded[fqdn] = True else: - self.thread_succeeded[fqdn] = False + self.empty_succeeded[fqdn] = False class AssignResourcesCommand(SKASubarray.AssignResourcesCommand): @transaction_id diff --git a/csp-lmc-common/csp_lmc_common/csp_manage_json.py b/csp-lmc-common/csp_lmc_common/csp_manage_json.py index 9d88f013b434eea43600d5a49a7a9f9c8c228097..e28103b56529f4715a195b5eea4d23ae02053664 100644 --- a/csp-lmc-common/csp_lmc_common/csp_manage_json.py +++ b/csp-lmc-common/csp_lmc_common/csp_manage_json.py @@ -66,6 +66,8 @@ class JsonConfiguration: """ common_dict = self.get_section('common') cbf_dict = self.get_section('cbf') + if 'transaction_id' in self.config: + common_dict['transaction_id'] = self.get_section('transaction_id') config_converted = {**common_dict, **cbf_dict} validate_csp_config(version=0, config=config_converted) self.config = config_converted diff --git a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py index ff3fc2f536063f056e2036d69316462a4a7d1d97..551aa5546b103d0fb96562a9f5e0b11537a265bb 100755 --- a/csp-lmc-mid/tests/integration/MidCspSubarray_test.py +++ b/csp-lmc-mid/tests/integration/MidCspSubarray_test.py @@ -178,7 +178,17 @@ class TestCspSubarray(TestBase): 'subarrayID': 1, 'dish': { 'receptorIDList': list(map(str, argin))}} return json.dumps(param) - + + @pytest.mark.transaction_id_in_CBF + def test_transaction_id_is_present_in_CBF_configuration(self): + """ + Test if the transaction id is properly sent to CBF + """ + self._configure_scan() + latest_configuration = self.cbf_subarray01.latestscanconfig + assert 'transaction_id' in latest_configuration + + @pytest.mark.init_EMPTY def test_AFTER_initialization(self): """ @@ -315,6 +325,30 @@ class TestCspSubarray(TestBase): prober_subarray_state = Probe(self.midcsp_subarray01, "State", DevState.ON, f"CSP Subarray not OFF") Poller(4, 0.2).check(prober_subarray_state) + @pytest.mark.off_empty + def test_OffCommand_after_EMPTY(self): + """ + Test that the Off command send the device in OFF-EMPTY + if it is ON-EMPTY + """ + self._setup_subarray() + subarray_state = self.midcsp_subarray01.State() + obs_state = self.midcsp_subarray01.obsState + LOGGER.info("CSPSubarray state before test:{}-{}".format(subarray_state, obs_state)) + self.midcsp_subarray01.Off() + prober_subarray_state = Probe(self.midcsp_subarray01, "State", DevState.OFF, f"CSP Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) + receptors = self.midcsp_subarray01.assignedReceptors + LOGGER.info(f'type of {type(receptors)}') + LOGGER.info(f'list of receptors{receptors}') + assert not receptors.any(), f"CSP Subarray is not empty" + @pytest.mark.off_resourcing def test_OffCommand_after_RESOURCING(self): """ @@ -335,6 +369,10 @@ class TestCspSubarray(TestBase): Poller(4, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(4, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors LOGGER.info(f'list of receptors{receptors}') assert not receptors.any(), f"CSP Subarray is not empty" @@ -351,6 +389,10 @@ class TestCspSubarray(TestBase): Poller(4, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(4, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors assert not receptors.any(), f"CSP Subarray is not empty" @@ -366,6 +408,10 @@ class TestCspSubarray(TestBase): Poller(10, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(10, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors assert not receptors.any(), f"CSP Subarray is not empty" @@ -383,6 +429,10 @@ class TestCspSubarray(TestBase): Poller(10, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(10, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors assert not receptors.any(), f"CSP Subarray is not empty" @@ -404,6 +454,10 @@ class TestCspSubarray(TestBase): Poller(10, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(10, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors assert not receptors.any(), f"CSP Subarray is not empty" @@ -422,6 +476,10 @@ class TestCspSubarray(TestBase): Poller(4, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(4, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors assert not receptors.any(), f"CSP Subarray is not empty" @@ -440,6 +498,10 @@ class TestCspSubarray(TestBase): Poller(4, 0.2).check(prober_subarray_state) prober_subarray_obsstate = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray not EMPTY") Poller(4, 0.2).check(prober_subarray_obsstate) + prober_subarray_state = Probe(self.cbf_subarray01, "State", DevState.OFF, f"CBF Subarray not OFF") + Poller(4, 0.2).check(prober_subarray_state) + prober_subarray_obsstate = Probe(self.cbf_subarray01, "obsState", ObsState.EMPTY, f"CBF Subarray not EMPTY") + Poller(4, 0.2).check(prober_subarray_obsstate) receptors = self.midcsp_subarray01.assignedReceptors assert not receptors.any(), f"CSP Subarray is not empty"