Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] runbot: reference slot instead of builds #1069

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
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: 1 addition & 1 deletion runbot/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'author': "Odoo SA",
'website': "http://runbot.odoo.com",
'category': 'Website',
'version': '5.8',
'version': '5.9',
'application': True,
'depends': ['base', 'base_automation', 'website'],
'data': [
Expand Down
22 changes: 22 additions & 0 deletions runbot/migrations/18.0.5.9/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging

_logger = logging.getLogger(__name__)


def migrate(cr, version):
# copy infor from ol build_reference_ids to slot_reference_ids
# old table is runbot_build_params_references
# new table is runbot_build_params_slot_references
cr.execute("""
ALTER TABLE runbot_build_params_slot_references DISABLE TRIGGER ALL;
INSERT INTO runbot_build_params_slot_references (runbot_build_params_id, runbot_batch_slot_id)
SELECT ref.runbot_build_params_id, slot.id
FROM runbot_build_params_references ref
JOIN LATERAL (
SELECT id
FROM runbot_batch_slot sl
WHERE sl.build_id = ref.runbot_build_id
LIMIT 1
) slot(id) ON TRUE;
ALTER TABLE runbot_build_params_slot_references ENABLE TRIGGER ALL;
""")
2 changes: 1 addition & 1 deletion runbot/models/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def _fill_missing(branch_commits, match_type):
'used_custom_trigger': bool(trigger_custom),
}

params_value['builds_reference_ids'] = trigger._reference_builds(self)
params_value['slot_reference_ids'] = [(4, s.id) for s in trigger._reference_slots(self)]

params = self.env['runbot.build.params'].create(params_value)

Expand Down
10 changes: 8 additions & 2 deletions runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class BuildParameters(models.Model):
used_custom_trigger = fields.Boolean('Custom trigger was used to generate this build')

build_ids = fields.One2many('runbot.build', 'params_id')
builds_reference_ids = fields.Many2many('runbot.build', relation='runbot_build_params_references', copy=True)
#builds_reference_ids = fields.Many2many('runbot.build', relation='runbot_build_params_references', copy=True)
builds_reference_ids = fields.Many2many('runbot.build', compute='_compute_builds_reference_ids')
slot_reference_ids = fields.Many2many('runbot.batch.slot', relation='runbot_build_params_slot_references', copy=True)
modules = fields.Char('Modules')

upgrade_to_build_id = fields.Many2one('runbot.build', index=True) # use to define sources to use with upgrade script
Expand All @@ -96,7 +98,7 @@ def _compute_fingerprint(self):
'config_data': param.config_data.dict,
'modules': param.modules or '',
'commit_link_ids': sorted(param.commit_link_ids.commit_id.ids),
'builds_reference_ids': sorted(param.builds_reference_ids.ids),
'slot_reference_ids': sorted(param.slot_reference_ids.ids),
'upgrade_from_build_id': param.upgrade_from_build_id.id,
'upgrade_to_build_id': param.upgrade_to_build_id.id,
'dump_db': param.dump_db.id,
Expand All @@ -110,6 +112,10 @@ def _compute_fingerprint(self):

param.fingerprint = hashlib.sha256(str(cleaned_vals).encode('utf8')).hexdigest()

def _compute_builds_reference_ids(self):
for params in self:
params.builds_reference_ids = params.slot_reference_ids.build_id

@api.depends('commit_link_ids')
def _compute_commit_ids(self):
for params in self:
Expand Down
8 changes: 4 additions & 4 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,16 +855,16 @@ def _run_restore(self, build):

return dict(cmd=cmd)

def _reference_builds(self, batch, trigger):
def _reference_slots(self, batch, trigger):
upgrade_dumps_trigger_id = trigger.upgrade_dumps_trigger_id
refs_batches = self._reference_batches(batch, trigger)
refs_builds = refs_batches.mapped('slot_ids').filtered(
refs_slots = refs_batches.mapped('slot_ids').filtered(
lambda slot: slot.trigger_id == upgrade_dumps_trigger_id
).mapped('build_id')
)
# should we filter on active? implicit. On match type? on skipped ?
# is last_"done"_batch enough?
# TODO active test false and take last done/running build limit 1 -> in case of rebuild
return refs_builds
return refs_slots

def _is_upgrade_step(self):
return self.job_type in ('configure_upgrade', 'configure_upgrade_complement')
Expand Down
6 changes: 3 additions & 3 deletions runbot/models/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def _upgrade_step_from_config(self, config):
raise UserError('Upgrade trigger should have a config with step of type Configure Upgrade')
return upgrade_step

def _reference_builds(self, batch):
def _reference_slots(self, batch):
self.ensure_one()
if self.upgrade_step_id: # this is an upgrade trigger, add corresponding builds
custom_config = next((trigger_custom.config_id for trigger_custom in batch.bundle_id.trigger_custom_ids if trigger_custom.trigger_id == self), False)
step = self._upgrade_step_from_config(custom_config) if custom_config else self.upgrade_step_id
refs_builds = step._reference_builds(batch, self)
return [(4, b.id) for b in refs_builds]
refs_slots = step._reference_slots(batch, self)
return refs_slots
return []

def _get_version_domain(self):
Expand Down
2 changes: 1 addition & 1 deletion runbot/templates/batch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</td>
<td>
<t t-foreach="reference_batch_ids.sorted(lambda b: b.bundle_id.version_id.number, reverse=True)" t-as="reference_batch">
<div t-att-title="f'Created {s2human(reference_batch.create_date - batch.create_date)} before this one'">
<div t-attf-title="Created {{s2human(reference_batch.create_date - batch.create_date)}} before this one">
<a t-attf-href="/runbot/batch/{{reference_batch.id}}"><t t-out="reference_batch.bundle_id.version_id.name"/> (<t t-out="reference_batch.id"/>)</a>
</div>
</t>
Expand Down
13 changes: 9 additions & 4 deletions runbot/templates/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@
<b>Extra params:</b>
<t t-out="build.params_id.extra_params"/>
<br/>
<t t-if="build.params_id.builds_reference_ids">
<b>Reference builds:</b>
<div t-foreach="build.params_id.builds_reference_ids" t-as="reference">
<a t-attf-href="/runbot/build/{{reference.id}}"><t t-esc="reference.id"/></a> - <em t-out="reference.params_id.version_id.name"/>
<t t-if="build.params_id.slot_reference_ids">
<b>Reference slots:</b>
<div t-foreach="build.params_id.slot_reference_ids" t-as="slot_reference">
<t t-if="slot_reference.build_id">
<a t-attf-href="/runbot/build/{{slot_reference.build_id.id}}"><t t-esc="slot_reference.build_id.id"/></a> - <em t-out="slot_reference.params_id.version_id.name"/>
</t>
<t t-else="">
<a t-attf-href="/runbot/batch/{{slot_reference.batch_id.id}}">Missing build for slot<t t-esc="slot_reference.trigger_id.name"/></a> - <em t-out="slot_reference.params_id.version_id.name"/>
</t>
</div>
</t>
<t t-if="len(build.params_id.build_ids) > 1">
Expand Down