2007-01-24 22:24:01 +08:00
|
|
|
""" Reporter classes for showing asynchronous and synchronous status events
|
|
|
|
"""
|
|
|
|
|
|
|
|
import py
|
|
|
|
import time
|
|
|
|
|
|
|
|
def basic_report(msg_type, message):
|
|
|
|
print msg_type, message
|
|
|
|
|
|
|
|
#def report(msg_type, message):
|
|
|
|
# pass
|
|
|
|
|
|
|
|
##def report_error(excinfo):
|
2007-02-14 03:21:53 +08:00
|
|
|
## if isinstance(excinfo, py.test.collect.Item.Skipped):
|
2007-01-24 22:24:01 +08:00
|
|
|
## # we need to dispatch this info
|
|
|
|
## report(Skipped(excinfo))
|
|
|
|
## else:
|
|
|
|
## report("itererror", excinfo)
|
|
|
|
|
|
|
|
def wrapcall(reporter, func, *args, **kwargs):
|
|
|
|
reporter(CallStart(func, args, kwargs))
|
|
|
|
try:
|
|
|
|
retval = func(*args, **kwargs)
|
|
|
|
except:
|
|
|
|
reporter(CallException(func, args, kwargs))
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
reporter(CallFinish(func, args, kwargs))
|
|
|
|
return retval
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# Reporting Events
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ReportEvent(object):
|
|
|
|
def __repr__(self):
|
|
|
|
l = ["%s=%s" %(key, value)
|
|
|
|
for key, value in self.__dict__.items()]
|
|
|
|
return "<%s %s>" %(self.__class__.__name__, " ".join(l),)
|
|
|
|
|
2007-08-27 17:02:50 +08:00
|
|
|
def is_failure(self):
|
|
|
|
return False
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
class SendItem(ReportEvent):
|
|
|
|
def __init__(self, channel, item):
|
|
|
|
self.item = item
|
|
|
|
self.channel = channel
|
|
|
|
if channel:
|
|
|
|
self.host = channel.gateway.host
|
|
|
|
|
|
|
|
class ReceivedItemOutcome(ReportEvent):
|
|
|
|
def __init__(self, channel, item, outcome):
|
|
|
|
self.channel = channel
|
|
|
|
if channel:
|
|
|
|
self.host = channel.gateway.host
|
|
|
|
self.item = item
|
|
|
|
self.outcome = outcome
|
|
|
|
|
2007-08-27 17:02:50 +08:00
|
|
|
def is_failure(self):
|
|
|
|
return not (self.outcome.passed or self.outcome.skipped)
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
class CallEvent(ReportEvent):
|
|
|
|
def __init__(self, func, args, kwargs):
|
|
|
|
self.func = func
|
|
|
|
self.args = args
|
|
|
|
self.kwargs = kwargs
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
call = "%s args=%s, kwargs=%s" %(self.func.__name__,
|
|
|
|
self.args, self.kwargs)
|
|
|
|
return '<%s %s>' %(self.__class__.__name__, call)
|
|
|
|
|
|
|
|
class CallStart(CallEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class CallException(CallEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class CallFinish(CallEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class HostRSyncing(ReportEvent):
|
2007-02-09 03:02:28 +08:00
|
|
|
def __init__(self, host, root, remotepath, synced):
|
2007-01-24 22:24:01 +08:00
|
|
|
self.host = host
|
2007-02-07 05:41:11 +08:00
|
|
|
self.root = root
|
|
|
|
self.remotepath = remotepath
|
2007-02-09 03:02:28 +08:00
|
|
|
self.synced = synced
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-07 02:57:14 +08:00
|
|
|
class HostGatewayReady(ReportEvent):
|
2007-02-06 18:31:08 +08:00
|
|
|
def __init__(self, host, roots):
|
|
|
|
self.host = host
|
|
|
|
self.roots = roots
|
|
|
|
|
|
|
|
class HostRSyncRootReady(ReportEvent):
|
|
|
|
def __init__(self, host, root):
|
2007-01-24 22:24:01 +08:00
|
|
|
self.host = host
|
2007-02-06 18:31:08 +08:00
|
|
|
self.root = root
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
class TestStarted(ReportEvent):
|
2008-01-25 23:54:04 +08:00
|
|
|
def __init__(self, hosts, config, roots):
|
2007-01-24 22:24:01 +08:00
|
|
|
self.hosts = hosts
|
2007-02-07 02:44:16 +08:00
|
|
|
self.roots = roots
|
2007-01-24 22:24:01 +08:00
|
|
|
self.timestart = time.time()
|
2008-01-25 23:54:04 +08:00
|
|
|
self.config = config
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
class TestFinished(ReportEvent):
|
|
|
|
def __init__(self):
|
|
|
|
self.timeend = time.time()
|
|
|
|
|
|
|
|
class Nodes(ReportEvent):
|
|
|
|
def __init__(self, nodes):
|
|
|
|
self.nodes = nodes
|
|
|
|
|
|
|
|
class SkippedTryiter(ReportEvent):
|
|
|
|
def __init__(self, excinfo, item):
|
|
|
|
self.excinfo = excinfo
|
|
|
|
self.item = item
|
|
|
|
|
|
|
|
class FailedTryiter(ReportEvent):
|
|
|
|
def __init__(self, excinfo, item):
|
|
|
|
self.excinfo = excinfo
|
|
|
|
self.item = item
|
|
|
|
|
2007-08-27 17:02:50 +08:00
|
|
|
def is_failure(self):
|
|
|
|
return True
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
class ItemStart(ReportEvent):
|
|
|
|
""" This class shows most of the start stuff, like directory, module, class
|
|
|
|
can be used for containers
|
|
|
|
"""
|
|
|
|
def __init__(self, item):
|
|
|
|
self.item = item
|
|
|
|
|
2008-01-25 23:54:04 +08:00
|
|
|
class ItemFinish(ReportEvent):
|
|
|
|
""" This class shows most of the start stuff, like directory, module, class
|
|
|
|
can be used for containers
|
|
|
|
"""
|
|
|
|
def __init__(self, item):
|
|
|
|
self.item = item
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
class RsyncFinished(ReportEvent):
|
|
|
|
def __init__(self):
|
|
|
|
self.time = time.time()
|
|
|
|
|
|
|
|
class ImmediateFailure(ReportEvent):
|
|
|
|
def __init__(self, item, outcome):
|
|
|
|
self.item = item
|
|
|
|
self.outcome = outcome
|
|
|
|
|
|
|
|
class PongReceived(ReportEvent):
|
|
|
|
def __init__(self, hostid, result):
|
|
|
|
self.hostid = hostid
|
|
|
|
self.result = result
|
2007-01-25 00:46:46 +08:00
|
|
|
|
|
|
|
class InterruptedExecution(ReportEvent):
|
2007-02-12 21:14:36 +08:00
|
|
|
def __init__(self):
|
|
|
|
self.timeend = time.time()
|
2007-01-25 00:46:46 +08:00
|
|
|
|
|
|
|
class CrashedExecution(ReportEvent):
|
2007-02-12 21:14:36 +08:00
|
|
|
def __init__(self):
|
|
|
|
self.timeend = time.time()
|