Skip to content

Commit 3a82f20

Browse files
committed
fix
1 parent 6181647 commit 3a82f20

7 files changed

Lines changed: 64 additions & 36 deletions

File tree

runbot/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def _docker_run(cmd=False, log_path=False, build_dir=False, container_name=False
261261
run_cmd = f'cd /data/build;touch start-{container_name};{run_cmd};cd /data/build;touch end-{container_name}'
262262
run_cmd_repr = str(run_cmd)
263263
if len(run_cmd_repr) > 250:
264-
run_cmd_repr = run_cmd_repr[:250] + '...'
264+
run_cmd_repr = run_cmd_repr[:250] + '...'
265265
_logger.info('Docker run command: %s', run_cmd_repr)
266266
docker_clear_state(container_name, build_dir) # ensure that no state are remaining
267267
build_dir = file_path(build_dir)

runbot/models/build.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,36 @@
1010
import shutil
1111
import time
1212
import uuid
13-
1413
from collections import defaultdict
15-
from dateutil import parser
1614
from pathlib import Path
15+
16+
from dateutil import parser
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, transactioncache
21-
from ..container import docker_stop, docker_state, Command, docker_run, docker_pull
22-
from ..fields import JsonDictField
23-
24-
from odoo import models, fields, api
25-
20+
from odoo import api, fields, models
2621
from odoo.exceptions import ValidationError
2722
from odoo.tools import file_open, file_path
2823
from odoo.tools.safe_eval import safe_eval
2924

25+
from ..common import (
26+
RunbotException,
27+
dest_reg,
28+
dt2time,
29+
findall,
30+
grep,
31+
list_local_dbs,
32+
local_pgadmin_cursor,
33+
markdown_escape,
34+
now,
35+
os,
36+
pseudo_markdown,
37+
sanitize,
38+
tail,
39+
transactioncache,
40+
)
41+
from ..container import Command, docker_pull, docker_run, docker_state, docker_stop
42+
from ..fields import JsonDictField
3043

3144
_logger = logging.getLogger(__name__)
3245

runbot/models/build_config.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def get_dependant(modules, build, dynamic_vars, depth=None):
5959
dependant = set(build._get_dependant_modules(modules, depth)) - set(modules)
6060
return ','.join(sorted(dependant))
6161

62+
6263
def filter_default_modules(selector, build, dynamic_vars):
6364
modules = build._get_modules_to_test(selector)
6465
return ','.join(modules)
@@ -79,6 +80,7 @@ def keep_modified_modules(modules, build, dynamic_vars, *defaults):
7980
filtered_modules = [module for module in modules if module in modified_modules]
8081
return ','.join(filtered_modules)
8182

83+
8284
def make_module_test_tags(modules, build, dynamic_vars):
8385
return ','.join([f'/{module}' for module in modules.split(',')])
8486

@@ -1539,7 +1541,7 @@ def _run_dynamic(self, build):
15391541
raw_vars = {}
15401542
for config_vars in config_vars_list:
15411543
raw_vars.update(config_vars)
1542-
1544+
15431545
raw_vars.update(build.params_id.config_data.get('dynamic_vars', {}))
15441546
dynamic_vars = {}
15451547
# dynamic_vars can either be raw value like 'account', value to evaluate lazily in anothed dynamic value like 'account->!mail'
@@ -1552,12 +1554,12 @@ def _run_dynamic(self, build):
15521554
dynamic_vars[key] = self._parse_dynamic_entry(value, build, dynamic_vars=dynamic_vars)
15531555

15541556
current_step = self._get_dynamic_step(build)
1555-
if current_step.get('log'):
1556-
text = self._parse_dynamic_entry(current_step['log'], build, dynamic_vars=dynamic_vars)
1557-
build._log('_run_dynamic', text)
15581557
if not current_step:
15591558
build._log('Dynamic Step', 'No dynamic config or steps found, skipping', level="WARNING")
15601559
return
1560+
if current_step.get('log'):
1561+
text = self._parse_dynamic_entry(current_step['log'], build, dynamic_vars=dynamic_vars)
1562+
build._log('_run_dynamic', text)
15611563
if current_step['job_type'] == 'create_build':
15621564
for_each_vars_list = current_step.get('for_each_vars', [{}])
15631565
if 'for_each_module' in current_step:

runbot/models/commit.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44

55
from ..common import os, RunbotException, make_github_session, transactioncache
6-
import glob
76
import shutil
87

98
from odoo import models, fields, api
@@ -193,10 +192,10 @@ def _git_show_files(self, files):
193192
header = buffer[offset:newline_idx].decode('utf-8')
194193
offset = newline_idx + 1
195194
try:
196-
size_in_bytes = int(header.rsplit(' ',1)[-1])
195+
size_in_bytes = int(header.rsplit(' ', 1)[-1])
197196
except ValueError: # most likely missing
198-
results.append(False)
199-
continue
197+
results.append(False)
198+
continue
200199
results.append(buffer[offset : offset + size_in_bytes].decode('utf-8', errors='replace'))
201200
offset += size_in_bytes + 1
202201
return results

runbot/tests/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class RunbotCase(TransactionCase):
1414

15-
def mock_git_helper(self, repo, cmd):
15+
def mock_git_helper(self, repo, cmd, input_data=None, raw=False):
1616
"""Helper that returns a mock for repo._git()"""
1717
if cmd[:2] == ['show', '-s'] or cmd[:3] == ['show', '--pretty="%H -- %s"', '-s']:
1818
return 'commit message for %s' % cmd[-1]
@@ -196,8 +196,8 @@ def setUp(self):
196196
self.docker_run_calls = []
197197
self.diff = ''
198198

199-
def mock_git(repo, cmd, quiet=False):
200-
return self.mock_git_helper(repo, cmd)
199+
def mock_git(repo, cmd, quiet=False, input_data=None, raw=False):
200+
return self.mock_git_helper(repo, cmd, input_data=input_data, raw=raw)
201201

202202
self.start_patcher('git_patcher', 'odoo.addons.runbot.models.repo.Repo._git', new=mock_git)
203203
self.start_patcher('hostname_patcher', 'odoo.addons.runbot.common.socket.gethostname', 'host.runbot.com')

runbot/tests/test_build_config_step.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,22 +451,36 @@ def setUp(self):
451451
"web_enterprise": ["web"],
452452
}
453453

454-
def mock_git_helper(self, repo, cmd):
455-
if repo == self.repo_odoo and cmd == ['show', 'dfdfcfcf0000ffffffffffffffffffffffffffff:odoo/tests/.runbot/parallel_testing.json']:
456-
return self.config_file
457-
elif repo == self.repo_odoo and cmd == ['show', 'dfdfcfcf0000ffffffffffffffffffffffffffff:odoo/tests/.runbot/l10n_standalone_testing.json']:
458-
return self.l10n_standalone_testing_file
459-
elif cmd[0] == 'show' and cmd[1].endswith('__manifest__.py'):
460-
module = cmd[1].split(':')[-1].split('/')[-2]
461-
return """{
462-
'name': '%s',
463-
'depends': %s,
464-
}""" % (module, self.module_dependencies.get(module, []))
465-
elif 'show' in cmd:
454+
def mock_git_helper(self, repo, cmd, input_data=None, raw=False):
455+
def make_catfile_output(commit, content):
456+
content_bytes = content.encode('utf-8')
457+
header = f"{commit} blob {len(content_bytes)}\n".encode()
458+
result = header + content_bytes + b"\n"
459+
return result
460+
461+
if cmd == ['cat-file', '--batch']:
462+
if repo == self.repo_odoo and input_data == 'dfdfcfcf0000ffffffffffffffffffffffffffff:odoo/tests/.runbot/parallel_testing.json\n':
463+
return make_catfile_output('dfdfcfcf0000ffffffffffffffffffffffffffff', self.config_file)
464+
if repo == self.repo_odoo and input_data == 'dfdfcfcf0000ffffffffffffffffffffffffffff:odoo/tests/.runbot/l10n_standalone_testing.json\n':
465+
return make_catfile_output('dfdfcfcf0000ffffffffffffffffffffffffffff', self.l10n_standalone_testing_file)
466+
467+
if "__manifest__.py" in input_data:
468+
modules_info = [
469+
(line, line.split(':')[-1].split('/')[-2])
470+
for line in input_data.splitlines()
471+
if line.endswith('__manifest__.py')
472+
]
473+
result = b""
474+
for original_query, module in modules_info:
475+
content = '''{'name': '%s', 'depends': %s}''' % (module, self.module_dependencies.get(module, []))
476+
result += make_catfile_output(original_query.split(':')[0], content)
477+
return result
478+
479+
if cmd == ['cat-file', '--batch']:
466480
raise subprocess.CalledProcessError(cmd, 128)
467481
elif 'diff' in cmd:
468482
return 'odoo/addons/crm/some/file.py\nodoo/addons/project/some/file.py'
469-
return super().mock_git_helper(repo, cmd)
483+
return super().mock_git_helper(repo, cmd, input_data, raw)
470484

471485
def test_module_filters(self):
472486
self.assertEqual(self.build._get_modules_to_test('-> !mail'), ['account', 'base', 'crm', 'documents'])
@@ -859,7 +873,7 @@ def test_modified_existing_module(self):
859873
self.assertEqual(child_dynamic_vars, {
860874
'modified_modules': 'crm,mail',
861875
'test_modules': 'test_mail',
862-
'modules_to_test': 'crm,mail,test_mail'
876+
'modules_to_test': 'crm,mail,test_mail',
863877
})
864878

865879
def test_modified_existing_module_parallel(self):

runbot/tests/test_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def setUp(self):
372372
self.fetch_count = 0
373373
self.force_failure = False
374374

375-
def mock_git_helper(self, repo, cmd):
375+
def mock_git_helper(self, repo, cmd, input_data=None, raw=False):
376376
self.assertIn('fetch', cmd)
377377
self.fetch_count += 1
378378
if self.fetch_count < 3 or self.force_failure:
@@ -457,7 +457,7 @@ def setUp(self):
457457
super().setUp()
458458
self.test_refs = []
459459

460-
def mock_git_helper(self, repo, cmd):
460+
def mock_git_helper(self, repo, cmd, input_data=None, raw=False):
461461
self.assertIn('for-each-ref', cmd)
462462
self.assertIn('refs/*/pull/*', cmd)
463463
return '\n'.join(['\x00'.join(ref_data) for ref_data in self.test_refs])

0 commit comments

Comments
 (0)