[IMP] runbot: improve archive failure logging

This commit is contained in:
Xavier-Do 2019-08-22 14:36:30 +02:00
parent 57a32ee937
commit a91b08897f
2 changed files with 14 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import time
import datetime import datetime
from ..common import dt2time, fqdn, now, grep, uniq_list, local_pgadmin_cursor, s2human, Commit from ..common import dt2time, fqdn, now, grep, uniq_list, local_pgadmin_cursor, s2human, Commit
from ..container import docker_build, docker_stop, docker_is_running, Command from ..container import docker_build, docker_stop, docker_is_running, Command
from odoo.addons.runbot.models.repo import HashMissingException from odoo.addons.runbot.models.repo import HashMissingException, ArchiveFailException
from odoo import models, fields, api from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.http import request from odoo.http import request
@ -729,6 +729,9 @@ class runbot_build(models.Model):
except HashMissingException: except HashMissingException:
self._log('_checkout', "Commit %s is unreachable. Did you force push the branch since build creation?" % commit, level='ERROR') self._log('_checkout', "Commit %s is unreachable. Did you force push the branch since build creation?" % commit, level='ERROR')
self._kill(result='ko') self._kill(result='ko')
except ArchiveFailException:
self._log('_checkout', "Archive %s failed. Did you force push the branch since build creation?" % commit, level='ERROR')
self._kill(result='ko')
return exports return exports
def _get_modules_to_test(self, commits=None): def _get_modules_to_test(self, commits=None):

View File

@ -25,6 +25,9 @@ _logger = logging.getLogger(__name__)
class HashMissingException(Exception): class HashMissingException(Exception):
pass pass
class ArchiveFailException(Exception):
pass
class runbot_repo(models.Model): class runbot_repo(models.Model):
_name = "runbot.repo" _name = "runbot.repo"
@ -121,8 +124,8 @@ class runbot_repo(models.Model):
def _git(self, cmd): def _git(self, cmd):
"""Execute a git command 'cmd'""" """Execute a git command 'cmd'"""
self.ensure_one() self.ensure_one()
_logger.debug("git command: git (dir %s) %s", self.short_name, ' '.join(cmd))
cmd = ['git', '--git-dir=%s' % self.path] + cmd cmd = ['git', '--git-dir=%s' % self.path] + cmd
_logger.debug("git command: %s", ' '.join(cmd))
return subprocess.check_output(cmd).decode('utf-8') return subprocess.check_output(cmd).decode('utf-8')
def _git_rev_parse(self, branch_name): def _git_rev_parse(self, branch_name):
@ -142,7 +145,7 @@ class runbot_repo(models.Model):
self._update(force=True) self._update(force=True)
if not self._hash_exists(sha): if not self._hash_exists(sha):
try: try:
self._git(['fetch', 'origin', sha]) result = self._git(['fetch', 'origin', sha])
except: except:
pass pass
if not self._hash_exists(sha): if not self._hash_exists(sha):
@ -150,10 +153,14 @@ class runbot_repo(models.Model):
_logger.info('git export: checkouting to %s (new)' % export_path) _logger.info('git export: checkouting to %s (new)' % export_path)
os.makedirs(export_path) os.makedirs(export_path)
p1 = subprocess.Popen(['git', '--git-dir=%s' % self.path, 'archive', sha], stdout=subprocess.PIPE) p1 = subprocess.Popen(['git', '--git-dir=%s' % self.path, 'archive', sha], stdout=subprocess.PIPE)
p2 = subprocess.Popen(['tar', '-xmC', export_path], stdin=p1.stdout, stdout=subprocess.PIPE) p2 = subprocess.Popen(['tar', '-xmC', export_path], stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
p2.communicate()[0] (out, err) = p2.communicate()
if err:
raise ArchiveFailException(err)
# TODO get result and fallback on cleaing in case of problem # TODO get result and fallback on cleaing in case of problem
return export_path return export_path