Skip to content

Commit 1fafc43

Browse files
committed
[IMP] runbot: limit the size of files to open
1 parent 0f2b55a commit 1fafc43

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

runbot/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from odoo.fields import Domain
2020
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT, file_open, html_escape, OrderedSet
2121

22+
DEFAULT_MAX_FILE_SIZE = 500 * 1024 * 1024
23+
2224
_logger = logging.getLogger(__name__)
2325

2426
dest_reg = re.compile(r'^\d{5,}-.+$')

runbot/models/build.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from psycopg2 import sql
1818
from psycopg2.extensions import TransactionRollbackError
1919

20-
from ..common import dt2time, now, grep, local_pgadmin_cursor, dest_reg, os, list_local_dbs, pseudo_markdown, RunbotException, findall, sanitize, markdown_escape, tail
20+
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
2121
from ..container import docker_stop, docker_state, Command, docker_run, docker_pull
2222
from ..fields import JsonDictField
2323

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

14101410
def _read_file(self, file, mode='r'):
14111411
file_path = self._path(file)
1412+
max_log_file_size = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_max_log_size', DEFAULT_MAX_FILE_SIZE)
1413+
if os.path.getsize(file_path) > max_log_file_size:
1414+
self._log('readfile', f"File size exceeds {max_log_file_size} limit", level="ERROR")
1415+
return False
14121416
try:
14131417
with file_open(file_path, mode) as f:
14141418
return f.read()

runbot/models/build_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import shlex
99
import time
1010
from unidiff import PatchSet
11-
from ..common import now, grep, time2str, rfind, s2human, os, RunbotException, ReProxy, markdown_escape
11+
from ..common import now, grep, time2str, rfind, s2human, os, RunbotException, ReProxy, markdown_escape, DEFAULT_MAX_FILE_SIZE
1212
from ..container import docker_get_gateway_ip, Command
1313
from odoo import models, fields, api, tools
1414
from odoo.exceptions import UserError, ValidationError
@@ -1298,6 +1298,10 @@ def _check_log(self, build):
12981298
if not os.path.isfile(log_path):
12991299
build._log('_make_tests_results', "Log file not found at the end of test job", level="ERROR")
13001300
return 'ko'
1301+
max_log_file_size = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_max_log_size', DEFAULT_MAX_FILE_SIZE)
1302+
if os.path.getsize(log_path) > max_log_file_size:
1303+
build._log('_make_tests_results', f"Log file exceeds {max_log_file_size} limit", level="ERROR")
1304+
return 'ko'
13011305
return 'ok'
13021306

13031307
def _check_module_loaded(self, build):

runbot/tests/test_build_config_step.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from odoo.exceptions import UserError
99
from odoo.addons.runbot.common import RunbotException
1010
from .common import RunbotCase
11-
from ..common import markdown_unescape
11+
from ..common import markdown_unescape, DEFAULT_MAX_FILE_SIZE
1212

1313

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

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

12571258
self.build = self.Build.create({
12581259
'params_id': self.base_params.id,
@@ -1474,3 +1475,10 @@ def make_warn(build):
14741475
mock_make_odoo_results.side_effect = make_warn
14751476
config_step._make_results(build)
14761477
self.assertEqual(build.local_result, 'warn')
1478+
1479+
def test_make_result_large_file(self):
1480+
self.patchers['get_size'].return_value = DEFAULT_MAX_FILE_SIZE * 2
1481+
self.config_step._make_results(self.build)
1482+
self.assertEqual(str(self.build.job_end), '1970-01-01 02:00:00')
1483+
self.assertIn(('ERROR', 'Log file exceeds %s limit' % DEFAULT_MAX_FILE_SIZE), self.logs)
1484+
self.assertEqual(self.build.local_result, 'ko')

runbot/tests/test_upgrade.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def setUp(self):
1919

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

2425
self.master_bundle = self.branch_odoo.bundle_id

0 commit comments

Comments
 (0)