def _report_results(self, test_playbook): '''Report results from playbook's ``results.yml`` (stored in artifactsdir) into ResultsDB. :param str test_playbook: base name of the playbook file :raise CheckbDirectiveError: when there's a problem processing ``results.yml`` file ''' results_file = os.path.join(self.arg_data['artifactsdir'], test_playbook, 'checkb', 'results.yml') log.info('Reporting results from: %s', results_file) if not os.path.exists(results_file): raise exc.CheckbDirectiveError( "Results file doesn't exist, " 'assuming the task crashed. If you wish to report no results, ' 'the results file still needs to exist - consult ' 'documentation. Expected results file location: %s' % results_file) rdb = resultsdb_directive.ResultsdbDirective() rdb.process(params={"file": results_file}, arg_data=self.arg_data) # create file indicating that results were reported to resultsdb reported_file = os.path.join(self.arg_data['artifactsdir'], test_playbook, 'checkb', 'results.yml.reported_ok') open(reported_file, 'a').close()
def process(self, params, arg_data): output_data = {} valid_actions = ['download'] action = params.get('action', None) if action not in valid_actions: raise CheckbDirectiveError( '%s is not a valid command for bodhi directive' % action) if 'arch' not in params or 'target_dir' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The bodhi directive requires 'arch' and 'target_dir' as an " "argument. Detected arguments: %s" % detected_args) # convert str to list if isinstance(params['arch'], basestring): params['arch'] = [params['arch']] if action == 'download': if 'update_id' not in params or 'arch' not in params: detected_args = ', '.join(params.keys()) raise CheckbDirectiveError( "The bodhi directive 'download' requires both 'update_id' and " "'arch' arguments. Detected arguments: %s" % detected_args) target_dir = params['target_dir'] updateid = params['update_id'] if 'all' in params['arch']: arches = config.get_config().supported_arches + ['noarch'] else: arches = params['arch'] if arches and ('noarch' not in arches): arches.append('noarch') src = params.get('src', False) log.info("getting rpms for update %s (%s) and downloading to %s", updateid, arches, target_dir) output_data['downloaded_rpms'] = self.action_download( updateid, arches, src, target_dir) return output_data
def process(self, params, arg_data): if 'file' in params and 'results' in params: raise CheckbDirectiveError( "Either `file` or `results` can be used, not both.") if 'artifactsdir' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The directive requires 'artifactsdir' as an " "argument. Detected arguments: %s" % detected_args) artifactsdir = params['artifactsdir'] try: if params.get('file', None): with open(params['file']) as resultfile: params['results'] = resultfile.read() check_details = check.import_YAML(params['results']) log.debug("YAML output parsed OK.") except (CheckbValueError, IOError) as e: raise CheckbDirectiveError("Failed to load results: %s" % e.message) log.debug('Generating report of %s results...', len(check_details)) results = [] for detail in check_details: results.append({ 'checkname': detail.checkname, 'outcome': detail.outcome, 'note': detail.note or '---', 'item': detail.item, 'type': detail.report_type, 'artifact': os.path.basename(detail.artifact) if detail.artifact else None, }) if 'path' in params: report_fname = os.path.join(artifactsdir, params['path']) else: report_fname = os.path.join(artifactsdir, 'report.html') if 'template' in params: template_fname = params['template'] else: template_fname = os.path.join(config.get_config()._data_dir, 'report_templates/html.j2') try: file_utils.makedirs(os.path.dirname(report_fname)) except OSError as e: raise CheckbDirectiveError(e) with open(template_fname) as f_template: with open(report_fname, 'w') as f_report: template = jinja2.Template(f_template.read()) report = template.render(results=results, artifactsdir=artifactsdir) f_report.write(report) log.info('Report generated in: %s', os.path.abspath(report_fname))
def process(self, params, arg_data): # process params valid_actions = ['download', 'download_tag', 'download_latest_stable'] action = params['action'] if action not in valid_actions: raise exc.CheckbDirectiveError('%s is not a valid action for koji ' 'directive' % action) if 'arch' not in params or 'target_dir' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The koji directive requires 'arch' and 'target_dir' as an " "argument. Detected arguments: %s" % detected_args) # convert str to list for param in ('arch', 'arch_exclude'): if param in params and isinstance(params[param], basestring): params[param] = [params[param]] arches = list(params['arch']) if arches and ('all' not in arches) and ('noarch' not in arches): arches.append('noarch') arch_exclude = params.get('arch_exclude', []) debuginfo = params.get('debuginfo', False) src = params.get('src', False) build_log = params.get('build_log', False) target_dir = params['target_dir'] file_utils.makedirs(target_dir) # download files output_data = {} if action == 'download': if 'koji_build' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The koji directive requires 'koji_build' for the 'download' " "action. Detected arguments: %s" % detected_args) nvr = rpm_utils.rpmformat(params['koji_build'], 'nvr') output_data['downloaded_rpms'] = self.koji.get_nvr_rpms( nvr, target_dir, arches=arches, arch_exclude=arch_exclude, debuginfo=debuginfo, src=src) elif action == 'download_tag': if 'koji_tag' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The koji directive requires 'koji_tag' for the 'download_tag' " "action. Detected arguments: %s" % detected_args) koji_tag = params['koji_tag'] output_data['downloaded_rpms'] = self.koji.get_tagged_rpms( koji_tag, target_dir, arches=arches, arch_exclude=arch_exclude, debuginfo=debuginfo, src=src) elif action == 'download_latest_stable': if 'koji_build' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The koji directive requires 'koji_build' for the 'download_latest_stable' " "action. Detected arguments: %s" % detected_args) name = rpm_utils.rpmformat(params['koji_build'], 'n') disttag = rpm_utils.get_dist_tag(params['koji_build']) # we need to do 'fc22' -> 'f22' conversion tag = disttag.replace('c', '') # first we need to check updates tag and if that fails, the latest # stable nvr is in the base repo tags = ['%s-updates' % tag, tag] nvr = self.koji.latest_by_tag(tags, name) if not nvr: log.info("There's no previous stable build for %s, skipping.", params['koji_build']) assert output_data == {} return output_data output_data['downloaded_rpms'] = self.koji.get_nvr_rpms( nvr, target_dir, arch_exclude=arch_exclude, arches=arches, debuginfo=debuginfo, src=src) # download build.log if requested if build_log: if action in ('download', 'download_latest_stable'): ret_log = self.koji.get_build_log( nvr, target_dir, arches=arches, arch_exclude=arch_exclude) output_data['downloaded_logs'] = ret_log['ok'] output_data['log_errors'] = ret_log['error'] else: log.warning("Downloading build logs is not supported for action '%s', ignoring.", action) return output_data
def process(self, params, arg_data): if ('package' not in params and 'nvr' not in params) or 'path' not in params \ or 'target_dir' not in params: detected_args = ', '.join(params.keys()) raise exc.CheckbDirectiveError( "The distgit directive requires 'package' (or 'nvr') and 'path' and 'target_dir' arguments." "Detected arguments: %s" % detected_args) package = None gitref = None namespace = None if 'nvr' in params: nvr = params['nvr'] package = rpm_utils.rpmformat(nvr, fmt='n') gitref = rpm_utils.get_dist_tag(nvr).replace('c', '') rawhide_tag = yumrepoinfo.YumRepoInfo(resolve_baseurl=False).get( 'rawhide', 'tag') if gitref == rawhide_tag: gitref = 'master' namespace = 'rpms' # Assign defaults package = params.get('package', package) gitref = params.get('gitref', gitref or 'master') namespace = params.get('namespace', namespace or 'rpms') baseurl = params.get('baseurl', BASEURL) target_dir = params['target_dir'] ignore_missing = params.get('ignore_missing', False) if not python_utils.iterable(params['path']): raise exc.CheckbValueError( "Incorrect value type of the 'path' argument: " "%s" % type(params['path'])) target_path = params['path'] output_data = {} if 'localpath' in params: if not python_utils.iterable(params['localpath']): raise exc.CheckbValueError( "Incorrect value type of the 'localpath' argument: " "%s" % type(params['path'])) if not len(params['path']) == len(params['localpath']): raise exc.CheckbValueError( 'path and localpath lists must be of the same ' 'length.') target_path = params['localpath'] format_fields = { 'package': package, 'gitref': gitref, 'namespace': namespace, 'baseurl': baseurl, } output_data['downloaded_files'] = [] for path, localpath in zip(params['path'], target_path): localpath = os.path.join(target_dir, localpath) file_utils.makedirs(os.path.dirname(localpath)) url = URL_FMT.format(path=path, **format_fields) try: output_data['downloaded_files'].append( file_utils.download(url, '.', localpath)) except exc.CheckbRemoteError as e: if e.errno == 404 and ignore_missing: log.debug('File not found, ignoring: %s', url) else: raise e return output_data