2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
""" Remote session base class
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import py
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
2007-08-27 17:02:50 +08:00
|
|
|
from py.__.test import repevent
|
2007-02-05 07:12:12 +08:00
|
|
|
from py.__.test.rsession.master import MasterNode, dispatch_loop, itemgen
|
2007-02-04 22:05:01 +08:00
|
|
|
from py.__.test.rsession.hostmanage import HostInfo, HostManager
|
2007-01-24 22:24:01 +08:00
|
|
|
from py.__.test.rsession.local import local_loop, plain_runner, apigen_runner,\
|
2007-01-25 00:46:46 +08:00
|
|
|
box_runner
|
2007-08-27 17:02:50 +08:00
|
|
|
from py.__.test.reporter import LocalReporter, RemoteReporter, TestReporter
|
|
|
|
from py.__.test.session import AbstractSession
|
2007-02-03 20:14:46 +08:00
|
|
|
from py.__.test.outcome import Skipped, Failed
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
class RSession(AbstractSession):
|
|
|
|
""" Remote version of session
|
|
|
|
"""
|
2007-01-25 05:05:33 +08:00
|
|
|
def fixoptions(self):
|
2007-01-28 21:25:03 +08:00
|
|
|
super(RSession, self).fixoptions()
|
2007-02-08 02:54:51 +08:00
|
|
|
option = self.config.option
|
|
|
|
if option.nocapture:
|
|
|
|
print "Cannot use nocapture with distributed testing"
|
|
|
|
sys.exit(1)
|
2007-01-25 05:05:33 +08:00
|
|
|
config = self.config
|
|
|
|
try:
|
2007-01-29 05:54:12 +08:00
|
|
|
config.getvalue('dist_hosts')
|
2007-01-25 05:05:33 +08:00
|
|
|
except KeyError:
|
2007-01-29 05:54:12 +08:00
|
|
|
print "For running ad-hoc distributed tests you need to specify"
|
|
|
|
print "dist_hosts in a local conftest.py file, for example:"
|
2007-01-25 05:05:33 +08:00
|
|
|
print "for example:"
|
2007-01-29 05:54:12 +08:00
|
|
|
print
|
|
|
|
print " dist_hosts = ['localhost'] * 4 # for 3 processors"
|
|
|
|
print " dist_hosts = ['you@remote.com', '...'] # for testing on ssh accounts"
|
|
|
|
print " # with your remote ssh accounts"
|
|
|
|
print
|
|
|
|
print "see also: http://codespeak.net/py/current/doc/test.html#automated-distributed-testing"
|
2007-01-25 05:05:33 +08:00
|
|
|
raise SystemExit
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
def main(self, reporter=None):
|
|
|
|
""" main loop for running tests. """
|
2007-08-27 17:02:50 +08:00
|
|
|
config = self.config
|
|
|
|
hm = HostManager(config)
|
|
|
|
reporter, checkfun = self.init_reporter(reporter, config, hm.hosts)
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-07 02:44:16 +08:00
|
|
|
reporter(repevent.TestStarted(hm.hosts, self.config.topdir,
|
|
|
|
hm.roots))
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
try:
|
2007-02-05 08:23:14 +08:00
|
|
|
nodes = hm.setup_hosts(reporter)
|
2007-02-05 07:34:23 +08:00
|
|
|
reporter(repevent.RsyncFinished())
|
2007-01-25 00:46:46 +08:00
|
|
|
try:
|
2007-02-05 07:12:12 +08:00
|
|
|
self.dispatch_tests(nodes, reporter, checkfun)
|
2007-01-25 00:46:46 +08:00
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
print >>sys.stderr, "C-c pressed waiting for gateways to teardown..."
|
|
|
|
channels = [node.channel for node in nodes]
|
2007-02-05 08:23:14 +08:00
|
|
|
hm.kill_channels(channels)
|
|
|
|
hm.teardown_gateways(reporter, channels)
|
2007-01-25 00:46:46 +08:00
|
|
|
print >>sys.stderr, "... Done"
|
|
|
|
raise
|
|
|
|
|
|
|
|
channels = [node.channel for node in nodes]
|
2007-02-05 08:23:14 +08:00
|
|
|
hm.teardown_hosts(reporter, channels, nodes,
|
|
|
|
exitfirst=self.config.option.exitfirst)
|
2007-02-05 07:34:23 +08:00
|
|
|
reporter(repevent.Nodes(nodes))
|
|
|
|
retval = reporter(repevent.TestFinished())
|
2007-01-25 00:46:46 +08:00
|
|
|
return retval
|
|
|
|
except (KeyboardInterrupt, SystemExit):
|
2007-02-05 07:34:23 +08:00
|
|
|
reporter(repevent.InterruptedExecution())
|
2007-01-25 00:46:46 +08:00
|
|
|
raise
|
|
|
|
except:
|
2007-02-05 07:34:23 +08:00
|
|
|
reporter(repevent.CrashedExecution())
|
2007-01-25 00:46:46 +08:00
|
|
|
raise
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-05 07:12:12 +08:00
|
|
|
def dispatch_tests(self, nodes, reporter, checkfun):
|
2007-01-26 19:49:59 +08:00
|
|
|
colitems = self.config.getcolitems()
|
2007-01-24 22:24:01 +08:00
|
|
|
keyword = self.config.option.keyword
|
2007-08-27 17:02:50 +08:00
|
|
|
itemgenerator = itemgen(colitems, reporter, keyword)
|
2007-01-24 22:24:01 +08:00
|
|
|
all_tests = dispatch_loop(nodes, itemgenerator, checkfun)
|
|
|
|
|
|
|
|
class LSession(AbstractSession):
|
|
|
|
""" Local version of session
|
|
|
|
"""
|
|
|
|
def main(self, reporter=None, runner=None):
|
|
|
|
# check out if used options makes any sense
|
2007-08-27 17:02:50 +08:00
|
|
|
config = self.config
|
|
|
|
hm = HostManager(config, hosts=[HostInfo('localhost')])
|
2007-02-05 08:14:11 +08:00
|
|
|
hosts = hm.hosts
|
2007-01-24 22:24:01 +08:00
|
|
|
if not self.config.option.nomagic:
|
|
|
|
py.magic.invoke(assertion=1)
|
|
|
|
|
2007-08-27 17:02:50 +08:00
|
|
|
reporter, checkfun = self.init_reporter(reporter, config, hosts)
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-07 02:44:16 +08:00
|
|
|
reporter(repevent.TestStarted(hosts, self.config.topdir, []))
|
2007-01-26 19:49:59 +08:00
|
|
|
colitems = self.config.getcolitems()
|
2007-02-05 07:34:23 +08:00
|
|
|
reporter(repevent.RsyncFinished())
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
if runner is None:
|
2007-01-27 21:01:58 +08:00
|
|
|
runner = self.init_runner()
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
keyword = self.config.option.keyword
|
|
|
|
|
2007-08-27 17:02:50 +08:00
|
|
|
itemgenerator = itemgen(colitems, reporter, keyword)
|
2007-01-24 22:24:01 +08:00
|
|
|
local_loop(self, reporter, itemgenerator, checkfun, self.config, runner=runner)
|
|
|
|
|
2007-02-05 07:34:23 +08:00
|
|
|
retval = reporter(repevent.TestFinished())
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
if not self.config.option.nomagic:
|
|
|
|
py.magic.revoke(assertion=1)
|
|
|
|
|
2007-01-27 21:01:58 +08:00
|
|
|
self.write_docs()
|
2007-01-24 22:24:01 +08:00
|
|
|
return retval
|
|
|
|
|
2007-01-27 21:01:58 +08:00
|
|
|
def write_docs(self):
|
2007-01-24 22:24:01 +08:00
|
|
|
if self.config.option.apigen:
|
|
|
|
from py.__.apigen.tracer.docstorage import DocStorageAccessor
|
|
|
|
apigen = py.path.local(self.config.option.apigen).pyimport()
|
2007-01-25 23:23:18 +08:00
|
|
|
if not hasattr(apigen, 'build'):
|
2007-01-29 04:25:11 +08:00
|
|
|
raise NotImplementedError("%s does not contain 'build' "
|
|
|
|
"function" %(apigen,))
|
2007-01-24 22:24:01 +08:00
|
|
|
print >>sys.stderr, 'building documentation'
|
2007-02-01 23:20:39 +08:00
|
|
|
capture = py.io.StdCaptureFD()
|
2007-01-24 22:24:01 +08:00
|
|
|
try:
|
2007-02-04 22:05:01 +08:00
|
|
|
pkgdir = py.path.local(self.config.args[0]).pypkgpath()
|
2007-01-29 20:53:52 +08:00
|
|
|
apigen.build(pkgdir,
|
2007-02-01 21:56:31 +08:00
|
|
|
DocStorageAccessor(self.docstorage),
|
|
|
|
capture)
|
2007-01-24 22:24:01 +08:00
|
|
|
finally:
|
|
|
|
capture.reset()
|
2007-02-07 23:33:46 +08:00
|
|
|
print >>sys.stderr, '\ndone'
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-27 21:01:58 +08:00
|
|
|
def init_runner(self):
|
2007-01-24 22:24:01 +08:00
|
|
|
if self.config.option.apigen:
|
|
|
|
from py.__.apigen.tracer.tracer import Tracer, DocStorage
|
2007-02-04 22:05:01 +08:00
|
|
|
pkgdir = py.path.local(self.config.args[0]).pypkgpath()
|
2007-01-30 18:34:08 +08:00
|
|
|
apigen = py.path.local(self.config.option.apigen).pyimport()
|
|
|
|
if not hasattr(apigen, 'get_documentable_items'):
|
2007-01-24 22:24:01 +08:00
|
|
|
raise NotImplementedError("Provided script does not seem "
|
|
|
|
"to contain get_documentable_items")
|
2007-01-30 18:34:08 +08:00
|
|
|
pkgname, items = apigen.get_documentable_items(pkgdir)
|
|
|
|
self.docstorage = DocStorage().from_dict(items,
|
|
|
|
module_name=pkgname)
|
2007-01-24 22:24:01 +08:00
|
|
|
self.tracer = Tracer(self.docstorage)
|
|
|
|
return apigen_runner
|
2007-02-08 02:43:23 +08:00
|
|
|
elif self.config.option.boxed:
|
|
|
|
return box_runner
|
2007-01-24 22:24:01 +08:00
|
|
|
else:
|
2007-01-25 00:46:46 +08:00
|
|
|
return plain_runner
|
|
|
|
|