Commit 3ca96847 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

AT5-262: change to the healthState update logic.

Note: forwarded attributes reporting the CSP Capability addresses
don't work: fault when forwarded attributes are array of strings
parent 657a6c6b
Loading
Loading
Loading
Loading
+26 −22
Original line number Diff line number Diff line
@@ -137,6 +137,9 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                        self._se_state[dev_name] = evt.attr_value.value
                        
                    elif evt.attr_value.name.lower() == "healthstate":
                        print("{}: received event on {} value {}".format(dev_name,
                                                                         evt.attr_value.name,
                                                                         evt.attr_value.value))
                        self._se_health_state[dev_name] = evt.attr_value.value
                    elif evt.attr_value.name.lower() == "adminmode":
                        print("device: {} adminMode value {}".format(dev_name,evt.attr_value.value ))
@@ -155,7 +158,9 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                                                          str(evt.attr_value.value))
                self.dev_logging(log_msg, tango.LogLevel.LOG_INFO)
                # update CSP global state
                if evt.attr_value.name.lower() in ["state", "healthstate"]:
                # healthState and State are updated accordingly to the updated values of
                # sub-elements healthState, State and adminMode
                if evt.attr_value.name.lower() in ["state", "healthstate", "adminmode"]:
                    self._update_csp_state()
            except tango.DevFailed as df:
                self.dev_logging(str(df.args[0].desc), tango.LogLevel.LOG_ERROR)
@@ -315,27 +320,29 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # The whole CSP HealthState is OK only if:
        # - all sub-elements with adminMode ON-LINE or MAINTENACE are ON AND
        # - each sub-element HealthState is OK
        admin_fqdn = [fqdn for fqdn, admin_value in self._se_admin_mode.items()
                      if admin_value in [AdminMode.ONLINE, AdminMode.MAINTENANCE]]
        health_fqdn = [fqdn for fqdn, health_value in self._se_health_state.items()
                       if health_value == HealthState.OK]
        state_fqdn =  [fqdn for fqdn, state_value in self._se_state.items()
                       if state_value in [tango.DevState.ON, tango.DevState.STANDBY]]
        admin_fqdn.sort()
        health_fqdn.sort()
        state_fqdn.sort()
        
        # default value to DEGRADED
        self._health_state = HealthState.DEGRADED
        if self.CspCbf not in admin_fqdn:
            if admin_fqdn == health_fqdn == state_fqdn:
                self._healthstate = HealthState.OK
        # build the list of all the sub-elements ONLINE/MAINTENANCE
        admin_fqdn = [fqdn for fqdn, admin_value in self._se_admin_mode.items()
                      if admin_value in [AdminMode.ONLINE, AdminMode.MAINTENANCE]]
        # build the list of sub-elements with State ON/STANDBY and ONLINE/MAINTENANCE
        state_fqdn =  [fqdn for fqdn in admin_fqdn if self._se_state[fqdn] in [tango.DevState.ON,
                                                                               tango.DevState.STANDBY]]
        # build the list with the healthState of the devices contributing to 
        # determine the CSP healthState
        health_list = [self._se_health_state[fqdn] for fqdn in state_fqdn]
        
        if self.CspCbf in admin_fqdn:
            if all(value == HealthState.OK for value in health_list):
                self._health_state = HealthState.OK
            elif self._se_health_state[self.CspCbf] in [HealthState.FAILED,
                                                      HealthState.UNKNOWN,
                                                      HealthState.DEGRADED]:
                self._healthstate = self._se_health_state[self.CbfSubarray]
                self._health_state = self._se_health_state[self.CspCbf]
        else:
            # if CBF is not ONLINE/MAINTENANCE ....
            self._healthstate = self._se_health_state[self.CspCbf]
            self._health_state = self._se_health_state[self.CspCbf]
        return
    
    def _connect_to_subelements (self):
@@ -365,9 +372,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                # Note: subscription is performed also for devices not ONLINE/MAINTENANCE.
                # In this way the CspMaster is able to detect a change in the admin value.
                
                # if the sub-element device is running,the adminMode is updated here
                # adminMode has to be subscribed first so that healthState and State are
                # updated accordingly with its value!
                
                ev_id = device_proxy.subscribe_event("adminMode",
                                                     EventType.CHANGE_EVENT,
                                                     self._se_scm_change_event_cb,
@@ -1667,7 +1672,6 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
    def read_numOfDevCompletedTask(self):
        # PROTECTED REGION ID(CspMaster.numOfDevCompletedTask_read) ENABLED START #
        """Return the numOfDevCompletedTask attribute."""
        print(self._num_dev_completed_task)
        if not self._last_executed_command:
            return 0
        return self._num_dev_completed_task[self._last_executed_command]
@@ -1676,7 +1680,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
    def read_onCmdAlarm(self):
        # PROTECTED REGION ID(CspMaster.onCmdAlarm_read) ENABLED START #
        """Return the onCmdAlarm attribute."""
        return self._alarm_expired['on']
        return self._alarm_raised['on']
        # PROTECTED REGION END #    //  CspMaster.onCmdAlarm_read

    def read_onAlarmMessage(self):
@@ -1688,7 +1692,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
    def read_offCmdAlarm(self):
        # PROTECTED REGION ID(CspMaster.offCmdAlarm_read) ENABLED START #
        """Return the offCmdAlarm attribute."""
        return self._alarm_expired['off']
        return self._alarm_raised['off']
        # PROTECTED REGION END #    //  CspMaster.offCmdAlarm_read

    def read_offAlarmMessage(self):
@@ -1700,7 +1704,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
    def read_standbyCmdAlarm(self):
        # PROTECTED REGION ID(CspMaster.standbyCmdAlarm_read) ENABLED START #
        """Return the standbyCmdAlarm attribute."""
        return self._alarm_expired['standby']
        return self._alarm_raised['standby']
        # PROTECTED REGION END #    //  CspMaster.standbyCmdAlarm_read

    def read_standbyAlarmMessage(self):