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

AT5-262: Move to new lmcbaseclasses release (>= 0.2.0).

Removed unused inherited attributes.
parent b2479f20
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -35,12 +35,7 @@ from tango import AttrWriteType, PipeWriteType

from skabase.SKABaseDevice import SKABaseDevice
from skabase.auxiliary import utils
# add the path to import global_enum package.
file_path = os.path.dirname(os.path.abspath(__file__))
utils_path = os.path.abspath(os.path.join(file_path, os.pardir)) + "/utils"
sys.path.insert(0, utils_path)
import cspcommons
from cspcommons import HealthState, AdminMode, ObsState, ObsMode
from .utils.cspcommons import HealthState, AdminMode, ObsState
 
# PROTECTED REGION END #    //  CspCapabilityMonitor.additionnal_import

@@ -153,8 +148,11 @@ class CspCapabilityMonitor(with_metaclass(DeviceMeta,SKABaseDevice)):
        self._csp_tango_db = tango.Database()
        attribute_properties = self._csp_tango_db.get_device_attribute_property(self.get_name(),
                                                                          {'adminMode': ['__value']})
        try:
            admin_mode_memorized = attribute_properties['adminMode']['__value']
            self._admin_mode = int(admin_mode_memorized[0])
        except keyError as key_err:
            self.logger.info("No {} key found".format(str(key_err)))
        self._connect_to_capability()
        self._healthState = HealthState.OK
        self.set_state(tango.DevState.ON)
@@ -235,9 +233,9 @@ class CspCapabilityMonitor(with_metaclass(DeviceMeta,SKABaseDevice)):
                log_msg = "New value for {} is {}".format(str(evt.attr_name),
                                                          str(evt.attr_value.value))
            except tango.DevFailed as df:
                self.dev_logging(str(df.args[0].desc), tango.LogLevel.LOG_ERROR)
                self.logger.error(str(df.args[0].desc))
            except Exception as except_occurred:
                self.dev_logging(str(except_occurred), tango.LogLevel.LOG_ERROR)
                self.logger.error(str(except_occurred))
        else:
            for item in evt.errors:
                # API_EventTimeout: if sub-element device not reachable it transitions
@@ -273,12 +271,12 @@ class CspCapabilityMonitor(with_metaclass(DeviceMeta,SKABaseDevice)):
                       "on device {}. Reason: {}".format(event_id,
                                                         fqdn,
                                                         key_err))
                self.dev_logging(msg, tango.LogLevel.LOG_ERROR)
                self.logger.error(msg)
        # remove the events id from the list
        for k in _event_id[fqdn].remove(k):
            if self._event_id[fqdn]:
                msg = "Still subscribed events: {}".format(self._event_id)
                self.dev_logging(msg, tango.LogLevel.LOG_WARN)
                self.logger.warn(msg)
            else:
                # remove the dictionary element
                self._event_id.pop(fqdn)
+13 −24
Original line number Diff line number Diff line
@@ -320,8 +320,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # 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
        # build the list with the healthState of ONLINE/MAINTENANCE devices 
        health_list = [self._se_health_state[fqdn] for fqdn in state_fqdn]
        
        if self.CspCbf in admin_fqdn:
@@ -510,7 +509,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                        self.logger.info("measured duration:", se_cmd_duration_measured[device][cmd_name])
                        self._se_cmd_progress[device][cmd_name] = 100
                        # command success: exit from the wait loop and issue the command
                        # on the next device of the list
                        # on the next device in the list
                        break
                    # check for other sub-element device State values
                    if self._se_state[device] in [tango.DevState.FAULT, tango.DevState.ALARM]:
@@ -525,10 +524,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                    # NOTE: as per the "SKA Control Guidelines", a sub-element shall not throw an
                    # exception if the sub-element is already in the requested final state or if the
                    # command is already running.
                    # A different behaviour causes a wrong behavior of the current function. If for
                    # example the sub-element raises an exception if the device is already ON when On
                    # command is issued, the cmd_end_cb calbback is invoked and the alarm flag is set:
                    # the device results failed, but this is not true.
                    # A different implementation could cause a wrong behavior of the current function.
                    if self._se_cmd_execution_state[device][cmd_name] == CmdExecState.FAILED:
                        # execution ended for this sub-element, skip to the next one
                        num_of_failed_device += 1
@@ -639,7 +635,11 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                                 self.TimingBeamsMonitor,
                                 self.VlbiBeamsMonitor]
        for fqdn in self._capability_fqdn:
            try:
                self._capability_proxy[fqdn] = tango.DeviceProxy(fqdn)
            except tango.Except as tango_err:
                self.logger.warn(tango_err.args[0].desc)
            
                
# PROTECTED REGION END #    //  CspMaster.class_protected_methods
    # -----------------
@@ -1167,15 +1167,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # Note: a memorized attribute has defined the attribute
        # property '__value'
        attribute_properties = csp_tango_db.get_device_attribute_property(self.get_name(),
                                                                          {'adminMode': ['__value'],
                                                                           'storageLoggingLevel': ['__value'],
                                                                           'elementLoggingLevel': ['__value'],
                                                                           'centralLoggingLevel': ['__value'],})
        
        # set storage and element logging level
        self._storage_logging_level = int(tango.LogLevel.LOG_INFO)
        self._element_logging_level = int(tango.LogLevel.LOG_INFO)
        self._central_logging_level = int(tango.LogLevel.LOG_WARN)
                                                                          {'adminMode': ['__value']})
        # set init values for the CSP Element and Sub-element SCM states
        self.set_state(tango.DevState.INIT)
        self._health_state = HealthState.OK
@@ -1196,7 +1188,6 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                                                         if key == '__value'}
        try:
            self._admin_mode = memorized_attr_dict['adminMode']
            self._storage_logging_level = memorized_attr_dict['storageLoggingLevel']
        except KeyError as key_err:
            self.logger.info("Key {} not found".format(key_err))
        
@@ -1229,7 +1220,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                self.logger.info(msg)
                                                                                      
        # _se_proxies: the sub-element proxies
        # implementes s a dictionary:
        # implemented as dictionary:
        # keys: sub-element FQDN
        # values: device proxy
        self._se_proxies = {}
@@ -1345,7 +1336,6 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # start CSP Capbilities monitoring
        self._connect_capabilities_monitor()       
              
                
        # to use the push model in command_inout_asynch (the one with the callback parameter),
        # change the global TANGO model to PUSH_CALLBACK.
        apiutil = tango.ApiUtil.instance()
@@ -1869,7 +1859,6 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
            return False
        return True
    

    @command(
        dtype_in='DevVarStringArray',
        doc_in=("If the array length is 0, the command applies to the whole CSP Element. "
+14 −16
Original line number Diff line number Diff line
@@ -22,13 +22,11 @@ class AdminModeCheck(object):
            # Check the AdminMode value: the command is callable only if the 
            # the administration mode is ONLINE or MAINTENACE
            
            if dev_instance._admin_mode in [AdminMode.OFFLINE, AdminMode.NOTFITTED,
                                   AdminMode.RESERVED]:
                # NOTE: when adminMode is NOT_FITTED, OFFLINE or RESERVED device itself
                # sets the TANGO state to DISABLE
            if dev_instance._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]:
                # NOTE: when adminMode is not ONLINE/MAINTENANCE the device State has to be
                # DISABLE
                # Add only a check on State value to log a warning message if it
                # is different from DISABLE
                #msg_args = (cmd_to_execute, dev_instance.get_state(), dev_instance._admin_mode.name)
                msg_args = (self._cmd_to_execute, dev_instance.get_state(), AdminMode(dev_instance._admin_mode).name)
                if dev_instance.get_state() != tango.DevState.DISABLE:
                    dev_instance.logger.warn("Command {}: incoherent device State {} "
@@ -93,8 +91,8 @@ class CmdInputArgsCheck(object):
    """
    Class designed to be a decorator for the CspMaster methods.
    The *decorator function* performs a check on the function input argument,
    detecting if the corresponding servers are running and the device
    administrative mode are in the right state to execute a command (i.e
    detecting if the corresponding servers are running and the 
    administrative mode of the devices has the right value to execute a command (i.e
    ONLINE/MAINTENACE)
    The *decorator function* accepts some parameters as input to customize
    its functionality
@@ -145,9 +143,9 @@ class CmdInputArgsCheck(object):
                    # with command execution
                    dev_instance.logger.warn("Too many input parameters")
            dev_instance.logger.debug("CmdInputArgsCheck: devices {}  to check:".format(device_list))
            # If a sub-element device is already executing a power command throws an
            # exception only if the requested command is different from the one
            # is already running (power commands have to be executed sequentially).
            # If a sub-element device is already executing a power command, an exception is
            # thown only when the requested command is different from the one
            # already running (power commands have to be executed sequentially).
            # TODO: 
            # What to do if the required device is performing a software upgrade or is changing its 
            # adminMode? How can CSP.LMC detect this condition?
@@ -179,10 +177,11 @@ class CmdInputArgsCheck(object):
            # check for devices that are not ONLINE/MAINTENANCE                    
            device_to_remove = []
            for device in device_list:
                print("processing device:", device)
                self.logger.debug("CmdInputArgsCheack-processing device:", device)
                # if the sub-element device server is not running or the adminMode
                # attribute is not ONLINE or MAINTENANCE, skip to next and add it to 
                # the list of the devices to remove from the input arg list
                # attribute is not ONLINE or MAINTENANCE:
                # - schedule the device for removing from the input arg list
                # - skip to next device and 
                if (not dev_instance._is_device_running(device, dev_instance._se_proxies) or 
                    dev_instance._se_admin_mode[device] not in [AdminMode.ONLINE,
                                                       AdminMode.MAINTENANCE]):
@@ -240,8 +239,7 @@ class CmdInputArgsCheck(object):
                        dev_instance.logger.info(tango_err.args[0].desc)
                # evaluate the total timeout value to execute the whole command
                # note: if the xxxDurationExpected attribute read fails, it is used the default value
                # returned from the defauld dictionary used to initialize the _se_cmd_duration_expected
                # attribute
                # (xxxDurationExpected  initialized as defaultdict)
                command_timeout +=  dev_instance._se_cmd_duration_expected[device][cmd_to_exec]
            # device loop end
            # use the greatest value for the onCommand duration expected.
+2 −1
Original line number Diff line number Diff line
@@ -6,4 +6,5 @@ RUN ipython profile create
#install lmc-base-classes
USER root
RUN DEBIAN_FRONTEND=noninteractive pip3 install https://nexus.engageska-portugal.pt/repository/pypi/packages/lmcbaseclasses/0.2.0+6bb55a6e/lmcbaseclasses-0.2.0+6bb55a6e.tar.gz
CMD ["/venv/bin/python", "/app/csp-lmc-common/csp-lmc-common/CspMaster.py"]

CMD ["/venv/bin/python", "-m"," csp_lmc_common.CspMaster" ]
+6 −10
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ services:
    command: >
      sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict --
             retry --max=5 -- tango_admin --ping-device common/elt/master &&\
             /venv/bin/python /app/csp-lmc-common/CspSubarray.py comsub1"
             /venv/bin/python /app/csp_lmc_common/CspSubarray.py comsub1"
    volumes_from:
      - rsyslog-csplmc:rw

@@ -57,7 +57,7 @@ services:
    command: >
      sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict --
             retry --max=5 -- tango_admin --ping-device common/elt/master &&\
             /venv/bin/python /app/csp-lmc-common/CspSubarray.py comsub2"
             /venv/bin/python /app/csp_lmc_common/CspSubarray.py comsub2"
    volumes_from:
      - rsyslog-csplmc:rw

@@ -74,11 +74,7 @@ services:
    command: >
      sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict --
             retry --max=5 -- tango_admin --ping-device mid_csp_cbf/sub_elt/master &&\
             retry --max=5 -- tango_admin --ping-device common/elt/search_beams_monitor &&\
             retry --max=5 -- tango_admin --ping-device common/elt/timing_beams_monitor &&\
             retry --max=5 -- tango_admin --ping-device common/elt/vlbi_beams_monitor &&\
             retry --max=5 -- tango_admin --ping-device mid_csp_cbf/sub_elt/master &&\
             /venv/bin/python /app/csp-lmc-common/CspMaster.py commaster"
             /venv/bin/python -m csp_lmc_common.CspMaster commaster"
    volumes_from:
      - rsyslog-csplmc:rw

@@ -93,7 +89,7 @@ services:
      - TANGO_HOST=${TANGO_HOST}
    command: >
      sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict --
            /venv/bin/python /app/csp-lmc-common/CspCapabilityMonitor.py searchbeams"
            /venv/bin/python -m csp_lmc_common.CspCapabilityMonitor searchbeams"
    volumes_from:
      - rsyslog-csplmc:rw

@@ -108,7 +104,7 @@ services:
      - TANGO_HOST=${TANGO_HOST}
    command: >
      sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict --
            /venv/bin/python /app/csp-lmc-common/CspCapabilityMonitor.py timingbeams"
            /venv/bin/python -m csp_lmc_common.CspCapabilityMonitor timingbeams"
    volumes_from:
      - rsyslog-csplmc:rw

@@ -123,7 +119,7 @@ services:
      - TANGO_HOST=${TANGO_HOST}
    command: >
      sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict --
            /venv/bin/python /app/csp-lmc-common/CspCapabilityMonitor.py vlbibeams"
            /venv/bin/python -m csp_lmc_common.CspCapabilityMonitor vlbibeams"
    volumes_from:
      - rsyslog-csplmc:rw
  
Loading