Commit ed062562 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

CT-69: new test to check fault condition raised by CBF Subarray on

invalid json configuration.
parent da1980e1
Loading
Loading
Loading
Loading
Loading
+82 −58
Original line number Diff line number Diff line
@@ -48,38 +48,26 @@ class TestCspSubarrayConfiguration(TestBase):
        Set the CSP Subarray to ON state.
        """
        # read from the CSP Master the list of available receptors
        # and the receptorMembership attribute reporting
        # dish affiliation to subarrays
        unassigned_receptors = self.midcsp_master.unassignedReceptorIDs
        receptor_membership = self.midcsp_master.receptorMembership
        # assign the first one to the subarray
        LOGGER.info("Add receptors")
        receptor_membership_expected = self.midcsp_master.receptorMembership
        # assign the first one to the CSP subarray to force 
        # the transition to ON
        LOGGER.info("Add receptors to CSP Subarray")
        self.midcsp_subarray01.AddReceptors([unassigned_receptors[0],])
        receptor_membership_expected[unassigned_receptors[0]- 1] = 1
        # wait for the expected value of the CSP Master receptorMembership attribute
        prober_receptor_membership = Probe(self.midcsp_master, 'receptorMembership', receptor_membership_expected, f"Wrong state")
        Poller(10, 0.2).check(prober_receptor_membership)
        # wait for the transition of the CSP subarray to ON
        receptor_membership[unassigned_receptors[0]- 1] = 1
        prober_first = Probe(self.midcsp_master, 'receptorMembership', receptor_membership, f"Wrong state")
        Poller(10, 0.2).check(prober_first)
        prober_first = Probe(self.midcsp_subarray01, 'state', DevState.ON, f"Wrong state")
        Poller(10, 0.2).check(prober_first)
        prober_subarray_state = Probe(self.midcsp_subarray01, 'state', DevState.ON, f"Wrong state")
        Poller(10, 0.2).check(prober_subarray_state)

    def _setup_csp_subarray(self):
        # setup the CSP Subarray
        LOGGER.info("Reset subarray to DISABLE")
        self._reset_subarray_to_init_state()
        state = self.midcsp_subarray01.State()
        assert state == DevState.DISABLE
        #switch-on the CspMaster
        LOGGER.info("Switch on Master")
        self.midcsp_master.On("")
        # wait for the transition of the CSP subarray to OFF
        prober_first = Probe(self.midcsp_subarray01, 'state', DevState.OFF, f"Wrong state")
        Poller(10, 0.2).check(prober_first)
        state = self.midcsp_subarray01.State()
        assert state in [DevState.OFF],"assuming that mid_csp_subarray_01 is OFF"
        self.__set_csp_subarray_to_on()

    def _reset_subarray_to_init_state(self):
    def _reset_subarray_to_disable_state(self):
        try:
            state = self.midcsp_subarray01.State()
            LOGGER.info("Init CSP Subarray State:{}".format(state))
            LOGGER.info("CSP Subarray init State:{}".format(state))
            if state == DevState.DISABLE:
                return
            if state == DevState.ON:
@@ -88,18 +76,20 @@ class TestCspSubarrayConfiguration(TestBase):
                LOGGER.info("Remove all receptors")
                self.midcsp_subarray01.RemoveAllReceptors()
                # wait for the transition of the CSP subarray to OFF
                prober_first = Probe(self.midcsp_subarray01, 'state', DevState.OFF, f"Wrong state")
                Poller(7, 0.2).check(prober_first)
                prober_first = Probe(self.midcsp_master, 'state', DevState.ON, f"Wrong state")
                Poller(7, 0.2).check(prober_first)
                prober_subarray_state = Probe(self.midcsp_subarray01, 'state', DevState.OFF, f"Wrong state")
                Poller(7, 0.2).check(prober_subarray_state)
                prober_master_state = Probe(self.midcsp_master, 'state', DevState.ON, f"Wrong state")
                Poller(7, 0.2).check(prober_master_state)
            # Set the CSP subarray to OFF issuing the Standby command
            # on CSP Master
            state = self.midcsp_subarray01.State()
            if state == DevState.OFF:
                LOGGER.info("State is OFF...going to execute Standby")
                LOGGER.info("CSP Subarray State is OFF...going to execute Standby")
                self.midcsp_master.Standby("")
                prober_first = Probe(self.midcsp_subarray01, 'state', DevState.DISABLE, f"Wrong state")
                Poller(5, 0.2).check(prober_first)
                prober_subarray_state = Probe(self.midcsp_subarray01, 'state', DevState.DISABLE, f"Wrong state")
                Poller(5, 0.2).check(prober_subarray_state)
                prober_master_state = Probe(self.midcsp_master, 'state', DevState.STANDBY, f"Wrong state")
                Poller(7, 0.2).check(prober_master_state)

        except tango.DevFailed as tango_err:
            LOGGER.warn(f"Unable to reset subarray to init state")
@@ -111,72 +101,106 @@ class TestCspSubarrayConfiguration(TestBase):
            configuration_string = json_file.read().replace("\n", "")
            return configuration_string
        except Exception as e:
            LOGGER.debug(f"Unable to locate file {filename}")
            LOGGER.warn(f"Unable to locate file {filename}")

    def _setup_csp_subarray(self):
        """
        Set the CSP Subarray state to ON
        """
        LOGGER.info("Setup subarray")
        self._reset_subarray_to_disable_state()
        # switch-on the CspMaster to force CSP Subarray
        # transition to OFF
        LOGGER.info("Switch on Master")
        self.midcsp_master.On("")
        # wait for the transition of the CSP subarray to OFF
        prober_subarray_state = Probe(self.midcsp_subarray01, 'state', DevState.OFF, f"Wrong state")
        Poller(10, 0.2).check(prober_subarray_state)
        state = self.midcsp_subarray01.State()
        assert state in [DevState.OFF],"assuming that mid_csp_subarray_01 is OFF"
        self.__set_csp_subarray_to_on()


    def test_send_configure_to_cbf_and_json_stored(self):
        """
        Configure the CSP Subarray with a JSon string including
        the new ADR4 fields.
        """
        time.sleep(3)
        prober_first = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong state")
        Poller(5, 0.2).check(prober_first)
        configuration_string = self._prepare_configuration_string()
        state = self.midcsp_subarray01.State()
        assert state == DevState.ON
        #prober_subarray_obstate = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE, f"Wrong state")
        #Poller(5, 0.2).check(prober_subarray_obstate)
        self._setup_csp_subarray()
        configuration_string = self._prepare_configuration_string()
        state = self.midcsp_subarray01.State()
        assert state == DevState.ON, "assume the CSP subarray State is ON"
        # exercise the device
        LOGGER.debug("sending configure:{}".format(configuration_string))
        LOGGER.debug(f"sending configure:{configuration_string}")
        LOGGER.info("Send configuration command")
        self.midcsp_subarray01.Configure(configuration_string)
        prober_first = Probe(self.midcsp_subarray01, 'obsState', ObsState.READY, f"Wrong state")
        Poller(5, 0.2).check(prober_first)
        prober_subarray_obstate = Probe(self.midcsp_subarray01, 'obsState', ObsState.READY, f"Wrong CSP Subarray obsState")
        Poller(5, 0.2).check(prober_subarray_obstate)
        # check
        # The CSP Subarray ObsState is READY
        obs_state = self.midcsp_subarray01.obsState
        assert obs_state == ObsState.READY
        # stored json string equal to the sent one
        stored_json = self.midcsp_subarray01.validScanConfiguration
        assert stored_json == configuration_string 
        
    def test_json_without_configuration_id(self):
    def test_configure_with_json_missing_configId(self):
        """
        Configure the CSP Subarray sending a json configuration script 
        without the configID entry. 
        """
        # setup the test
        configuration_string = self._prepare_configuration_string("test_ConfigureScan_without_configID.json")
        # Set the CSP Subarray to ON-IDLE state
        state = self.midcsp_subarray01.State()
        self._setup_csp_subarray()
        configuration_string = self._prepare_configuration_string("test_ConfigureScan_without_configID.json")

        # exercise the device
        with pytest.raises(tango.DevFailed) as df:
            self.midcsp_subarray01.Configure(configuration_string)
            time.sleep(3)
        # check
        obs_state = self.midcsp_subarray01.obsState
        assert obs_state == ObsState.IDLE

    def test_cspsubarray_wrong_state_for_configure(self):
    def test_configure_with_cspsubarray_in_wrong_state(self):
        """
        Set the CSP Subarray in a wrong state and issue the
        Configure command on it
        Configure command on it.
        """
        # setup the test: Subarray DISABLE-IDLE
        self._setup_csp_subarray()
        self._reset_subarray_to_disable_state()
        configuration_string = self._prepare_configuration_string()
        LOGGER.debug("configuration string:{}".format(configuration_string))
        self._reset_subarray_to_init_state()
        obs_state = self.midcsp_subarray01.obsState
        assert obs_state == ObsState.IDLE
        state = self.midcsp_subarray01.State()
        assert state == DevState.DISABLE
        init_state = self.midcsp_subarray01.State()

        # exercise the device
        with pytest.raises(tango.DevFailed) as df:
            self.midcsp_subarray01.Configure(configuration_string)
        if df:
            LOGGER.info("Command configure failed with er {}".format(str(df.value.args[0].desc)))
            err_msg = str(df.value.args[0].desc)
            LOGGER.info(f"Command configure failed with error: {err_msg}")
        # check
        # Subarray final ObsState IDLE
        obs_state = self.midcsp_subarray01.obsState
        end_state = self.midcsp_subarray01.State()
        assert obs_state == ObsState.IDLE 
        assert end_state == init_state 

    def test_configure_with_cbf_invalid_json(self):
        """
        Set the CSP Subarray in a wrong state and issue the
        Configure command on it.
        """
        # setup the test: Subarray DISABLE-IDLE
        self._setup_csp_subarray()
        configuration_string = self._prepare_configuration_string()
        init_state = self.midcsp_subarray01.State()

        # exercise the device
        self.midcsp_subarray01.Configure(configuration_string)
        # check
        # Subarray final ObsState IDLE
        prober_subarray_flag = Probe(self.midcsp_subarray01, 'failureRaisedFlag', True, f"Failure flag is false")
        Poller(5, 0.2).check(prober_subarray_flag)
        #failure_flag = self.midcsp_subarray01.failureRaisedFlag
        #assert failure_flag