util Package

advLogging Module

class eWRT.util.advLogging.SNMPHandler(moduleName)[source]

Bases: logging.Handler

Logging handler for sending SNMP traps

emit(record)[source]

sends the message

class eWRT.util.advLogging.TestHandler(methodName='runTest')[source]

Bases: unittest.case.TestCase

testHandler()[source]

tests the handler

eWRT.util.advLogging.sendSNMPTrap(message, module, level)[source]

sends a SNMP message @param message: String that should be sent @param level: SNMP levels (‘ok’, ‘warning’, ‘critical’, ‘unknown’)

assert Module

@package eWRT.util.assert Assertion based counters

Examples: see unittests

class eWRT.util.assert.AssertReturnValue(evalExpression, counterNameTrue, counterNameFalse)[source]

Bases: object

decorator class used to time functions

class eWRT.util.assert.TestAssertReturnValue[source]

Bases: object

testAssertCounter()[source]

verifies the assertion counters

async Module

@package eWRT.util.async asynchronous procedure calls

@warning this library is still a draft and might change considerable

class eWRT.util.async.Async(cache_dir, cache_nesting_level=0, cache_file_suffix='', max_processes=8, debug_dir=None)[source]

Bases: eWRT.util.cache.DiskCache

Asynchronous Call Handling

fetch(cache_file)[source]
getPostHashfile(cmd)[source]

returns an identifier representing the object which is compatible to the identifiers returned by the eWRT.util.cache.* classes.

has_processes_limit_reached()[source]

closes finished processes and verifies whether we have already reached the maximum number of processes

post(cmd)[source]

checks whether the given command is already cached and calls the command otherwise. @param[in] cmdline command to call @returns the hash required to fetch this object

class eWRT.util.async.TestAsync[source]

Bases: object

unittests covering the class async

TEST_CACHE_DIR = './.test-async'
setUp()[source]
tearDown()[source]
testDebugMode()[source]

tests the debug mode

testMaxProcessLimit()[source]

tests the max process limit

cache Module

@package eWRT.util.cache caches arbitrary objects

class eWRT.util.cache.Cache(fn=None)[source]

Bases: object

An abstract class for caching functions

fetch(fetch_function, *args, **kargs)[source]

Fetches a object from the cache or computes it by calling the fetch_function. The objectId is computed based on the function arguments

fetchObjectId(key, fetch_function, *args, **kargs)[source]

Fetches a object from the cache or computes it by calling the fetch_function. The key helps to determine whether the object is already in the cache or not.

static getKey(*args, **kargs)[source]

returns the key for a set of function parameters

static getObjectId(obj)[source]

returns an identifier representing the object

class eWRT.util.cache.DiskCache(cache_dir, cache_nesting_level=0, cache_file_suffix='', fn=None)[source]

Bases: eWRT.util.cache.Cache

@class DiskCache Caches abitrary functions based on the function’s arguments (fetch) or on a user defined key (fetchObjectId)

@remarks This version of DiskCached is threadsafe

fetch(fetch_function, *args, **kargs)[source]
fetches the object with the given id, querying
  1. the cache and
  2. the fetch_function

if the fetch_function is called, the functions result is saved in the cache

::param fetch_function: function to call if the result is not in the cache ::param args: arguments ::param kargs: optional keyword arguments

::returns: the object (retrieved from the cache or computed)

fetchObjectId(key, fetch_function, *args, **kargs)[source]
fetches the object with the given id, querying
  • the cache and
  • the fetch_function

if the fetch_function is called, the functions result is saved in the cache

::param key: key to fetch ::param fetch_function: function to call if the result is not in the cache ::param args: arguments ::param kargs: optional keyword arguments

::returns: the object (retrieved from the cache or computed)

getCacheStatistics()[source]

returns statistics regarding the cache’s hit/miss ratio

class eWRT.util.cache.DiskCached(cache_dir, cache_nesting_level=0, cache_file_suffix='')[source]

Bases: object

Decorator based on Cache for caching arbitrary function calls usage:

@DiskCached(”./cache/myfunction”) def myfunction(*args):

@remarks This version of DiskCached is threadsafe

cache
class eWRT.util.cache.IterableCache(cache_dir, cache_nesting_level=0, cache_file_suffix='', fn=None)[source]

Bases: eWRT.util.cache.DiskCache

caches arbitrary iterable content identified by an identifier

fetchObjectId(key, function, *args, **kargs)[source]
fetches the object with the given id, querying
  1. the cache and
  2. the function

if the function is called, the functions result is saved in the cache

::param key: key to fetch ::param function: function to call if the result is not in the cache ::param args: arguments ::param kargs: optional keyword arguments

::returns: the object (retrieved from the cache or computed)

next()[source]
class eWRT.util.cache.MemoryCache(max_cache_size=0, fn=None)[source]

Bases: eWRT.util.cache.Cache

@class MemoryCached

Caches abitrary functions based on the function’s arguments (fetch) or on a user defined key (fetchObjectId)

fetch(fetch_function, *args, **kargs)[source]
fetchObjectId(key, fetch_function, *args, **kargs)[source]
garbage_collect_cache()[source]

removes the object which have not been in use for the longest time

max_cache_size
class eWRT.util.cache.MemoryCached(arg)[source]

Bases: eWRT.util.cache.MemoryCache

Decorator based on MemoryCache for caching arbitrary function calls usage:

@MemoryCached or @MemoryCached(max_cache_size) def myfunction(*args): ...
class eWRT.util.cache.RedisCache(max_cache_size=0, fn=None, host='localhost', port=6379, db=0)[source]

Bases: eWRT.util.cache.Cache

fetch(fetch_function, *args, **kargs)[source]
fetchObjectId(key, fetch_function, *args, **kargs)[source]
garbage_collect_cache()[source]

removes the object which have not been in use for the longest time

class eWRT.util.cache.RedisCached(arg)[source]

Bases: eWRT.util.cache.RedisCache

Decorator based on MemoryCache for caching arbitrary function calls usage:

@MemoryCached or @MemoryCached(max_cache_size) def myfunction(*args): ...
eWRT.util.cache.get_unique_temp_file(fname)

exception Module

@package eWRT.util.exception

exception eWRT.util.exception.SNMPException(module_name, msg, level='warning')[source]

Bases: exceptions.Exception

reports an exception to snmp

class eWRT.util.exception.TestSNMPException[source]

Bases: object

testQuoting()[source]
testSNMPException()[source]

tests an SNMP exception

execute Module

@package eWRT.util.execute Helpers for executing third party modules

class eWRT.util.execute.TestExecute[source]

Bases: object

test_pipe_content()[source]
eWRT.util.execute.pipe_content(cmd, stdin=None)[source]

Pipes the content through the given command. @param[in] cmd: command to be executed @param[in] stdin: standard input @return: (exit_status, stdout)

monitoring Module

The class NSCA-Service helps the enables to send test-results over the NSCA service to Nagios. This is a more reliable way of sending messages directly from programs than with SNMP. On the one hand because they are not only associated to single service, but also as the configuration is easier

== Configuration ==

  • Install the package nsca
aptitude install nsca
  • On the monitoring system:

** edit the file ‘’/etc/nsca.cfg’‘: ** set a password and an appropriate encryption method

  • On the host:

** edit the file ‘’/etc/send_nsca.cfg’’ ** enter the above password and encryption method

class eWRT.util.monitoring.NSCA[source]

Bases: object

class NSCA Service helps sending test results to Nagios

static send(message, status, service_name, src_host=None, performance=[], monitoringServer="'tor.wu.ac.at'")[source]

sends the

class eWRT.util.monitoring.Performance(label, value, unit='', warn='', critical='', min='', max='')[source]

Bases: object

pickleIterator Module

pickelIterator

class eWRT.util.pickleIterator.AbstractIterator(fname, file_mode=None)[source]

Bases: object

Abstract Iterator class used to implement ReadPickleIterator and WritePickleIterator

close()[source]
classmethod get_filename(fname)[source]
next()[source]

Python 2 compatibility

class eWRT.util.pickleIterator.ReadPickleIterator(fname)[source]

Bases: eWRT.util.pickleIterator.AbstractIterator

provides an iterator over pickeled elements

class eWRT.util.pickleIterator.WritePickleIterator(fname)[source]

Bases: eWRT.util.pickleIterator.AbstractIterator

writes pickeled elements (available as iterator) to a file

dump(obj)[source]

dumps the following object to the pickle file

profile Module

@package eWRT.util.profile google like profiling :)

@warning this library is still a draft and might change considerable

eWRT.util.profile.profile(fn, logfile='profile.awi')[source]

profile function

eWRT.util.profile.profileFunction()[source]

function to profile

eWRT.util.profile.testProfile()[source]

test the profiling

timing Module

@package eWRT.util.timing timing of abitrary method calls

Examples: see unittests

class eWRT.util.timing.Timed(f)[source]

Bases: object

decorator class used to time functions

clear()[source]
class eWRT.util.timing.TimedTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

testCallStatistics()[source]
testClearCallStatistics()[source]
testReturnValue()[source]