runbot multihost

This commit is contained in:
Antony Lesuisse 2014-08-13 22:47:41 +02:00
parent 3ae2ab8435
commit e7ca719dca

View File

@ -4,6 +4,7 @@ import datetime
import fcntl import fcntl
import glob import glob
import hashlib import hashlib
import itertools
import logging import logging
import operator import operator
import os import os
@ -12,11 +13,11 @@ import resource
import shutil import shutil
import signal import signal
import simplejson import simplejson
import socket
import subprocess import subprocess
import time
import sys import sys
import time
from collections import OrderedDict from collections import OrderedDict
import itertools
import dateutil.parser import dateutil.parser
import requests import requests
@ -146,6 +147,9 @@ def decode_utf(field):
def uniq_list(l): def uniq_list(l):
return OrderedDict.fromkeys(l).keys() return OrderedDict.fromkeys(l).keys()
def fqdn():
return socket.gethostname()
#---------------------------------------------------------- #----------------------------------------------------------
# RunBot Models # RunBot Models
#---------------------------------------------------------- #----------------------------------------------------------
@ -197,7 +201,7 @@ class runbot_repo(osv.osv):
} }
def domain(self, cr, uid, context=None): def domain(self, cr, uid, context=None):
domain = self.pool.get('ir.config_parameter').get_param(cr, uid, 'runbot.domain', 'runbot.odoo.com') domain = self.pool.get('ir.config_parameter').get_param(cr, uid, 'runbot.domain', fqdn())
return domain return domain
def root(self, cr, uid, context=None): def root(self, cr, uid, context=None):
@ -308,16 +312,18 @@ class runbot_repo(osv.osv):
icp = self.pool['ir.config_parameter'] icp = self.pool['ir.config_parameter']
workers = int(icp.get_param(cr, uid, 'runbot.workers', default=6)) workers = int(icp.get_param(cr, uid, 'runbot.workers', default=6))
running_max = int(icp.get_param(cr, uid, 'runbot.running_max', default=75)) running_max = int(icp.get_param(cr, uid, 'runbot.running_max', default=75))
host = fqdn()
Build = self.pool['runbot.build'] Build = self.pool['runbot.build']
domain = [('repo_id', 'in', ids)] domain = [('repo_id', 'in', ids)]
domain_host = domain + [('host', '=', host)]
# schedule jobs (transitions testing -> running, kill jobs, ...) # schedule jobs (transitions testing -> running, kill jobs, ...)
build_ids = Build.search(cr, uid, domain + [('state', 'in', ['testing', 'running'])]) build_ids = Build.search(cr, uid, domain_host + [('state', 'in', ['testing', 'running'])])
Build.schedule(cr, uid, build_ids) Build.schedule(cr, uid, build_ids)
# launch new tests # launch new tests
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')]) testing = Build.search_count(cr, uid, domain_host + [('state', '=', 'testing')])
pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')]) pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')])
while testing < workers and pending > 0: while testing < workers and pending > 0:
@ -331,11 +337,11 @@ class runbot_repo(osv.osv):
pending_build.schedule() pending_build.schedule()
# compute the number of testing and pending jobs again # compute the number of testing and pending jobs again
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')]) testing = Build.search_count(cr, uid, domain_host + [('state', '=', 'testing')])
pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')]) pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')])
# terminate and reap doomed build # terminate and reap doomed build
build_ids = Build.search(cr, uid, domain + [('state', '=', 'running')]) build_ids = Build.search(cr, uid, domain_host + [('state', '=', 'running')])
# sort builds: the last build of each sticky branch then the rest # sort builds: the last build of each sticky branch then the rest
sticky = {} sticky = {}
non_sticky = [] non_sticky = []
@ -458,6 +464,7 @@ class runbot_build(osv.osv):
'branch_id': fields.many2one('runbot.branch', 'Branch', required=True, ondelete='cascade', select=1), 'branch_id': fields.many2one('runbot.branch', 'Branch', required=True, ondelete='cascade', select=1),
'repo_id': fields.related('branch_id', 'repo_id', type="many2one", relation="runbot.repo", string="Repository", readonly=True, store=True, ondelete='cascade', select=1), 'repo_id': fields.related('branch_id', 'repo_id', type="many2one", relation="runbot.repo", string="Repository", readonly=True, store=True, ondelete='cascade', select=1),
'name': fields.char('Revno', required=True, select=1), 'name': fields.char('Revno', required=True, select=1),
'host': fields.char('Host'),
'port': fields.integer('Port'), 'port': fields.integer('Port'),
'dest': fields.function(_get_dest, type='char', string='Dest', readonly=1, store=True), 'dest': fields.function(_get_dest, type='char', string='Dest', readonly=1, store=True),
'domain': fields.function(_get_domain, type='char', string='URL'), 'domain': fields.function(_get_domain, type='char', string='URL'),
@ -862,6 +869,7 @@ class runbot_build(osv.osv):
# allocate port and schedule first job # allocate port and schedule first job
port = self.find_port(cr, uid) port = self.find_port(cr, uid)
values = { values = {
'host': fqdn(),
'port': port, 'port': port,
'state': 'testing', 'state': 'testing',
'job': jobs[0], 'job': jobs[0],