Exemplo n.º 1
0
 def _load_logs_in_db(self):
     for log_type in ('test', 'flake8', 'coverage'):
         try:
             getattr(self, '_load_%s_logs' % log_type)()
         except Exception as e:
             _logger.error('Error while loading %s logs: %s' %
                           (log_type, get_exception_message(e)))
Exemplo n.º 2
0
 def _get_last_server_logs(self):
     branch = self.branch_id.branch_tmpl_id or self.branch_id
     filepath = os.path.join(branch.os_id.odoo_dir, LOGFILE)
     cmd = ['tail', '-n', self.server_logs_length, filepath]
     try:
         self.server_logs = self.docker_host_id.execute_command(
             self.docker_container, cmd)
     except Exception as e:
         self.server_logs = get_exception_message(e)
Exemplo n.º 3
0
 def _set_build_result(self):
     super(ScmRepositoryBranchBuild, self)._set_build_result()
     if self.result.endswith('stable'):
         try:
             modules_list = self._get_modules_list()
             self.branch_id.sudo()._update_modules_list(modules_list)
         except Exception as e:
             _logger.error(
                 'Error while updating installed modules list for %s: %s' %
                 (self.branch_id.display_name, get_exception_message(e)))
Exemplo n.º 4
0
 def _set_to_failed(self, e):
     if self.result == 'killed':
         return
     msg = get_exception_message(e)
     _logger.error(msg)
     self.write_with_new_cursor({
         'state': 'done',
         'result': 'failed',
         'port': '',
         'date_stop': fields.Datetime.now(),
         'error': '...%s' % msg[-77:],
     })
     self.with_context(build_error=msg)._send_build_result('Failed')
Exemplo n.º 5
0
 def _setup_complete(self):
     super(Build, self)._setup_complete()
     callers = [frame[3] for frame in inspect.stack()]
     if 'preload_registries' in callers:
         try:
             _logger.info(
                 "Cleaning testing/running builds before restarting")
             self._remove_not_pending_build_directories()
             self._recreate_testing_builds()
             self._kill_not_really_running_builds()
             self._remove_unknown_containers(['running'])
             self._clean_networks()
         except Exception as e:
             _logger.error(get_exception_message(e))
Exemplo n.º 6
0
 def _setup_complete(self):
     super(Branch, self)._setup_complete()
     callers = [frame[3] for frame in inspect.stack()]
     if 'preload_registries' in callers:
         try:
             _logger.info("Updating branches to find out which ones are "
                          "in registry before restarting")
             for branch in self.search([]):
                 base_branch = branch.branch_tmpl_id or branch
                 image = format_image(base_branch.docker_image)
                 is_in_registry = 'base' in branch.docker_registry_id. \
                     get_image_tags(image)
                 if branch.is_in_registry != is_in_registry:
                     branch.is_in_registry = is_in_registry
         except Exception as e:
             _logger.error(get_exception_message(e))
Exemplo n.º 7
0
 def _copy_sources(self):
     _logger.info('Copying %s sources...' % self.branch_id.display_name)
     try:
         # Do not copy smile_test and useless files
         ignore_patterns = shutil.ignore_patterns(TEST_MODULE,
                                                  *IGNORE_PATTERNS)
         for branch, subfolder in self._get_branches_to_merge():
             mergetree(branch.directory,
                       os.path.join(self.build_directory, subfolder),
                       ignore=ignore_patterns)
         self._add_ci_addons()
     except Exception as e:
         _logger.error(get_exception_message(e))
         self._remove_directory()
         e.traceback = sys.exc_info()
         raise e
Exemplo n.º 8
0
 def _attach_files(self):
     _logger.info('Attaching files for %s...' % self.docker_container)
     branch = self.branch_id.branch_tmpl_id or self.branch_id
     container = self.docker_container
     filepaths = []
     for filename in [
             CONFIGFILE, COVERAGEFILE, LOGFILE, FLAKE8FILE, TESTFILE
     ]:
         filepaths.append(os.path.join(branch.os_id.odoo_dir, filename))
     for path in branch.addons_path.replace(' ', '').split(','):
         filename = '%s.cloc' % path.split('/')[-1]
         filepaths.append(
             os.path.join(branch.os_id.odoo_dir, path, filename))
     missing_files = []
     for filepath in filepaths:
         filename = os.path.basename(filepath)
         filelike = None
         try:
             filelike = StringIO()
             for response in self.docker_host_id.get_archive(
                     container, filepath):
                 filelike.write(response)
             filelike.seek(0)
             tar = tarfile.open(fileobj=filelike)
             content = tar.extractfile(os.path.basename(filepath)).read()
             self.env['ir.attachment'].create({
                 'name':
                 filename,
                 'datas_fname':
                 filename,
                 'datas':
                 base64.b64encode(content or ''),
                 'res_model':
                 self._name,
                 'res_id':
                 self.id,
             })
         except APIError:
             missing_files.append(filename)
         except Exception as e:
             _logger.error('Error while attaching %s: %s' %
                           (filename, get_exception_message(e)))
         finally:
             if filelike is not None:
                 filelike.close()
     if missing_files:
         _logger.info("The following files are missing: %s" % missing_files)
Exemplo n.º 9
0
 def check_branches(self):
     branches_to_deactivate = self.env['scm.repository.branch'].browse()
     for repository in self:
         try:
             if not repository.vcs_id.cmd_list:
                 continue
             branches = repository.list_branches()
             for branch in repository.branch_ids:
                 if branch.branch not in branches:
                     branches_to_deactivate |= branch
         except Exception as e:
             msg = "Check branches failed"
             error = get_exception_message(e)
             _logger.error(msg + ' for repository %s\n\n%s' %
                           (repository.name, error))
             repository.message_post('\n\n'.join([_(msg), error]))
     return branches_to_deactivate.write({'active': False})
Exemplo n.º 10
0
 def _create_build(self, force):
     try:
         self._update()
         if self.check_if_revno_changed() or force is True:
             _logger.info('Creating build for branch %s' %
                          self.display_name)
             self.mapped(
                 'branch_dependency_ids.merge_with_branch_id')._update()
             vals = {
                 'branch_id': self.id,
                 'revno': self.get_revno(),
                 'commit_logs': self.get_last_commits(),
             }
             self.env['scm.repository.branch.build'].create(vals)
     except Exception as e:
         msg = "Build creation failed"
         error = get_exception_message(e)
         _logger.error(msg + ' for branch %s\n\n%s' %
                       (self.display_name, error))
         self.message_post('\n\n'.join([_(msg), error]))
Exemplo n.º 11
0
 def _update(self):
     _logger.info('Updating sources for branch %s' % self.display_name)
     try:
         if self.state == 'draft':
             self.clone()
         else:
             self.pull()
     except UserError as e:
         error = get_exception_message(e)
         if "Could not find remote branch" in error:
             msg = _("Branch deactivated because "
                     "doesn't exist anymore\n\n%s") % error
             self._post_error_message(msg)
         raise
     else:
         nextcall = datetime.strptime(fields.Datetime.now(),
                                      DATETIME_FORMAT)
         nextcall += relativedelta(
             **{self.interval_type: self.interval_number})
         self.nextcall = nextcall.strftime(DATETIME_FORMAT)
Exemplo n.º 12
0
 def _store_in_registry(self):
     try:
         if not self.branch_tmpl_id.is_in_registry:
             branch = self.branch_tmpl_id or self
             super(Branch, branch)._store_in_registry()
             for docker_host in self.env['docker.host'].search([
                 ('id', '!=', branch.docker_host_id.id)
             ]):
                 docker_host.remove_image(branch.docker_registry_image)
             branch.message_post(_("Base image successfully created"))
         self.is_in_registry = True
         # INFO: do not force is_in_registry=True for others children
         # and let scheduled action manage them
     except Exception as e:
         self.use_in_ci = False
         msg = "Base image creation failed"
         error = get_exception_message(e)
         _logger.error(msg + ' for branch %s\n\n%s' %
                       (self.display_name, error))
         self.message_post('\n\n'.join([_(msg), error]))
     else:
         self._create_build(force=True)
Exemplo n.º 13
0
 def _generate_tests_report(self):
     try:
         tests_by_module = self._connect('common').list_tests(
             self.admin_passwd, DBNAME)
         Report = self.env['report'].sudo().with_context(
             tests_by_module=tests_by_module)
         content = Report.get_pdf(self.ids, 'smile_ci.report_tests')
         filename = 'report_tests.pdf'
         self.env['ir.attachment'].create({
             'name':
             filename,
             'datas_fname':
             filename,
             'datas':
             base64.b64encode(content or ''),
             'res_model':
             self._name,
             'res_id':
             self.id,
         })
     except Exception as e:
         _logger.error('Error while generating tests report: %s' %
                       (get_exception_message(e)))