"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "buildbot/test/fake/remotecommand.py" between
buildbot-3.0.2.tar.gz and buildbot-3.1.0.tar.gz

About: Buildbot is a continuous integration testing framework (Python-based). It supports also automation of complex build systems, application deployment, and management of sophisticated software-release processes.

remotecommand.py  (buildbot-3.0.2):remotecommand.py  (buildbot-3.1.0)
skipping to change at line 24 skipping to change at line 24
# Copyright Buildbot Team Members # Copyright Buildbot Team Members
import functools import functools
from twisted.internet import defer from twisted.internet import defer
from twisted.python import failure from twisted.python import failure
from buildbot.process.results import CANCELLED from buildbot.process.results import CANCELLED
from buildbot.process.results import FAILURE from buildbot.process.results import FAILURE
from buildbot.process.results import SUCCESS from buildbot.process.results import SUCCESS
from buildbot.test.fake import logfile
class FakeRemoteCommand: class FakeRemoteCommand:
# callers should set this to the running TestCase instance # callers should set this to the running TestCase instance
testcase = None testcase = None
active = False active = False
interrupted = False interrupted = False
skipping to change at line 77 skipping to change at line 76
# delegate back to the test case # delegate back to the test case
cmd = yield self.testcase._remotecommand_run(self, step, conn, builder_n ame) cmd = yield self.testcase._remotecommand_run(self, step, conn, builder_n ame)
for name, log_ in self.logs.items(): for name, log_ in self.logs.items():
if self._log_close_when_finished[name]: if self._log_close_when_finished[name]:
log_.finish() log_.finish()
return cmd return cmd
def useLog(self, log_, closeWhenFinished=False, logfileName=None): def useLog(self, log_, closeWhenFinished=False, logfileName=None):
if not logfileName: if not logfileName:
logfileName = log_.getName() logfileName = log_.getName()
assert logfileName not in self.logs
assert logfileName not in self.delayedLogs
self.logs[logfileName] = log_ self.logs[logfileName] = log_
self._log_close_when_finished[logfileName] = closeWhenFinished self._log_close_when_finished[logfileName] = closeWhenFinished
def useLogDelayed(self, logfileName, activateCallBack, closeWhenFinished=Fal se): def useLogDelayed(self, logfileName, activateCallBack, closeWhenFinished=Fal se):
assert logfileName not in self.logs
assert logfileName not in self.delayedLogs
self.delayedLogs[logfileName] = (activateCallBack, closeWhenFinished) self.delayedLogs[logfileName] = (activateCallBack, closeWhenFinished)
def addStdout(self, data):
if self.collectStdout:
self.stdout += data
if self.stdioLogName is not None and self.stdioLogName in self.logs:
self.logs[self.stdioLogName].addStdout(data)
def addStderr(self, data):
if self.collectStderr:
self.stderr += data
if self.stdioLogName is not None and self.stdioLogName in self.logs:
self.logs[self.stdioLogName].addStderr(data)
def addHeader(self, data):
if self.stdioLogName is not None and self.stdioLogName in self.logs:
self.logs[self.stdioLogName].addHeader(data)
@defer.inlineCallbacks
def addToLog(self, logname, data):
# Activate delayed logs on first data.
if logname in self.delayedLogs:
(activate_callback, close_when_finished) = self.delayedLogs[logname]
del self.delayedLogs[logname]
loog = yield activate_callback(self)
self.logs[logname] = loog
self._log_close_when_finished[logname] = close_when_finished
if logname in self.logs:
self.logs[logname].addStdout(data)
else:
raise Exception("{}.addToLog: no such log {}".format(self, logname))
def interrupt(self, why): def interrupt(self, why):
if not self._waiting_for_interrupt: if not self._waiting_for_interrupt:
raise RuntimeError("Got interrupt, but FakeRemoteCommand was not exp ecting it") raise RuntimeError("Got interrupt, but FakeRemoteCommand was not exp ecting it")
self._waiting_for_interrupt = False self._waiting_for_interrupt = False
self.interrupted = True self.interrupted = True
def results(self): def results(self):
if self.interrupted: if self.interrupted:
return CANCELLED return CANCELLED
if self.rc in self.decodeRC: if self.rc in self.decodeRC:
return self.decodeRC[self.rc] return self.decodeRC[self.rc]
return FAILURE return FAILURE
def didFail(self): def didFail(self):
return self.results() == FAILURE return self.results() == FAILURE
def fakeLogData(self, step, log, header='', stdout='', stderr=''):
# note that this should not be used in the same test as useLog(Delayed)
self.logs[log] = fakelog = logfile.FakeLogFile(log)
self._log_close_when_finished[log] = False
fakelog.fakeData(header=header, stdout=stdout, stderr=stderr)
def set_run_interrupt(self): def set_run_interrupt(self):
self._waiting_for_interrupt = True self._waiting_for_interrupt = True
def __repr__(self): def __repr__(self):
return "FakeRemoteCommand(" + repr(self.remote_command) + "," + repr(sel f.args) + ")" return "FakeRemoteCommand(" + repr(self.remote_command) + "," + repr(sel f.args) + ")"
class FakeRemoteShellCommand(FakeRemoteCommand): class FakeRemoteShellCommand(FakeRemoteCommand):
def __init__(self, workdir, command, env=None, def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1, want_stdout=1, want_stderr=1,
skipping to change at line 129 skipping to change at line 157
stdioLogName='stdio'): stdioLogName='stdio'):
if logfiles is None: if logfiles is None:
logfiles = {} logfiles = {}
if decodeRC is None: if decodeRC is None:
decodeRC = {0: SUCCESS} decodeRC = {0: SUCCESS}
args = dict(workdir=workdir, command=command, env=env or {}, args = dict(workdir=workdir, command=command, env=env or {},
want_stdout=want_stdout, want_stderr=want_stderr, want_stdout=want_stdout, want_stderr=want_stderr,
initial_stdin=initialStdin, initial_stdin=initialStdin,
timeout=timeout, maxTime=maxTime, logfiles=logfiles, timeout=timeout, maxTime=maxTime, logfiles=logfiles,
usePTY=usePTY, logEnviron=logEnviron) usePTY=usePTY, logEnviron=logEnviron)
if interruptSignal is not None and interruptSignal != 'KILL':
args['interruptSignal'] = interruptSignal
super().__init__("shell", args, super().__init__("shell", args,
collectStdout=collectStdout, collectStdout=collectStdout,
collectStderr=collectStderr, collectStderr=collectStderr,
decodeRC=decodeRC, decodeRC=decodeRC,
stdioLogName=stdioLogName) stdioLogName=stdioLogName)
class ExpectRemoteRef: class ExpectRemoteRef:
""" """
Define an expected RemoteReference in the args to an L{Expect} class Define an expected RemoteReference in the args to an L{Expect} class
skipping to change at line 234 skipping to change at line 265
d.addCallback( d.addCallback(
functools.partial(lambda log, _: log.unwrap(), log)) functools.partial(lambda log, _: log.unwrap(), log))
d.addCallback(lambda l: l.flushFakeLogfile()) d.addCallback(lambda l: l.flushFakeLogfile())
return d return d
elif behavior == 'err': elif behavior == 'err':
return defer.fail(args[0]) return defer.fail(args[0])
elif behavior == 'update': elif behavior == 'update':
command.updates.setdefault(args[0], []).append(args[1]) command.updates.setdefault(args[0], []).append(args[1])
elif behavior == 'log': elif behavior == 'log':
name, streams = args name, streams = args
if 'header' in streams: for stream in streams:
command.logs[name].addHeader(streams['header']) if stream not in ['header', 'stdout', 'stderr']:
if 'stdout' in streams: raise Exception('Log stream {} is not recognized'.format(str
command.logs[name].addStdout(streams['stdout']) eam))
if command.collectStdout:
command.stdout += streams['stdout'] if name == command.stdioLogName:
if 'stderr' in streams: if 'header' in streams:
command.logs[name].addStderr(streams['stderr']) command.addHeader(streams['header'])
if command.collectStderr: if 'stdout' in streams:
command.stderr += streams['stderr'] command.addStdout(streams['stdout'])
if 'stderr' in streams:
command.addStderr(streams['stderr'])
else:
if 'header' in streams or 'stderr' in streams:
raise Exception('Non stdio streams only support stdout')
return command.addToLog(name, streams['stdout'])
elif behavior == 'callable': elif behavior == 'callable':
return defer.maybeDeferred(lambda: args[0](command)) return defer.maybeDeferred(lambda: args[0](command))
else: else:
return defer.fail(failure.Failure(AssertionError('invalid behavior { }'.format( return defer.fail(failure.Failure(AssertionError('invalid behavior { }'.format(
behavior)))) behavior))))
return defer.succeed(None) return defer.succeed(None)
@defer.inlineCallbacks @defer.inlineCallbacks
def runBehaviors(self, command): def runBehaviors(self, command):
""" """
skipping to change at line 323 skipping to change at line 359
class ExpectShell(Expect): class ExpectShell(Expect):
""" """
Define an expected L{RemoteShellCommand}, with the same arguments Any Define an expected L{RemoteShellCommand}, with the same arguments Any
non-default arguments must be specified explicitly (e.g., usePTY). non-default arguments must be specified explicitly (e.g., usePTY).
""" """
def __init__(self, workdir, command, env=None, def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1, initialStdin=None, want_stdout=1, want_stderr=1, initialStdin=None,
timeout=20 * 60, maxTime=None, logfiles=None, timeout=20 * 60, maxTime=None, logfiles=None,
usePTY=None, logEnviron=True): usePTY=None, logEnviron=True, interruptSignal=None):
if env is None: if env is None:
env = {} env = {}
if logfiles is None: if logfiles is None:
logfiles = {} logfiles = {}
args = dict(workdir=workdir, command=command, env=env, args = dict(workdir=workdir, command=command, env=env,
want_stdout=want_stdout, want_stderr=want_stderr, want_stdout=want_stdout, want_stderr=want_stderr,
initial_stdin=initialStdin, initial_stdin=initialStdin,
timeout=timeout, maxTime=maxTime, logfiles=logfiles, timeout=timeout, maxTime=maxTime, logfiles=logfiles,
usePTY=usePTY, logEnviron=logEnviron) usePTY=usePTY, logEnviron=logEnviron)
if interruptSignal is not None:
args['interruptSignal'] = interruptSignal
super().__init__("shell", args) super().__init__("shell", args)
def __repr__(self): def __repr__(self):
return "ExpectShell(" + repr(self.remote_command) + repr(self.args['comm and']) + ")" return "ExpectShell(" + repr(self.remote_command) + repr(self.args['comm and']) + ")"
 End of changes. 9 change blocks. 
18 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)