Wrap stdout object only once with wrap_stream

Make sure to perform wrap external to loop, as otherwise this will
recursively wrap the output object and potentially result in getattr
lookups exceeding the recursion limit in python.

Change-Id: Ie9318a3d23a721e62c16e7b05f52d5b9bec1bb82
This commit is contained in:
Darragh Bailey 2016-01-11 17:58:17 +00:00
parent 71449dbed9
commit e1f5dec356
2 changed files with 5 additions and 2 deletions
jenkins_jobs
tests/cmd/subcommands

@ -350,12 +350,15 @@ class Builder(object):
raise
if output:
# ensure only wrapped once
if hasattr(output, 'write'):
output = utils.wrap_stream(output)
for job in self.parser.xml_jobs:
if hasattr(output, 'write'):
# `output` is a file-like object
logger.info("Job name: %s", job.name)
logger.debug("Writing XML to '{0}'".format(output))
output = utils.wrap_stream(output)
try:
output.write(job.output())
except IOError as exc:

@ -71,7 +71,7 @@ class TestTests(CmdTestsBase):
os.path.join(self.fixtures_path,
'cmd-001.yaml'),
'invalid'])
args.output_dir = mock.MagicMock()
args.output_dir = mock.MagicMock(wraps=io.BytesIO())
cmd.execute(args, self.config) # probably better to fail here
def test_valid_job(self):