示例#1
0
    def set_logLevels(self, logger_name, levels):
        """
        Set the default log level for this component.

        Parameter:
        logger_name - name of the component's logger
        levels - maci.LoggingConfigurable.LogLevels instance containing default log level values

        Raises: LoggerDoesNotExistExImpl if the logger is not active.
        """
        if Log.doesLoggerExist(logger_name):
            Log.getLogger(logger_name).setLevels(levels)
        else:
            raise LoggerDoesNotExistExImpl()
示例#2
0
 def testNestedOutput(self):
     """SeveralLoggerCheck messages are logged only once for nested loggers"""
     nlogger = Log.getLogger("MyLogger1.child")
     before = len(Log.CENTRALHANDLER.buffer)
     nlogger.logInfo("Nested Message")
     after =  len(Log.CENTRALHANDLER.buffer)
     self.assertEqual(1, after - before)
     Log.CENTRALHANDLER.buffer = []
示例#3
0
 def testNestedOutput(self):
     """SeveralLoggerCheck messages are logged only once for nested loggers"""
     nlogger = Log.getLogger("MyLogger1.child")
     before = len(Log.CENTRALHANDLER.buffer)
     nlogger.logInfo("Nested Message")
     after = len(Log.CENTRALHANDLER.buffer)
     self.assertEqual(1, after - before)
     Log.CENTRALHANDLER.buffer = []
示例#4
0
    def __init__(self, sourceName = None, hostName = None):
        """
        Create an instance of the AlarmSystemInterface.

        Parameters:  sourceName is the name of this source
                     hostName is the name of the computer where the source is running.
        """
        self.logger = Log.getLogger()
        self.sourceName = sourceName
        self.hostName = hostName
        self.configuration = ASI.ASIConfiguration()
示例#5
0
    def __init__(self, sourceName=None, hostName=None):
        """
        Create an instance of the AlarmSystemInterface.

        Parameters:  sourceName is the name of this source
                     hostName is the name of the computer where the source is running.
        """
        self.logger = Log.getLogger()
        self.sourceName = sourceName
        self.hostName = hostName
        self.configuration = ASI.ASIConfiguration()
示例#6
0
    def get_logLevels(self, logger_name):
        """
        Retrieve the log levels for a given component.

        Parameter:
        logger_name - name of the component's logger

        Returns: maci.LoggingConfigurable.LogLevels instance containing the logger's log level values

        Raises: LoggerDoesNotExistExImpl if the logger is not active.
        """
        if Log.doesLoggerExist(logger_name):
            return Log.getLogger(logger_name).getLevels()
        else:
            raise LoggerDoesNotExistExImpl()
示例#7
0
    def configureComponentLogger(self, name):
        '''
        Configure the logger for the given component name from the values in the CDB.

        Parameters:
        name is the name of the component
        '''
        # Each component has an associated logger instance
        clogger = Log.getLogger(name)

        # Default levels are used for missing values
        defaultlevels = Log.getDefaultLevels()
        
        try:
            #Get the global unnamed logging config to retrieve the maxLogsPerSecond attribute
            logconfigG = self.cdbAccess.getElement("MACI/Containers/"  + self.name + "/LoggingConfig", "LoggingConfig")
            maxLogsPerSec = int(logconfigG[0]['maxLogsPerSecond'])
        except (Exception):
            # No value was supplied so default is used
            maxLogsPerSec = -1
        
        try:
            # Process all the named logger configurations
            logconfig = self.cdbAccess.getElement("MACI/Containers/"  + self.name + "/LoggingConfig", "LoggingConfig/log:_")
            for cfg in logconfig:
                if cfg["Name"] == name:
                    try:
                        centrallevel = int(cfg['minLogLevel'])
                    except KeyError:
                        # No value was supplied so default is used
                        centrallevel = defaultlevels.minLogLevel
                    try:
                        locallevel = int(cfg['minLogLevelLocal'])
                    except KeyError:
                        # No value was supplied so default is used
                        locallevel = defaultlevels.minLogLevelLocal
                    
                    clogger.setLevels(maci.LoggingConfigurable.LogLevels(False, centrallevel, locallevel))
                    clogger.configureLogging(maxLogsPerSec)
                    # There should only be one entry per logger so we are done
                    break
            else:
                # No matching named logger was found so the default values are used
                clogger.setLevels(maci.LoggingConfigurable.LogLevels(True, 0, 0))
        except Exception:
            # No named loggers were defined so the default values are used
            clogger.setLevels(maci.LoggingConfigurable.LogLevels(True, 0, 0))
示例#8
0
 def setUp(self):
     self.pname = "MyLogger1"
     self.plogger = Log.getLogger(self.pname)
     self.cname = "MyLogger2"
     self.clogger = Log.getLogger(self.cname)
示例#9
0
 def setUp(self):
     self.mylogger = Log.getLogger()
示例#10
0
class AlarmSystemInterfaceFactory(object):
    """
    Base class for creating sources and fault states.
    """
    logger = Log.getLogger("AlarmSystemInterfaceFactory")
    manager = None
    systemtype = None
    initialized = False
    registry = {}

    @classmethod
    def init(cls, man=None):
        """
        Initializes the factory.  This method must be called before using
        the other methods of this class.

        Returns: None
        """
        cls.logger.logTrace("AlarmSystemInterfaceFactory::init() entering.")
        cls.manager = man
        cls.initialized = True

        try:
            import ACSAlarmSystemInterfaceProxy as ACSProxy
            cls.registry['ACS'] = ACSProxy.ACSAlarmSystemInterfaceProxy
        except:
            pass

        try:
            import CERNAlarmSystemInterfaceProxy as CERNProxy
            cls.registry['CERN'] = CERNProxy.CERNAlarmSystemInterfaceProxy
        except:
            pass

        # Parse the CDB to get the system type
        cdb = CDBAccess.CDBaccess()
        try:
            ln = cdb.getField(
                'Alarms/Administrative/AlarmSystemConfiguration',
                'AlarmSystemConfiguration/configuration-property')
            doc = AcsAlarmSystem_xsd.minidom.parseString(ln)
            rootNode = doc.documentElement
            rootObj = AcsAlarmSystem_xsd.alarm_system_configurationListType.factory(
            )
            rootObj.build(rootNode)
            cls.systemtype = rootObj.get_configuration_property()[0].valueOf_
        except:
            cls.systemtype = 'ACS'

        cls.logger.logDebug("Using %s alarm system" % cls.systemtype)
        cls.logger.logTrace("AlarmSystemInterfaceFactory::init() exiting.")

    @classmethod
    def done(cls):
        """
        Release the resources held by the factory.  This method must be called
        when the client is finished using the factory.

        Returns:  None
        """
        cls.logger.logTrace("AlarmSystemInterfaceFactory::done() entering.")
        cls.manager = None
        cls.initialized = False
        cls.systemtype = None
        cls.registry = {}
        cls.logger.logTrace("AlarmSystemInterfaceFactory::done() exiting.")

    @classmethod
    def createSource(cls, sourceName=None):
        """
        Create a new instance of an alarm system interface.

        Parameters: sourceName is the name of the alarm source

        Returns: an instance of the appropriate interface

        Raises:  exception if factory has not been initialized
        """
        cls.logger.logTrace(
            "AlarmSystemInterfaceFactory::createSource() entering.")
        if not cls.initialized:
            raise ErrFactory.ACSASFactoryNotInitedExImpl()
        cls.logger.logTrace(
            "AlarmSystemInterfaceFactory::createSource() exiting.")
        return cls.registry[cls.systemtype](sourceName)

    @classmethod
    def createFaultState(cls, family=None, member=None, code=None):
        """
        Create a new instance of a fault state.

        Parameters: family is the name of the alarm family for this fault
                    member is the name of the member of the alarm family for this fault
                    code is the error code for this fault

        Returns: an instance of FaultState

        Raises:  exception if factory has not been initialized
        """
        cls.logger.logTrace(
            "AlarmSystemInterfaceFactory::createFaultState() entering.")
        if not cls.initialized:
            raise ErrFactory.ACSASFactoryNotInitedExImpl()
        cls.logger.logTrace(
            "AlarmSystemInterfaceFactory::createFaultState() exiting.")
        return FaultState.FaultState(family, member, code)
示例#11
0
 def setUp(self):
     self.logger = Log.getLogger("dispatchcheck")
     self.logger.stdouthandler = mock.Mock()
     self.logger.handlers[0] = self.logger.stdouthandler
示例#12
0
    def __init__ (self, name):
        '''
        Constructor.

        Initializes member variables and CORBA

        Parameters: name is the stringified name of this container.

        Raises: ???
        '''

        print maci.Container.ContainerStatusStartupBeginMsg
        #Member variables
        self.isReady = Event()
        self.running = 1  #As long as this is true, container is not shutdown
        self.name = name  #Container Name
        self.canRecover = True  #Whether this container is capable of recovery
        self.components = {}  #A dict where components are referenced by name
        self.compHandles = {}  #A dict where comp names are referenced by handles
        self.shutdownHandles = []
        self.containerPOA = None  #POA to activate this container
        self.componentPOA = None  #POA to create POAs for components
        self.compPolicies = []  #Policy[] for components
        self.offShootPolicies = []  #Policy[] for offshoots
        self.corbaRef = None  #reference to this object's CORBA reference
        self.logger = Log.getLogger(name) # Container's logger
        self.client_type = maci.CONTAINER_TYPE
        self.cdbContainerInfo = {}
        self.autoLoadPackages = []
        #dictionary which maps package names to the number of active components
        #using said package
        self.compModuleCount = {}
        
        # Initialize the alarm factory
        Acsalarmpy.AlarmSystemInterfaceFactory.init(ACSCorba.getManager())
        # The alarm source
        self.alarmSource = None
        
        # The interface to receive notification from the LogThrottle 
        # for sending alarms
        self.clta=ContainerLogThrottleAlarmer(self)

        #Configure CORBA
        print maci.Container.ContainerStatusORBInitBeginMsg
        self.configCORBA()
        print maci.Container.ContainerStatusORBInitEndMsg

        #call superclass constructor
        print maci.Container.ContainerStatusMgrInitBeginMsg
        BaseClient.__init__(self, self.name)
        print maci.Container.ContainerStatusMgrInitEndMsg

        self.logger.logTrace('CORBA configured for Container: ' + self.name)

        self.cdbAccess = CDBaccess()

        self.logger.logTrace('Starting Container: ' + self.name)

        #get info from the CDB
        self.getCDBInfo()
        self.refresh_logging_config()
        self.configureComponentLogger(name)

        #Run everything
        self.logger.logInfo('Container ' + self.name + ' waiting for requests')
        self.isReady.set()
        print maci.Container.ContainerStatusStartupEndMsg
        sys.stdout.flush()
示例#13
0
 def setUp(self):
     self.pname = "MyLogger1"
     self.plogger = Log.getLogger(self.pname)
     self.cname = "MyLogger2"
     self.clogger = Log.getLogger(self.cname)
示例#14
0
 def setUp(self):
     self.mylogger = Log.getLogger()
示例#15
0
 def setUp(self):
     self.logger = Log.getLogger("dispatchcheck")
     self.logger.stdouthandler = mock.Mock()
     self.logger.handlers[0] = self.logger.stdouthandler
示例#16
0
 def setUp(self):
     self.logger = Log.getLogger("dispatchcheck")
     self.logger.stdouthandler = mock.Mock()
     self.logger.handlers[0] = self.logger.stdouthandler
     Log.CENTRALHANDLER.buffer = []
示例#17
0
 def setUp(self):
     self.logger = Log.getLogger("dispatchcheck")
     self.logger.stdouthandler = mock.Mock()
     self.logger.handlers[0] = self.logger.stdouthandler
     Log.CENTRALHANDLER.buffer = []