[IMP] runbot: get the logdb uri from a config parameter

When a build is created, the --log-db command line argument is built
using the same db and credentials that the one used by the runbot.

With this commit, this argument is built based on a postgress connect
URI given as ir.config_parameter in the settings.

A dedicated role must be created beforehand on the runbot postgresql
server, accordingly to the given URI.

Also, care should be taken to give minimal privileges to this user only
granting "update" on the table ir_logging_id_seq and
"insert,select,udpate" on the table ir_logging.
This commit is contained in:
Christophe Monniez 2019-01-11 16:57:21 +01:00
parent b40bd6da5f
commit 8ef9eafc60
4 changed files with 27 additions and 3 deletions

View File

@ -679,9 +679,10 @@ class runbot_build(models.Model):
if grep(build._server("tools/config.py"), "no-netrpc"):
cmd.append("--no-netrpc")
if grep(build._server("tools/config.py"), "log-db"):
logdb_uri = self.env['ir.config_parameter'].get_param('runbot.runbot_logdb_uri')
logdb = self.env.cr.dbname
if config['db_host'] and grep(build._server('sql_db.py'), 'allow_uri'):
logdb = 'postgres://{cfg[db_user]}:{cfg[db_password]}@{cfg[db_host]}/{db}'.format(cfg=config, db=self.env.cr.dbname)
if logdb_uri and grep(build._server('sql_db.py'), 'allow_uri'):
logdb = '%s' % logdb_uri
cmd += ["--log-db=%s" % logdb]
if grep(build._server('tools/config.py'), 'log-db-level'):
cmd += ["--log-db-level", '25']

View File

@ -13,6 +13,7 @@ class ResConfigSettings(models.TransientModel):
runbot_starting_port = fields.Integer('Starting port for running builds')
runbot_domain = fields.Char('Runbot domain')
runbot_max_age = fields.Integer('Max branch age (in days)')
runbot_logdb_uri = fields.Char('Runbot URI for build logs')
@api.model
def get_values(self):
@ -23,7 +24,9 @@ class ResConfigSettings(models.TransientModel):
runbot_timeout=int(get_param('runbot.runbot_timeout', default=1800)),
runbot_starting_port=int(get_param('runbot.runbot_starting_port', default=2000)),
runbot_domain=get_param('runbot.runbot_domain', default=common.fqdn()),
runbot_max_age=int(get_param('runbot.runbot_max_age', default=30)))
runbot_max_age=int(get_param('runbot.runbot_max_age', default=30)),
runbot_logdb_uri=get_param('runbot.runbot_logdb_uri', default=False),
)
return res
@api.multi
@ -36,3 +39,4 @@ class ResConfigSettings(models.TransientModel):
set_param("runbot.runbot_starting_port", self.runbot_starting_port)
set_param("runbot.runbot_domain", self.runbot_domain)
set_param("runbot.runbot_max_age", self.runbot_max_age)
set_param("runbot.runbot_logdb_uri", self.runbot_logdb_uri)

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from unittest.mock import patch
from odoo.tools.config import configmanager
from odoo.tests import common
class Test_Build(common.TransactionCase):
@ -43,6 +44,20 @@ class Test_Build(common.TransactionCase):
build._get_domain()
self.assertEqual(build.domain, 'runbot99.example.org:1234')
@patch('odoo.addons.runbot.models.build.os.mkdir')
@patch('odoo.addons.runbot.models.build.grep')
def test_build_cmd_log_db(self, mock_grep, mock_mkdir):
""" test that the logdb connection URI is taken from the .odoorc file """
uri = 'postgres://someone:pass@somewhere.com/db'
self.env['ir.config_parameter'].sudo().set_param("runbot.runbot_logdb_uri", uri)
build = self.Build.create({
'branch_id': self.branch.id,
'name': 'd0d0caca0000ffffffffffffffffffffffffffff',
'port': '1234',
})
cmd = build._cmd()[0]
self.assertIn('--log-db=%s' % uri, cmd)
def test_pr_is_duplicate(self):
""" test PR is a duplicate of a dev branch build """
dup_repo = self.Repo.create({

View File

@ -42,6 +42,10 @@
<label for="runbot_max_age" class="col-xs-3 o_light_label" style="width: 60%;"/>
<field name="runbot_max_age" style="width: 30%;"/>
</div>
<div class="mt-16 row">
<label for="runbot_logdb_uri" class="col-xs-3 o_light_label" style="width: 60%;"/>
<field name="runbot_logdb_uri" style="width: 30%;"/>
</div>
</div>
</div>
</div>