Merge "Limit bytes when reading Ansible output"
This commit is contained in:
commit
9ce5c5e471
|
@ -8067,6 +8067,23 @@ class TestJobOutput(AnsibleZuulTestCase):
|
|||
self.assertReportedStat(post_failure_stat, value='1', kind='c')
|
||||
self.assertReportedStat(post_failure_stat, kind='ms')
|
||||
|
||||
@mock.patch("zuul.executor.server.OUTPUT_MAX_LINE_BYTES", 50)
|
||||
def test_job_output_max_line_bytes(self):
|
||||
logger = logging.getLogger('zuul.AnsibleJob')
|
||||
output = io.StringIO()
|
||||
logger.addHandler(logging.StreamHandler(output))
|
||||
|
||||
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
|
||||
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertHistory([
|
||||
dict(name='job-output', result='SUCCESS', changes='1,1'),
|
||||
], ordered=False)
|
||||
|
||||
log_output = output.getvalue()
|
||||
self.assertIn('Ansible output exceeds max. line size of', log_output)
|
||||
|
||||
|
||||
class TestNoLog(AnsibleZuulTestCase):
|
||||
tenant_config_file = 'config/ansible-no-log/main.yaml'
|
||||
|
|
|
@ -33,6 +33,7 @@ import threading
|
|||
import time
|
||||
import traceback
|
||||
from concurrent.futures.process import ProcessPoolExecutor, BrokenProcessPool
|
||||
from functools import partial
|
||||
|
||||
from kazoo.exceptions import NoNodeError
|
||||
from kazoo.retry import KazooRetry
|
||||
|
@ -90,6 +91,7 @@ from zuul.zk.semaphore import SemaphoreHandler
|
|||
|
||||
|
||||
BUFFER_LINES_FOR_SYNTAX = 200
|
||||
OUTPUT_MAX_LINE_BYTES = 51200 # 50 MiB
|
||||
DEFAULT_FINGER_PORT = 7900
|
||||
DEFAULT_STREAM_PORT = 19885
|
||||
BLACKLISTED_ANSIBLE_CONNECTION_TYPES = [
|
||||
|
@ -2951,7 +2953,13 @@ class AnsibleJob(object):
|
|||
# don't count towards BUFFER_LINES_FOR_SYNTAX
|
||||
idx = 0
|
||||
first = True
|
||||
for line in iter(self.proc.stdout.readline, b''):
|
||||
for line in iter(
|
||||
partial(self.proc.stdout.readline, OUTPUT_MAX_LINE_BYTES),
|
||||
b''):
|
||||
if line and line[-1:] != b'\n':
|
||||
self.log.warning(
|
||||
"Ansible output exceeds max. line size of %s MiB",
|
||||
OUTPUT_MAX_LINE_BYTES / 1024)
|
||||
if first:
|
||||
# When we receive our first log line, bwrap should
|
||||
# have started Ansible and it should still be
|
||||
|
|
Loading…
Reference in New Issue