Commit f013f97c authored by Gianluca Marotta's avatar Gianluca Marotta
Browse files

CT-214 Fixed errors; deleted outdated tango commands; update pogo file.

parent 826f40d1
Loading
Loading
Loading
Loading
Loading
+16 −99
Original line number Diff line number Diff line
@@ -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
# ----------
+0 −18
Original line number Diff line number Diff line
@@ -268,15 +268,6 @@
      </argout>
      <status abstract="false" inherited="true" concrete="true"/>
    </commands>
    <commands name="AddReceptors" description="Add the receptors specified via theor IDs to the subarray." execMethod="add_receptors" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
      <argin description="List of the receptor IDs to add to the subarray.">
        <type xsi:type="pogoDsl:UShortArrayType"/>
      </argin>
      <argout description="">
        <type xsi:type="pogoDsl:VoidType"/>
      </argout>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </commands>
    <commands name="RemoveReceptors" description="Remove the required receptors (individuated via their IDs) from the&#xA;subarray." execMethod="remove_receptors" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
      <argin description="The list with the receptor IDs to remove">
        <type xsi:type="pogoDsl:UShortArrayType"/>
@@ -286,15 +277,6 @@
      </argout>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </commands>
    <commands name="RemoveAllReceptors" description="Remove all the assigned receptors." execMethod="remove_all_receptors" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
      <argin description="">
        <type xsi:type="pogoDsl:VoidType"/>
      </argin>
      <argout description="">
        <type xsi:type="pogoDsl:VoidType"/>
      </argout>
      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
    </commands>
    <commands name="AddSearchBeams" description="Add the specified SeachBeam Capability IDs o the CSP &#xA;sub-array." execMethod="add_search_beams" displayLevel="OPERATOR" polledPeriod="0">
      <argin description="The list of SearchBeam Capability IDs to assign to the CSP sub-array.">
        <type xsi:type="pogoDsl:UShortArrayType"/>
+5 −5
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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():         
    """