Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions runbot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from odoo.fields import Domain
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT, file_open, html_escape, OrderedSet

DEFAULT_MAX_FILE_SIZE = 500 * 1024 * 1024

_logger = logging.getLogger(__name__)

dest_reg = re.compile(r'^\d{5,}-.+$')
Expand Down
6 changes: 5 additions & 1 deletion runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from psycopg2 import sql
from psycopg2.extensions import TransactionRollbackError

from ..common import dt2time, now, grep, local_pgadmin_cursor, dest_reg, os, list_local_dbs, pseudo_markdown, RunbotException, findall, sanitize, markdown_escape, tail
from ..common import dt2time, now, grep, local_pgadmin_cursor, dest_reg, os, list_local_dbs, pseudo_markdown, RunbotException, findall, sanitize, markdown_escape, tail, DEFAULT_MAX_FILE_SIZE
from ..container import docker_stop, docker_state, Command, docker_run, docker_pull
from ..fields import JsonDictField

Expand Down Expand Up @@ -1409,6 +1409,10 @@ def _is_file(self, file, mode='r'):

def _read_file(self, file, mode='r'):
file_path = self._path(file)
max_log_file_size = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_max_log_size', DEFAULT_MAX_FILE_SIZE)
if os.path.getsize(file_path) > max_log_file_size:
self._log('readfile', f"File size exceeds {max_log_file_size} limit", level="ERROR")
return False
try:
with file_open(file_path, mode) as f:
return f.read()
Expand Down
6 changes: 5 additions & 1 deletion runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import shlex
import time
from unidiff import PatchSet
from ..common import now, grep, time2str, rfind, s2human, os, RunbotException, ReProxy, markdown_escape
from ..common import now, grep, time2str, rfind, s2human, os, RunbotException, ReProxy, markdown_escape, DEFAULT_MAX_FILE_SIZE
from ..container import docker_get_gateway_ip, Command
from odoo import models, fields, api, tools
from odoo.exceptions import UserError, ValidationError
Expand Down Expand Up @@ -1298,6 +1298,10 @@ def _check_log(self, build):
if not os.path.isfile(log_path):
build._log('_make_tests_results', "Log file not found at the end of test job", level="ERROR")
return 'ko'
max_log_file_size = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_max_log_size', DEFAULT_MAX_FILE_SIZE)
if os.path.getsize(log_path) > max_log_file_size:
build._log('_make_tests_results', f"Log file exceeds {max_log_file_size} limit", level="ERROR")
return 'ko'
return 'ok'

def _check_module_loaded(self, build):
Expand Down
6 changes: 5 additions & 1 deletion runbot/models/build_stat_regex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import logging

from ..common import os
from ..common import os, DEFAULT_MAX_FILE_SIZE
import re

from odoo import models, fields, api
Expand Down Expand Up @@ -53,6 +53,10 @@ def _find_in_file(self, file_path):
"""
if not os.path.exists(file_path):
return {}
max_log_file_size = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_max_log_size', DEFAULT_MAX_FILE_SIZE)
if os.path.getsize(file_path) > max_log_file_size:
_logger.warning("Log file '%s' exceeds %s limit", file_path, max_log_file_size)
return {}
stats_matches = {}
with file_open(file_path, "r") as log_file:
data = log_file.read()
Expand Down
10 changes: 9 additions & 1 deletion runbot/tests/test_build_config_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from odoo.exceptions import UserError
from odoo.addons.runbot.common import RunbotException
from .common import RunbotCase
from ..common import markdown_unescape
from ..common import markdown_unescape, DEFAULT_MAX_FILE_SIZE


class TestBuildConfigStepCommon(RunbotCase):
Expand Down Expand Up @@ -1253,6 +1253,7 @@ def _log(build, func, message, level='INFO', log_type='runbot', path='runbot'):
self.logs.append((level, message))

self.start_patcher('log_patcher', 'odoo.addons.runbot.models.build.BuildResult._log', new=_log)
self.start_patcher('get_size', 'odoo.addons.runbot.models.build_config.os.path.getsize', return_value=100)

self.build = self.Build.create({
'params_id': self.base_params.id,
Expand Down Expand Up @@ -1474,3 +1475,10 @@ def make_warn(build):
mock_make_odoo_results.side_effect = make_warn
config_step._make_results(build)
self.assertEqual(build.local_result, 'warn')

def test_make_result_large_file(self):
self.patchers['get_size'].return_value = DEFAULT_MAX_FILE_SIZE * 2
self.config_step._make_results(self.build)
self.assertEqual(str(self.build.job_end), '1970-01-01 02:00:00')
self.assertIn(('ERROR', 'Log file exceeds %s limit' % DEFAULT_MAX_FILE_SIZE), self.logs)
self.assertEqual(self.build.local_result, 'ko')
1 change: 1 addition & 0 deletions runbot/tests/test_build_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class TestBuildStatRegex(RunbotCase):
def setUp(self):
super(TestBuildStatRegex, self).setUp()
self.start_patcher('get_size', 'odoo.addons.runbot.models.build_config.os.path.getsize', return_value=100)
self.StatRegex = self.env["runbot.build.stat.regex"]
self.ConfigStep = self.env["runbot.build.config.step"]
self.BuildStat = self.env["runbot.build.stat"]
Expand Down
1 change: 1 addition & 0 deletions runbot/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setUp(self):

def upgrade_flow_setup(self):
self.start_patcher('find_patcher', 'odoo.addons.runbot.common.find', 0)
self.start_patcher('get_size', 'odoo.addons.runbot.models.build_config.os.path.getsize', return_value=100)
self.additionnal_setup()

self.master_bundle = self.branch_odoo.bundle_id
Expand Down