class Resource(object): def __init__(self, identifier, execparams, propertydefs=(), loggerName=None): """propertydefs is a iterable of tuples that contain (propid, propname, type, mode, defaultvalue, units, action, kinds) defaultvalue should be None if there is no default, otherwise: simple - a single str, int, float, bool simple sequence - an iterable of str, int, float, or bool struct - a dictionary there the key is the "id" and the value is a tuple of (propname, type, mode) struct sequence - a iterable of dictionaries following the struct format """ self.propertySetAccess = threading.Lock() self._id = identifier self._started = False if loggerName == None: self._log = logging.getLogger(self._id) else: self._log = logging.getLogger(loggerName) self._name = execparams.get("NAME_BINDING", "") # The base resource class manages properties ... self._props = PropertyStorage(self, propertydefs, execparams) self._props.initialize() # ... and also manages ports self.__loadPorts() logging.trace("Initial property storage %s", self._props) ######################################### # CF::Resource def start(self): self._log.trace("start()") self._started = True def stop(self): self._log.trace("stop()") self._started = False def _get_identifier(self): return self._id def _get_started(self): return self._started ######################################### # CF::LifeCycle def initialize(self): self._log.trace("initialize()") def releaseObject(self): self._log.trace("releaseObject()") objid = self._default_POA().servant_to_id(self) self._default_POA().deactivate_object(objid) __orb__.shutdown(False) ######################################### # CF::PortSupplier def getPort(self, name): """The default behavior of getPort() will automatically return ports as defined by 'usesport' and 'providesport' static class attributes.""" self._log.trace("getPort(%s)", name) try: portdef = self.__ports[name] except KeyError: self._log.warning("getPort() could not find port %s", name) raise CF.PortSupplier.UnknownPort() else: port = portdef.__get__(self)._this() if not portdef.isValid(port): self._log.warning("getPort() for %s did match required repid", name) self._log.trace("getPort() --> %s", port) return port def __loadPorts(self): self.__ports = {} for name in dir(type(self)): attr = getattr(type(self), name) if isinstance(attr, _port): self.__ports[attr.name] = attr ######################################### # CF::TestableObject def runTest(self, testid, properties): """Override this function to provide the desired behavior.""" self._log.trace("runTest()") raise CF.Device.UnknownTest("unknown test: %s" % str(testid)) ######################################### # CF::PropertySet def query(self, configProperties): self.propertySetAccess.acquire() # If the list is empty, get all props if configProperties == []: self._log.trace("query all properties") try: rv = [] for propid in self._props.keys(): if self._props.has_id(propid) and self._props.isQueryable(propid): rv.append(CF.DataType(id=propid, value=self._props.query(propid))) except: self.propertySetAccess.release() raise # otherwise get only the requested ones else: self._log.trace("query %s properties", len(configProperties)) try: unknownProperties = [] for prop in configProperties: if self._props.has_id(prop.id) and self._props.isQueryable(prop.id): prop.value = self._props.query(prop.id) else: self._log.warning("property %s cannot be queried. valid Id: %s", prop.id, self._props.has_id(prop.id)) unknownProperties.append(prop) except: self.propertySetAccess.release() raise if len(unknownProperties) > 0: self._log.warning("query called with invalid properties %s", unknownProperties) self.propertySetAccess.release() raise CF.UnknownProperties(unknownProperties) rv = configProperties self.propertySetAccess.release() self._log.trace("query -> %s properties", len(rv)) return rv def configure(self, configProperties): self._log.trace("configure(%s)", configProperties) self.propertySetAccess.acquire() notSet = [] for prop in configProperties: try: if self._props.has_id(prop.id) and self._props.isConfigurable(prop.id): try: self._props.configure(prop.id, prop.value) except ValueError, e: self._log.warning("Invalid value provided to configure for property %s %s", prop.id, e) notSet.append(prop) else: self._log.warning("Tried to configure non-existent, readonly, or property with action not equal to external %s", prop.id) notSet.append(prop) except Exception, e: self._log.exception("Unexpected exception.") notSet.append(prop)
class Resource(object): def __init__(self, identifier, execparams, propertydefs=(), loggerName=None): """propertydefs is a iterable of tuples that contain (propid, propname, type, mode, defaultvalue, units, action, kinds) defaultvalue should be None if there is no default, otherwise: simple - a single str, int, float, bool simple sequence - an iterable of str, int, float, or bool struct - a dictionary there the key is the "id" and the value is a tuple of (propname, type, mode) struct sequence - a iterable of dictionaries following the struct format """ self.propertySetAccess = threading.Lock() self._id = identifier self._started = False if loggerName == None: self._log = logging.getLogger(self._id) else: self._log = logging.getLogger(loggerName) self._name = execparams.get("NAME_BINDING", "") # The base resource class manages properties ... self._props = PropertyStorage(self, propertydefs, execparams) self._props.initialize() # ... and also manages ports self.__loadPorts() logging.trace("Initial property storage %s", self._props) ######################################### # CF::Resource def start(self): self._log.trace("start()") self._started = True def stop(self): self._log.trace("stop()") self._started = False def _get_identifier(self): return self._id def _get_started(self): return self._started ######################################### # CF::LifeCycle def initialize(self): self._log.trace("initialize()") def releaseObject(self): self._log.trace("releaseObject()") objid = self._default_POA().servant_to_id(self) self._default_POA().deactivate_object(objid) __orb__.shutdown(False) ######################################### # CF::PortSupplier def getPort(self, name): """The default behavior of getPort() will automatically return ports as defined by 'usesport' and 'providesport' static class attributes.""" self._log.trace("getPort(%s)", name) try: portdef = self.__ports[name] except KeyError: self._log.warning("getPort() could not find port %s", name) raise CF.PortSupplier.UnknownPort() else: port = portdef.__get__(self)._this() if not portdef.isValid(port): self._log.warning("getPort() for %s did match required repid", name) self._log.trace("getPort() --> %s", port) return port def __loadPorts(self): self.__ports = {} for name in dir(type(self)): attr = getattr(type(self), name) if isinstance(attr, _port): self.__ports[attr.name] = attr ######################################### # CF::TestableObject def runTest(self, testid, properties): """Override this function to provide the desired behavior.""" self._log.trace("runTest()") raise CF.Device.UnknownTest("unknown test: %s" % str(testid)) ######################################### # CF::PropertySet def query(self, configProperties): self.propertySetAccess.acquire() # If the list is empty, get all props if configProperties == []: self._log.trace("query all properties") try: rv = [] for propid in self._props.keys(): if self._props.has_id(propid) and self._props.isQueryable( propid): rv.append( CF.DataType(id=propid, value=self._props.query(propid))) except: self.propertySetAccess.release() raise # otherwise get only the requested ones else: self._log.trace("query %s properties", len(configProperties)) try: unknownProperties = [] for prop in configProperties: if self._props.has_id(prop.id) and self._props.isQueryable( prop.id): prop.value = self._props.query(prop.id) else: self._log.warning( "property %s cannot be queried. valid Id: %s", prop.id, self._props.has_id(prop.id)) unknownProperties.append(prop) except: self.propertySetAccess.release() raise if len(unknownProperties) > 0: self._log.warning("query called with invalid properties %s", unknownProperties) self.propertySetAccess.release() raise CF.UnknownProperties(unknownProperties) rv = configProperties self.propertySetAccess.release() self._log.trace("query -> %s properties", len(rv)) return rv def configure(self, configProperties): self._log.trace("configure(%s)", configProperties) self.propertySetAccess.acquire() notSet = [] for prop in configProperties: try: if self._props.has_id(prop.id) and self._props.isConfigurable( prop.id): try: self._props.configure(prop.id, prop.value) except ValueError, e: self._log.warning( "Invalid value provided to configure for property %s %s", prop.id, e) notSet.append(prop) else: self._log.warning( "Tried to configure non-existent, readonly, or property with action not equal to external %s", prop.id) notSet.append(prop) except Exception, e: self._log.exception("Unexpected exception.") notSet.append(prop)
class Resource(object): def __init__(self, identifier, execparams, propertydefs=(), loggerName=None): """propertydefs is a iterable of tuples that contain (propid, propname, type, mode, defaultvalue, units, action, kinds) defaultvalue should be None if there is no default, otherwise: simple - a single str, int, float, bool simple sequence - an iterable of str, int, float, or bool struct - a dictionary there the key is the "id" and the value is a tuple of (propname, type, mode) struct sequence - a iterable of dictionaries following the struct format """ self.propertySetAccess = threading.Lock() self._id = identifier self._started = False ## ## logging context for the resource ## self.logLevel = logging.INFO self.logConfig = "" self.loggingMacros = ossie.logger.GetDefaultMacros() ossie.logger.ResolveHostInfo( self.loggingMacros ) self.loggingCtx = None self.loggingURL=None if loggerName == None: self._logid = self._id self._log = logging.getLogger(self._id) else: self._logid = loggerName self._log = logging.getLogger(loggerName) self.logListenerCallback=None self._name = execparams.get("NAME_BINDING", "") # The base resource class manages properties ... self._props = PropertyStorage(self, propertydefs, execparams) self._props.initialize() # ... and also manages ports self.__loadPorts() logging.trace("Initial property storage %s", self._props) def setAdditionalParameters(self, softwareProfile): self._softwareProfile = softwareProfile ######################################### # CF::Resource def start(self): self._log.trace("start()") self._started = True def stop(self): self._log.trace("stop()") self._started = False def _get_identifier(self): return self._id def _get_started(self): return self._started def _get_softwareProfile(self): return self._softwareProfile ######################################### # CF::LifeCycle def initialize(self): self._log.trace("initialize()") def releaseObject(self): self._log.trace("releaseObject()") objid = self._default_POA().servant_to_id(self) self._default_POA().deactivate_object(objid) __orb__.shutdown(False) ######################################### # CF::PortSupplier def getPort(self, name): """The default behavior of getPort() will automatically return ports as defined by 'usesport' and 'providesport' static class attributes.""" self._log.trace("getPort(%s)", name) try: portdef = self.__ports[name] except KeyError: self._log.warning("getPort() could not find port %s", name) raise CF.PortSupplier.UnknownPort() else: portobj = portdef.__get__(self) if portobj == None: self._log.warning("component did not implement port %s",name) raise CF.PortSupplier.UnknownPort() port = portobj._this() if not portdef.isValid(port): self._log.warning("getPort() for %s did match required repid", name) self._log.trace("getPort() --> %s", port) return port def __loadPorts(self): self.__ports = {} for name in dir(type(self)): attr = getattr(type(self), name) if isinstance(attr, _port): self.__ports[attr.name] = attr ######################################### # Common resource logging API # return logger assigned to resource def getLogger(self): return self._log # return a named logger def getLogger(self, logid, assignToResource=False): newLogger=logging.getLogger(logid) if assignToResource: self._logid = logid self._log = newLogger return newLogger # Apply a resource context to the set of logging Macros def setLoggingMacros(self, newTbl, applyCtx=False ): self.loggingMacros = newTbl if applyCtx and self.loggingCtx: self.loggingCtx.apply(self.loggingMacros ) # Apply a resource context to the set of logging Macros def setResourceContext(self, rscCtx ): if rscCtx: rscCtx.apply(self.loggingMacros ) self.loggingCtx = rscCtx def setLoggingContext(self, rscCtx ): # apply resource context to macro definitions if rscCtx: rscCtx.apply(self.loggingMacros ) self.loggingCtx = rscCtx elif self.loggingCtx : self.loggingCtx.apply(self.loggingMacros ) # load logging configuration url to resource self.setLogConfigURL( self.loggingURL ) # apply logging level self.setLogLevel( self._logid, self.loglevel ) # # set the logging context for the resouce. Use the contents of # of the url as the logging configuration data. If the # the file contains any predefined macros then then # apply the resource context object to the macro defintions. # After the configuration is established then set the # the appropriate level. The contents of the level correspond # to the command line options when a program starts. # # def setLoggingContext(self, logcfg_url, oldstyle_loglevel, rscCtx ): # test we have a logging URI if logcfg_url==None or logcfg_url=="" : ossie.logger.ConfigureDefault() else: # apply resource context to macro definitions if rscCtx: rscCtx.apply(self.loggingMacros ) self.loggingCtx = rscCtx # load logging configuration url to resource self.setLogConfigURL( logcfg_url ) # apply logging level if explicitly stated if oldstyle_loglevel != None and oldstyle_loglevel > -1 : self.setLogLevel( self._logid, ossie.logger.ConvertLogLevel(oldstyle_loglevel) ) else: _logLevel = ossie.logger.ConvertLog4ToCFLevel( logging.getLogger(None).getEffectiveLevel() ) def saveLoggingContext(self, logcfg_url, oldstyle_loglevel, rscCtx ): # apply resource context to macro definitions if rscCtx: rscCtx.apply(self.loggingMacros ) self.loggingCtx = rscCtx # test we have a logging URLx self.loggingURL = logcfg_url if logcfg_url==None or logcfg_url=="" : self.logConfig = ossie.logger.GetDefaultConfig() else: # try to process URL and grab contents try: cfg_data=ossie.logger.GetConfigFileContents( logcfg_url ) if cfg_data and len(cfg_data) > 0 : self.logConfig = ossie.logger.ExpandMacros( cfg_data, self.loggingMacros ) except: pass # apply logging level if explicitly stated if oldstyle_loglevel != None and oldstyle_loglevel > -1 : _logLevel = ossie.logger.ConvertLogLevel(oldstyle_loglevel) else: _logLevel = ossie.logger.ConvertLog4ToCFLevel( logging.getLogger(None).getEffectiveLevel() ) def setLogListenerCallback(self, loglistenerCB ): self.logListenerCallback=logListenerCB def addPropertyChangeListener(self, id, callback): self._props.addChangeListener(callback, id) ######################################### # CF::LogConfiguration def _get_log_level(self): return self.logLevel def _set_log_level(self, newLogLevel ): self.log_level( newLogLevel ) def log_level(self, newLogLevel=None ): if newLogLevel == None: return self.logLevel if self.logListenerCallback and callable(self.logListenerCallback.logLevelChanged): self.logLevel = newLogLevel; self.logListenerCallback.logLevelChanged(self._logid, newLogLevel) else: ossie.logger.SetLogLevel( self._logid, newLogLevel ) self.logLevel = newLogLevel def setLogLevel(self, logid, newLogLevel ): if self.logListenerCallback and callable(self.logListenerCallback.logLevelChanged): self.logLevel = newLogLevel; self.logListenerCallback.logLevelChanged(logid, newLogLevel) else: ossie.logger.SetLogLevel( logid, newLogLevel ) def getLogConfig(self): return self.logConfig def setLogConfig(self, new_log_config): if self.logListenerCallback and callable(self.logListenerCallback.logConfigChanged): self.logConfig = new_log_config; self.logListenerCallback.logConfigChanged(new_log_config) elif new_log_config: tcfg= ossie.logger.ConfigureWithContext( new_log_config, self.loggingMacros ) if tcfg: self.logConfig = tcfg else: pass def setLogConfigURL(self, log_config_url): if log_config_url: fc=ossie.logger.GetConfigFileContents( log_config_url ) self.loggingURL = log_config_url if fc and len(fc) > 0 : self.setLogConfig( fc ) ######################################### # CF::LogEventConsumer def retrieve_records(self, howMany, startingRecord ): howMany=0 return None def retrieve_records_by_date(self, howMany, to_timetStamp ): howMany=0 return None def retrieve_records_from_date(self, howMany, from_timetStamp ): howMany=0 return None ######################################### # CF::TestableObject def runTest(self, testid, properties): """Override this function to provide the desired behavior.""" self._log.trace("runTest()") raise CF.Device.UnknownTest("unknown test: %s" % str(testid)) ######################################### # CF::PropertySet def query(self, configProperties): self.propertySetAccess.acquire() # If the list is empty, get all props if configProperties == []: self._log.trace("query all properties") try: rv = [] for propid in self._props.keys(): if self._props.has_id(propid) and self._props.isQueryable(propid): try: value = self._props.query(propid) except Exception, e: self._log.error('Failed to query %s: %s', propid, e) value = any.to_any(None) rv.append(CF.DataType(propid, value)) except: self.propertySetAccess.release() raise # otherwise get only the requested ones else: self._log.trace("query %s properties", len(configProperties)) try: unknownProperties = [] for prop in configProperties: if self._props.has_id(prop.id) and self._props.isQueryable(prop.id): try: prop.value = self._props.query(prop.id) except Exception, e: self._log.error('Failed to query %s: %s', prop.id, e) else: self._log.warning("property %s cannot be queried. valid Id: %s", prop.id, self._props.has_id(prop.id)) unknownProperties.append(prop) except: self.propertySetAccess.release() raise if len(unknownProperties) > 0: self._log.warning("query called with invalid properties %s", unknownProperties) self.propertySetAccess.release() raise CF.UnknownProperties(unknownProperties) rv = configProperties self.propertySetAccess.release() self._log.trace("query -> %s properties", len(rv)) return rv def configure(self, configProperties): self._log.trace("configure(%s)", configProperties) self.propertySetAccess.acquire() notSet = [] for prop in configProperties: try: if self._props.has_id(prop.id) and self._props.isConfigurable(prop.id): try: self._props.configure(prop.id, prop.value) except ValueError, e: self._log.warning("Invalid value provided to configure for property %s %s", prop.id, e) notSet.append(prop) else: self._log.warning("Tried to configure non-existent, readonly, or property with action not equal to external %s", prop.id) notSet.append(prop) except Exception, e: self._log.exception("Unexpected exception.") notSet.append(prop)
class Resource(object): def __init__(self, identifier, execparams, propertydefs=(), loggerName=None): """propertydefs is a iterable of tuples that contain (propid, propname, type, mode, defaultvalue, units, action, kinds) defaultvalue should be None if there is no default, otherwise: simple - a single str, int, float, bool simple sequence - an iterable of str, int, float, or bool struct - a dictionary there the key is the "id" and the value is a tuple of (propname, type, mode) struct sequence - a iterable of dictionaries following the struct format """ self.propertySetAccess = threading.Lock() self._id = identifier self._started = False ## ## logging context for the resource ## self.logLevel = logging.INFO self.logConfig = "" self.loggingMacros = ossie.logger.GetDefaultMacros() ossie.logger.ResolveHostInfo(self.loggingMacros) self.loggingCtx = None self.loggingURL = None if loggerName == None: self._logid = self._id self._log = logging.getLogger(self._id) else: self._logid = loggerName self._log = logging.getLogger(loggerName) self.logListenerCallback = None self._name = execparams.get("NAME_BINDING", "") # The base resource class manages properties ... self._props = PropertyStorage(self, propertydefs, execparams) self._props.initialize() # ... and also manages ports self.__loadPorts() logging.trace("Initial property storage %s", self._props) def setAdditionalParameters(self, softwareProfile): self._softwareProfile = softwareProfile ######################################### # CF::Resource def start(self): self._log.trace("start()") self._started = True def stop(self): self._log.trace("stop()") self._started = False def _get_identifier(self): return self._id def _get_started(self): return self._started def _get_softwareProfile(self): return self._softwareProfile ######################################### # CF::LifeCycle def initialize(self): self._log.trace("initialize()") def releaseObject(self): self._log.trace("releaseObject()") objid = self._default_POA().servant_to_id(self) self._default_POA().deactivate_object(objid) __orb__.shutdown(False) ######################################### # CF::PortSupplier def getPort(self, name): """The default behavior of getPort() will automatically return ports as defined by 'usesport' and 'providesport' static class attributes.""" self._log.trace("getPort(%s)", name) try: portdef = self.__ports[name] except KeyError: self._log.warning("getPort() could not find port %s", name) raise CF.PortSupplier.UnknownPort() else: portobj = portdef.__get__(self) if portobj == None: self._log.warning("component did not implement port %s", name) raise CF.PortSupplier.UnknownPort() port = portobj._this() if not portdef.isValid(port): self._log.warning("getPort() for %s did match required repid", name) self._log.trace("getPort() --> %s", port) return port def __loadPorts(self): self.__ports = {} for name in dir(type(self)): attr = getattr(type(self), name) if isinstance(attr, _port): self.__ports[attr.name] = attr ######################################### # Common resource logging API # return logger assigned to resource def getLogger(self): return self._log # return a named logger def getLogger(self, logid, assignToResource=False): newLogger = logging.getLogger(logid) if assignToResource: self._logid = logid self._log = newLogger return newLogger # Apply a resource context to the set of logging Macros def setLoggingMacros(self, newTbl, applyCtx=False): self.loggingMacros = newTbl if applyCtx and self.loggingCtx: self.loggingCtx.apply(self.loggingMacros) # Apply a resource context to the set of logging Macros def setResourceContext(self, rscCtx): if rscCtx: rscCtx.apply(self.loggingMacros) self.loggingCtx = rscCtx def setLoggingContext(self, rscCtx): # apply resource context to macro definitions if rscCtx: rscCtx.apply(self.loggingMacros) self.loggingCtx = rscCtx elif self.loggingCtx: self.loggingCtx.apply(self.loggingMacros) # load logging configuration url to resource self.setLogConfigURL(self.loggingURL) # apply logging level self.setLogLevel(self._logid, self.loglevel) # # set the logging context for the resouce. Use the contents of # of the url as the logging configuration data. If the # the file contains any predefined macros then then # apply the resource context object to the macro defintions. # After the configuration is established then set the # the appropriate level. The contents of the level correspond # to the command line options when a program starts. # # def setLoggingContext(self, logcfg_url, oldstyle_loglevel, rscCtx): # test we have a logging URI if logcfg_url == None or logcfg_url == "": ossie.logger.ConfigureDefault() else: # apply resource context to macro definitions if rscCtx: rscCtx.apply(self.loggingMacros) self.loggingCtx = rscCtx # load logging configuration url to resource self.setLogConfigURL(logcfg_url) # apply logging level if explicitly stated if oldstyle_loglevel != None and oldstyle_loglevel > -1: self.setLogLevel(self._logid, ossie.logger.ConvertLogLevel(oldstyle_loglevel)) else: _logLevel = ossie.logger.ConvertLog4ToCFLevel( logging.getLogger(None).getEffectiveLevel()) def saveLoggingContext(self, logcfg_url, oldstyle_loglevel, rscCtx): # apply resource context to macro definitions if rscCtx: rscCtx.apply(self.loggingMacros) self.loggingCtx = rscCtx # test we have a logging URLx self.loggingURL = logcfg_url if logcfg_url == None or logcfg_url == "": self.logConfig = ossie.logger.GetDefaultConfig() else: # try to process URL and grab contents try: cfg_data = ossie.logger.GetConfigFileContents(logcfg_url) if cfg_data and len(cfg_data) > 0: self.logConfig = ossie.logger.ExpandMacros( cfg_data, self.loggingMacros) except: pass # apply logging level if explicitly stated if oldstyle_loglevel != None and oldstyle_loglevel > -1: _logLevel = ossie.logger.ConvertLogLevel(oldstyle_loglevel) else: _logLevel = ossie.logger.ConvertLog4ToCFLevel( logging.getLogger(None).getEffectiveLevel()) def setLogListenerCallback(self, loglistenerCB): self.logListenerCallback = logListenerCB def addPropertyChangeListener(self, id, callback): self._props.addChangeListener(callback, id) ######################################### # CF::LogConfiguration def _get_log_level(self): return self.logLevel def _set_log_level(self, newLogLevel): self.log_level(newLogLevel) def log_level(self, newLogLevel=None): if newLogLevel == None: return self.logLevel if self.logListenerCallback and callable( self.logListenerCallback.logLevelChanged): self.logLevel = newLogLevel self.logListenerCallback.logLevelChanged(self._logid, newLogLevel) else: ossie.logger.SetLogLevel(self._logid, newLogLevel) self.logLevel = newLogLevel def setLogLevel(self, logid, newLogLevel): if self.logListenerCallback and callable( self.logListenerCallback.logLevelChanged): self.logLevel = newLogLevel self.logListenerCallback.logLevelChanged(logid, newLogLevel) else: ossie.logger.SetLogLevel(logid, newLogLevel) def getLogConfig(self): return self.logConfig def setLogConfig(self, new_log_config): if self.logListenerCallback and callable( self.logListenerCallback.logConfigChanged): self.logConfig = new_log_config self.logListenerCallback.logConfigChanged(new_log_config) elif new_log_config: tcfg = ossie.logger.ConfigureWithContext(new_log_config, self.loggingMacros) if tcfg: self.logConfig = tcfg else: pass def setLogConfigURL(self, log_config_url): if log_config_url: fc = ossie.logger.GetConfigFileContents(log_config_url) self.loggingURL = log_config_url if fc and len(fc) > 0: self.setLogConfig(fc) ######################################### # CF::LogEventConsumer def retrieve_records(self, howMany, startingRecord): howMany = 0 return None def retrieve_records_by_date(self, howMany, to_timetStamp): howMany = 0 return None def retrieve_records_from_date(self, howMany, from_timetStamp): howMany = 0 return None ######################################### # CF::TestableObject def runTest(self, testid, properties): """Override this function to provide the desired behavior.""" self._log.trace("runTest()") raise CF.Device.UnknownTest("unknown test: %s" % str(testid)) ######################################### # CF::PropertySet def query(self, configProperties): self.propertySetAccess.acquire() # If the list is empty, get all props if configProperties == []: self._log.trace("query all properties") try: rv = [] for propid in self._props.keys(): if self._props.has_id(propid) and self._props.isQueryable( propid): try: value = self._props.query(propid) except Exception, e: self._log.error('Failed to query %s: %s', propid, e) value = any.to_any(None) rv.append(CF.DataType(propid, value)) except: self.propertySetAccess.release() raise # otherwise get only the requested ones else: self._log.trace("query %s properties", len(configProperties)) try: unknownProperties = [] for prop in configProperties: if self._props.has_id(prop.id) and self._props.isQueryable( prop.id): try: prop.value = self._props.query(prop.id) except Exception, e: self._log.error('Failed to query %s: %s', prop.id, e) else: self._log.warning( "property %s cannot be queried. valid Id: %s", prop.id, self._props.has_id(prop.id)) unknownProperties.append(prop) except: self.propertySetAccess.release() raise if len(unknownProperties) > 0: self._log.warning("query called with invalid properties %s", unknownProperties) self.propertySetAccess.release() raise CF.UnknownProperties(unknownProperties) rv = configProperties self.propertySetAccess.release() self._log.trace("query -> %s properties", len(rv)) return rv def configure(self, configProperties): self._log.trace("configure(%s)", configProperties) self.propertySetAccess.acquire() notSet = [] for prop in configProperties: try: if self._props.has_id(prop.id) and self._props.isConfigurable( prop.id): try: self._props.configure(prop.id, prop.value) except ValueError, e: self._log.warning( "Invalid value provided to configure for property %s %s", prop.id, e) notSet.append(prop) else: self._log.warning( "Tried to configure non-existent, readonly, or property with action not equal to external %s", prop.id) notSet.append(prop) except Exception, e: self._log.exception("Unexpected exception.") notSet.append(prop)