Commit 32db2fc9 authored by Gianluca Marotta's avatar Gianluca Marotta
Browse files

Added transaction ID to CBF configuration; Sending OFF command in case CBF is ON-EMPTY

parent b06f9324
Loading
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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
+63 −1
Original line number Diff line number Diff line
@@ -179,6 +179,16 @@ class TestCspSubarray(TestBase):
            '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"