def run_check(cls, results_dir, **kwargs): """Compares old and new RPMs using pkgdiff""" csmock_report = {} old_pkgs = results_store.get_old_build().get('srpm', None) new_pkgs = results_store.get_new_build().get('srpm', None) cls.results_dir = os.path.join(results_dir, cls.CMD) cls.prepare_results_dir() arguments = [ '--force', '-a', '-r', 'fedora-rawhide-x86_64', '--base-srpm' ] if old_pkgs and new_pkgs: cmd = [cls.CMD] cmd.extend(arguments) cmd.append(old_pkgs) cmd.append(new_pkgs) cmd.extend(['-o', results_dir]) output = io.StringIO() try: ProcessHelper.run_subprocess(cmd, output_file=output) except OSError as e: raise CheckerNotFoundError( "Checker '{}' was not found or installed.".format( cls.name)) from e csmock_report['error'] = PathHelper.find_all_files_current_dir( results_dir, '*.err') csmock_report['txt'] = PathHelper.find_all_files_current_dir( results_dir, '*.txt') csmock_report['log'] = PathHelper.find_all_files_current_dir( results_dir, '*.log') csmock_report['path'] = cls.get_checker_output_dir_short() return csmock_report
def run_check(cls, results_dir): """Compares old and new RPMs using rpmdiff""" results_dict = {} for tag in settings.CHECKER_TAGS: results_dict[tag] = [] cls.results_dir = results_dir # Only S (size), M(mode) and 5 (checksum) are now important not_catched_flags = ['T', 'F', 'G', 'U', 'V', 'L', 'D', 'N'] old_pkgs = cls._get_rpms(results_store.get_old_build().get( 'rpm', None)) new_pkgs = cls._get_rpms(results_store.get_new_build().get( 'rpm', None)) for key, value in six.iteritems(old_pkgs): if 'debuginfo' in key or 'debugsource' in key: # skip debug{info,source} packages continue cmd = [cls.CMD] # TODO modify to online command for x in not_catched_flags: cmd.extend(['-i', x]) cmd.append(value) # We would like to build correct old package against correct new packages try: cmd.append(new_pkgs[key]) except KeyError: logger.warning('New version of package %s was not found!', key) continue output = StringIO() try: ProcessHelper.run_subprocess(cmd, output=output) except OSError: raise CheckerNotFoundError( "Checker '%s' was not found or installed." % cls.CMD) results_dict = cls._analyze_logs(output, results_dict) results_dict = cls.update_added_removed(results_dict) results_dict = dict( (k, v) for k, v in six.iteritems(results_dict) if v) lines = [] for key, val in six.iteritems(results_dict): if val: if lines: lines.append('') lines.append('Following files were %s:' % key) lines.extend(val) rpmdiff_report = os.path.join(cls.results_dir, 'report-' + cls.CMD + '.log') try: with open(rpmdiff_report, "w") as f: f.write('\n'.join(lines)) except IOError: raise RebaseHelperError("Unable to write result from %s to '%s'" % (cls.CMD, rpmdiff_report)) return {rpmdiff_report: None}
def run_check(cls, results_dir, **kwargs): """ Compares old and new RPMs using pkgdiff :param results_dir result dir where are stored results """ cls.results_dir = os.path.join(results_dir, cls.name) cls.prepare_results_dir() cls.pkgdiff_results_full_path_html = os.path.join( cls.results_dir, cls.pkgdiff_results_filename + '.html') cmd = [cls.CMD] cmd.append('-hide-unchanged') for version in ['old', 'new']: old = results_store.get_build(version) if old: file_name = cls._create_xml(version, input_structure=old) cmd.append(file_name) cmd.append('-extra-info') cmd.append(cls.results_dir) cmd.append('-report-path') cmd.append(cls.pkgdiff_results_full_path_html) try: ret_code = ProcessHelper.run_subprocess( cmd, output_file=ProcessHelper.DEV_NULL) except OSError as e: raise CheckerNotFoundError( "Checker '{}' was not found or installed.".format( cls.name)) from e # From pkgdiff source code: # ret_code 0 means unchanged # ret_code 1 means Changed # other return codes means error if int(ret_code) != 0 and int(ret_code) != 1: raise RebaseHelperError( 'Execution of {} failed.\nCommand line is: {}'.format( cls.CMD, cmd)) results_dict = cls.process_xml_results(cls.results_dir) lines: List[str] = [] for key, val in results_dict.items(): if val: if lines: lines.append('') lines.append('Following files were {}:'.format(key)) lines.extend(val) pkgdiff_report = os.path.join(cls.results_dir, cls.pkgdiff_results_filename + '.txt') try: with open(pkgdiff_report, "w", encoding=ENCODING) as f: f.write('\n'.join(lines)) except IOError as e: raise RebaseHelperError( "Unable to write result from {} to '{}'".format( cls.name, pkgdiff_report)) from e return dict(path=cls.get_checker_output_dir_short())
def run_check(cls, result_dir): """Compares old and new RPMs using pkgdiff""" debug_old, rest_pkgs_old = cls._get_packages_for_abipkgdiff(results_store.get_build('old')) debug_new, rest_pkgs_new = cls._get_packages_for_abipkgdiff(results_store.get_build('new')) cmd = [cls.CMD] if debug_old is None: logger.warning("Package doesn't contain any debug package") return None try: cmd.append('--d1') cmd.append(debug_old[0]) except IndexError: logger.error('Debuginfo package not found for old package.') return None try: cmd.append('--d2') cmd.append(debug_new[0]) except IndexError: logger.error('Debuginfo package not found for new package.') return None reports = {} for pkg in rest_pkgs_old: command = list(cmd) # Package can be <letters><numbers>-<letters>-<and_whatever> regexp = r'^(\w*)(-\D+)?.*$' reg = re.compile(regexp) matched = reg.search(os.path.basename(pkg)) if matched: file_name = matched.group(1) command.append(pkg) find = [x for x in rest_pkgs_new if os.path.basename(x).startswith(file_name)] command.append(find[0]) package_name = os.path.basename(os.path.basename(pkg)) logger.debug('Package name for ABI comparision %s', package_name) regexp_name = r'(\w-)*(\D+)*' reg_name = re.compile(regexp_name) matched = reg_name.search(os.path.basename(pkg)) logger.debug('Found matches %s', matched.groups()) if matched: package_name = matched.group(0) + cls.log_name else: package_name = package_name + '-' + cls.log_name output = os.path.join(cls.results_dir, result_dir, package_name) try: ret_code = ProcessHelper.run_subprocess(command, output=output) except OSError: raise CheckerNotFoundError("Checker '%s' was not found or installed." % cls.CMD) if int(ret_code) & settings.ABIDIFF_ERROR and int(ret_code) & settings.ABIDIFF_USAGE_ERROR: raise RebaseHelperError('Execution of %s failed.\nCommand line is: %s' % (cls.CMD, cmd)) if int(ret_code) == 0: text = 'ABI of the compared binaries in package %s are equal.' % package_name else: text = 'ABI of the compared binaries in package %s are not equal.' % package_name reports[output] = text else: logger.debug("Rebase-helper did not find a package name in '%s'", package_name) return reports
def run_check(cls, results_dir, **kwargs): """Compares old and new RPMs using rpmdiff""" results_dict: Dict[str, List[str]] = {} for tag in cls.CHECKER_TAGS: results_dict[tag] = [] cls.results_dir = os.path.join(results_dir, cls.name) cls.prepare_results_dir() # Only S (size), M(mode) and 5 (checksum) are now important not_catched_flags = ['T', 'F', 'G', 'U', 'V', 'L', 'D', 'N'] old_pkgs = cls._get_rpms(results_store.get_old_build().get('rpm', None)) new_pkgs = cls._get_rpms(results_store.get_new_build().get('rpm', None)) for key, value in old_pkgs.items(): if 'debuginfo' in key or 'debugsource' in key: # skip debug{info,source} packages continue cmd = [cls.CMD] # TODO modify to online command for x in not_catched_flags: cmd.extend(['--ignore={0}'.format(x)]) cmd.append(value) # We would like to build correct old package against correct new packages try: cmd.append(new_pkgs[key]) except KeyError: logger.warning('New version of package %s was not found!', key) continue output = io.StringIO() try: ProcessHelper.run_subprocess(cmd, output_file=output) except OSError as e: raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name)) from e results_dict = cls._analyze_logs(output, results_dict) results_dict = cls.update_added_removed(results_dict) cls.results_dict = {k: v for k, v in results_dict.items() if v} lines: List[str] = [] for key, val in results_dict.items(): if val: if lines: lines.append('') lines.append('Following files were {}:'.format(key)) lines.extend(val) rpmdiff_report = os.path.join(cls.results_dir, 'report.txt') counts = {k: len(v) for k, v in results_dict.items()} try: with open(rpmdiff_report, "w", encoding=ENCODING) as f: f.write('\n'.join(lines)) except IOError as e: raise RebaseHelperError("Unable to write result from {} to '{}'".format(cls.name, rpmdiff_report)) from e return {'path': cls.get_checker_output_dir_short(), 'files_changes': counts}
def run_check(cls, results_dir, **kwargs): """Compares old and new RPMs using abipkgdiff""" # Check if ABI changes occured cls.abi_changes = None cls.results_dir = os.path.join(results_dir, cls.NAME) os.makedirs(cls.results_dir) debug_old, rest_pkgs_old = cls._get_packages_for_abipkgdiff( results_store.get_build('old')) debug_new, rest_pkgs_new = cls._get_packages_for_abipkgdiff( results_store.get_build('new')) cmd = [cls.NAME] reports = {} for pkg in rest_pkgs_old: command = list(cmd) debug = cls._find_debuginfo(debug_old, pkg) if debug: command.append('--d1') command.append(debug) old_name = RpmHelper.split_nevra(os.path.basename(pkg))['name'] find = [ x for x in rest_pkgs_new if RpmHelper.split_nevra( os.path.basename(x))['name'] == old_name ] if not find: logger.warning('New version of package %s was not found!', old_name) continue new_pkg = find[0] debug = cls._find_debuginfo(debug_new, new_pkg) if debug: command.append('--d2') command.append(debug) command.append(pkg) command.append(new_pkg) logger.debug('Package name for ABI comparison %s', old_name) output = os.path.join(cls.results_dir, old_name + '.txt') try: ret_code = ProcessHelper.run_subprocess(command, output_file=output) except OSError: raise CheckerNotFoundError( "Checker '{}' was not found or installed.".format( cls.NAME)) if int(ret_code) & cls.ABIDIFF_ERROR and int( ret_code) & cls.ABIDIFF_USAGE_ERROR: raise RebaseHelperError( 'Execution of {} failed.\nCommand line is: {}'.format( cls.NAME, cmd)) reports[old_name] = int(ret_code) return dict(packages=cls.parse_abi_logs(reports), abi_changes=cls.abi_changes, path=cls.get_checker_output_dir_short())
def run_check(cls, results_dir): """ Compares old and new RPMs using pkgdiff :param results_dir result dir where are stored results """ cls.results_dir = results_dir cls.pkgdiff_results_full_path = os.path.join(cls.results_dir, cls.pkgdiff_results_filename) cmd = [cls.CMD] cmd.append('-hide-unchanged') for version in ['old', 'new']: old = results_store.get_build(version) if old: file_name = cls._create_xml(version, input_structure=old) cmd.append(file_name) cmd.append('-extra-info') cmd.append(cls.results_dir) cmd.append('-report-path') cmd.append(cls.pkgdiff_results_full_path) try: ret_code = ProcessHelper.run_subprocess(cmd, output=ProcessHelper.DEV_NULL) except OSError: raise CheckerNotFoundError("Checker '%s' was not found or installed." % cls.CMD) """ From pkgdiff source code: ret_code 0 means unchanged ret_code 1 means Changed other return codes means error """ if int(ret_code) != 0 and int(ret_code) != 1: raise RebaseHelperError('Execution of %s failed.\nCommand line is: %s' % (cls.CMD, cmd)) results_dict = cls.process_xml_results(cls.results_dir) lines = [] for key, val in six.iteritems(results_dict): if val: if lines: lines.append('') lines.append('Following files were %s:' % key) lines.extend(val) pkgdiff_report = os.path.join(cls.results_dir, 'report-' + cls.pkgdiff_results_filename + '.log') try: with open(pkgdiff_report, "w") as f: f.write('\n'.join(lines)) except IOError: raise RebaseHelperError("Unable to write result from %s to '%s'" % (cls.CMD, pkgdiff_report)) return {pkgdiff_report: None}
def run_check(cls, result_dir): """Compares old and new RPMs using abipkgdiff""" debug_old, rest_pkgs_old = cls._get_packages_for_abipkgdiff( results_store.get_build('old')) debug_new, rest_pkgs_new = cls._get_packages_for_abipkgdiff( results_store.get_build('new')) cmd = [cls.CMD] reports = {} for pkg in rest_pkgs_old: command = list(cmd) debug = cls._find_debuginfo(debug_old, pkg) if debug: command.append('--d1') command.append(debug) old_name = RpmHelper.split_nevra(os.path.basename(pkg))['name'] find = [ x for x in rest_pkgs_new if RpmHelper.split_nevra( os.path.basename(x))['name'] == old_name ] if not find: logger.warning('New version of package %s was not found!', old_name) continue new_pkg = find[0] debug = cls._find_debuginfo(debug_new, new_pkg) if debug: command.append('--d2') command.append(debug) command.append(pkg) command.append(new_pkg) logger.debug('Package name for ABI comparison %s', old_name) output = os.path.join(cls.results_dir, result_dir, old_name + '-' + cls.log_name) try: ret_code = ProcessHelper.run_subprocess(command, output=output) except OSError: raise CheckerNotFoundError( "Checker '%s' was not found or installed." % cls.CMD) if int(ret_code) & settings.ABIDIFF_ERROR and int( ret_code) & settings.ABIDIFF_USAGE_ERROR: raise RebaseHelperError( 'Execution of %s failed.\nCommand line is: %s' % (cls.CMD, cmd)) if int(ret_code) == 0: text = 'ABI of the compared binaries in package %s are equal.' % old_name else: text = 'ABI of the compared binaries in package %s are not equal.' % old_name reports[output] = text return reports
def run_check(cls, results_dir, **kwargs): """Compares old and new RPMs using abipkgdiff""" # Check if ABI changes occured cls.results_dir = os.path.join(results_dir, cls.name) cls.prepare_results_dir() debug_old, rest_pkgs_old = cls._get_packages_for_abipkgdiff(results_store.get_build('old')) debug_new, rest_pkgs_new = cls._get_packages_for_abipkgdiff(results_store.get_build('new')) ret_codes = {} for pkg in rest_pkgs_old: command = [cls.CMD] command_fallback = [cls.CMD] debug = cls._find_debuginfo(debug_old, pkg) if debug: command.append('--d1') command.append(debug) old_name = RpmHelper.split_nevra(os.path.basename(pkg))['name'] find = [x for x in rest_pkgs_new if RpmHelper.split_nevra(os.path.basename(x))['name'] == old_name] if not find: logger.warning('New version of package %s was not found!', old_name) continue new_pkg = find[0] debug = cls._find_debuginfo(debug_new, new_pkg) if debug: command.append('--d2') command.append(debug) command.extend([pkg, new_pkg]) command_fallback.extend([pkg, new_pkg]) logger.verbose('Package name for ABI comparison %s', old_name) output = os.path.join(cls.results_dir, old_name + '.txt') for cmd in [command, command_fallback]: try: ret_code = ProcessHelper.run_subprocess(cmd, output_file=output) except OSError as e: raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name)) from e if int(ret_code) & cls.ABIDIFF_ERROR and int(ret_code) & cls.ABIDIFF_USAGE_ERROR: raise RebaseHelperError( 'Execution of {} failed.\nCommand line is: {}'.format(cls.CMD, ' '.join(cmd))) if int(ret_code) & cls.ABIDIFF_ERROR: # abipkgdiff might not be able to read the debuginfo, try again without it continue break ret_codes[old_name] = int(ret_code) return dict(packages=cls.parse_abi_logs(ret_codes), abi_changes=any(x & cls.ABIDIFF_ABI_CHANGE for x in ret_codes.values()), abi_incompatible_changes=any(x & cls.ABIDIFF_ABI_INCOMPATIBLE_CHANGE for x in ret_codes.values()), path=cls.get_checker_output_dir_short(), ret_codes=ret_codes)
def run_rpminspect(cls, checker_dir: str, old_pkg: str, new_pkg: str) -> Tuple[str, Dict[str, int]]: """Runs rpminspect on the given package. Args: checker_dir: Path to the results directory of the checker old_pkg: Path to the old package. new_pkg: Path to the new package. Returns: Tuple of (path, data), where path is the path to rpminspect output and data is the dict of count of OK/BAD/VERIFY checks. """ cmd = [cls.CMD, '-F', 'json'] pkg_name = RpmHelper.split_nevra(os.path.basename(new_pkg))['name'] cmd.append(old_pkg) cmd.append(new_pkg) outfile = os.path.join(checker_dir, '{}.json'.format(pkg_name)) try: ret = ProcessHelper.run_subprocess(cmd, output_file=outfile, ignore_stderr=True) except OSError as e: raise CheckerNotFoundError( 'Checker \'{}\' was not found or installed.'.format( cls.name)) from e # Exit code 1 is used when bad check is found, 0 when everything is OK. Others on error if ret not in (0, 1): raise RebaseHelperError( 'An error occurred when running checker \'{}\''.format( cls.name)) with open(outfile, 'r', encoding=ENCODING) as json_file: data = json.load(json_file) return outfile, cls.process_data(data)