Skip to content

Commit

Permalink
RemoteCommand: add collectStderr
Browse files Browse the repository at this point in the history
Some master side steps also need to parse the stdout.
Clone the collectStdout feature for stderr

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Sep 21, 2012
1 parent 0ce60c9 commit bf7132b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 8 additions & 3 deletions master/buildbot/process/buildstep.py
Expand Up @@ -43,11 +43,12 @@ class RemoteCommand(pb.Referenceable):
debug = False

def __init__(self, remote_command, args, ignore_updates=False,
collectStdout=False, decodeRC={0:SUCCESS}):
collectStdout=False, collectStderr=False, decodeRC={0:SUCCESS}):
self.logs = {}
self.delayedLogs = {}
self._closeWhenFinished = {}
self.collectStdout = collectStdout
self.collectStderr = collectStderr
self.stdout = ''

self._startTime = None
Expand Down Expand Up @@ -206,6 +207,8 @@ def addStdout(self, data):
def addStderr(self, data):
if 'stdio' in self.logs:
self.logs['stdio'].addStderr(data)
if self.collectStderr:
self.stderr += data

def addHeader(self, data):
if 'stdio' in self.logs:
Expand Down Expand Up @@ -354,7 +357,8 @@ def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1,
timeout=20*60, maxTime=None, logfiles={},
usePTY="slave-config", logEnviron=True,
collectStdout=False, interruptSignal=None,
collectStdout=False,collectStderr=False,
interruptSignal=None,
initialStdin=None, decodeRC={0:SUCCESS}):

self.command = command # stash .command, set it later
Expand All @@ -377,7 +381,8 @@ def __init__(self, workdir, command, env=None,
if interruptSignal is not None:
args['interruptSignal'] = interruptSignal
RemoteCommand.__init__(self, "shell", args, collectStdout=collectStdout,
decodeRC=decodeRC)
collectStderr=collectStderr,
decodeRC=decodeRC)

def _start(self):
self.args['command'] = self.command
Expand Down
12 changes: 10 additions & 2 deletions master/buildbot/test/fake/remotecommand.py
Expand Up @@ -28,18 +28,21 @@ class FakeRemoteCommand(object):
active = False

def __init__(self, remote_command, args,
ignore_updates=False, collectStdout=False, decodeRC={0:SUCCESS}):
ignore_updates=False, collectStdout=False, collectStderr=False, decodeRC={0:SUCCESS}):
# copy the args and set a few defaults
self.remote_command = remote_command
self.args = args.copy()
self.logs = {}
self.delayedLogs = {}
self.rc = -999
self.collectStdout = collectStdout
self.collectStderr = collectStderr
self.updates = {}
self.decodeRC = decodeRC
if collectStdout:
self.stdout = ''
if collectStderr:
self.stderr = ''

def run(self, step, remote):
# delegate back to the test case
Expand Down Expand Up @@ -76,14 +79,17 @@ def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1,
timeout=20*60, maxTime=None, logfiles={},
usePTY="slave-config", logEnviron=True, collectStdout=False,
collectStderr=False,
interruptSignal=None, initialStdin=None, decodeRC={0:SUCCESS}):
args = dict(workdir=workdir, command=command, env=env or {},
want_stdout=want_stdout, want_stderr=want_stderr,
initial_stdin=initialStdin,
timeout=timeout, maxTime=maxTime, logfiles=logfiles,
usePTY=usePTY, logEnviron=logEnviron)
FakeRemoteCommand.__init__(self, "shell", args,
collectStdout=collectStdout, decodeRC=decodeRC)
collectStdout=collectStdout,
collectStderr=collectStderr,
decodeRC=decodeRC)


class FakeLogFile(object):
Expand Down Expand Up @@ -247,6 +253,8 @@ def runBehavior(self, behavior, args, command):
command.stdout += streams['stdout']
if 'stderr' in streams:
command.logs[name].addStderr(streams['stderr'])
if command.collectStderr:
command.stderr += streams['stderr']
elif behavior == 'callable':
return defer.maybeDeferred(lambda : args[0](command))
else:
Expand Down

0 comments on commit bf7132b

Please sign in to comment.