Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def run_check(cls, results_dir, **kwargs):
        cls.results_dir = os.path.join(results_dir, 'rpminspect-rpm')
        cls.prepare_results_dir()

        result = {
            'path': cls.get_checker_output_dir_short(),
            'files': [],
            'checks': {}
        }
        old_pkgs = results_store.get_old_build()['rpm']
        new_pkgs = results_store.get_new_build()['rpm']
        for old_pkg in old_pkgs:
            if 'debuginfo' in old_pkg:
                continue
            name = RpmHelper.split_nevra(os.path.basename(old_pkg))['name']
            found = [
                x for x in new_pkgs
                if RpmHelper.split_nevra(os.path.basename(x))['name'] == name
            ]
            if not found:
                logger.warning('New version of package %s was not found!',
                               name)
                continue
            new_pkg = found[0]
            outfile, pkg_data = cls.run_rpminspect(cls.results_dir, old_pkg,
                                                   new_pkg)
            result['files'].append(os.path.basename(outfile))
            result['checks'][name] = pkg_data

        return result
Ejemplo n.º 3
0
    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)
        results_dir = os.path.join(results_dir, cls.CMD)
        os.makedirs(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:
                raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name))
        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
Ejemplo n.º 4
0
    def fill_dictionary(cls, result_dir, old_version=None, new_version=None):
        """
        Parsed files.xml and symbols.xml and fill dictionary
        :param result_dir: where should be stored file for pkgdiff
        :param old_version: old version of package
        :param new_version: new version of package
        :return:
        """
        XML_FILES = ['files.xml', 'symbols.xml']
        if old_version is None:
            old_version = results_store.get_old_build().get('version')
            if old_version is '':
                old_version = cls._get_rpm_info(
                    'version',
                    results_store.get_old_build()['rpm'])
        if new_version is None:
            new_version = results_store.get_new_build().get('version')
            if new_version is '':
                new_version = cls._get_rpm_info(
                    'version',
                    results_store.get_new_build()['rpm'])

        for tag in cls.CHECKER_TAGS:
            cls.results_dict[tag] = []
        for file_name in [os.path.join(result_dir, x) for x in XML_FILES]:
            logger.verbose('Processing %s file.', file_name)
            try:
                with open(file_name, "r") as f:
                    lines = ['<pkgdiff>']
                    lines.extend(f.readlines())
                    lines.append('</pkgdiff>')
                    pkgdiff_tree = ElementTree.fromstringlist(lines)
                    for tag in cls.CHECKER_TAGS:
                        for pkgdiff in pkgdiff_tree.findall('.//' + tag):
                            files = [
                                x.strip()
                                for x in pkgdiff.text.strip().split('\n')
                            ]
                            files = [
                                x.replace(old_version, '*') for x in files
                            ]
                            files = [
                                x.replace(new_version, '*') for x in files
                            ]
                            cls.results_dict[tag].extend(files)
            except IOError:
                continue
Ejemplo n.º 5
0
    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}
Ejemplo n.º 6
0
    def run_check(cls, results_dir, **kwargs):
        """Compares old and new RPMs using rpmdiff"""
        results_dict = {}

        for tag in cls.CHECKER_TAGS:
            results_dict[tag] = []

        cls.results_dir = os.path.join(results_dir, cls.name)
        os.makedirs(cls.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(['-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 = io.StringIO()
            try:
                ProcessHelper.run_subprocess(cmd, output_file=output)
            except OSError:
                raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name))
            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 = []
        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") as f:
                f.write('\n'.join(lines))
        except IOError:
            raise RebaseHelperError("Unable to write result from {} to '{}'".format(cls.name, rpmdiff_report))

        return {'path': cls.get_checker_output_dir_short(), 'files_changes': counts}
Ejemplo n.º 7
0
    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}
Ejemplo n.º 8
0
    def print_cli_summary(cls, app):
        """
        Print report of the rebase

        :param app: Application instance
        """
        cls.app = app
        cls.print_patches_cli()
        result = results_store.get_result_message()

        cls.print_important_checkers_output()

        logger_output.heading('\nAvailable logs:')
        logger_output.info(
            '%s:\n%s', 'Debug log',
            cls.prepend_results_dir_name(
                os.path.relpath(app.debug_log_file, app.results_dir)))
        if results_store.get_old_build() is not None:
            logger_output.info('%s:\n%s', 'Old build logs and (S)RPMs',
                               cls.prepend_results_dir_name('old-build'))
        if results_store.get_new_build() is not None:
            logger_output.info('%s:\n%s', 'New build logs and (S)RPMs',
                               cls.prepend_results_dir_name('new-build'))
        logger_output.info('')

        logger_output.heading('%s:', 'Rebased sources')
        logger_output.info(
            "%s",
            cls.prepend_results_dir_name(
                os.path.relpath(app.rebased_sources_dir, app.results_dir)))

        patch = results_store.get_changes_patch()
        if 'changes_patch' in patch:
            logger_output.heading('%s:', 'Generated patch')
            logger_output.info(
                "%s\n",
                cls.prepend_results_dir_name(
                    os.path.basename(patch['changes_patch'])))

        cls.print_report_file_path()

        if not app.conf.patch_only:
            if 'success' in result:
                logger_output.success('\n%s' % result['success'])
            # Error is printed out through exception caught in CliHelper.run()
        else:
            if results_store.get_patches()['success']:
                logger_output.success("\nPatching successful")
            elif results_store.get_patches()['success']:
                logger_output.error("\nPatching failed")
Ejemplo n.º 9
0
    def fill_dictionary(cls, result_dir, old_version=None, new_version=None):
        """
        Parsed files.xml and symbols.xml and fill dictionary
        :param result_dir: where should be stored file for pkgdiff
        :param old_version: old version of package
        :param new_version: new version of package
        :return:
        """
        XML_FILES = ['files.xml', 'symbols.xml']
        if old_version is None:
            old_version = results_store.get_old_build().get('version')
            if old_version is '':
                old_version = cls._get_rpm_info('version', results_store.get_old_build()['rpm'])
        if new_version is None:
            new_version = results_store.get_new_build().get('version')
            if new_version is '':
                new_version = cls._get_rpm_info('version', results_store.get_new_build()['rpm'])

        for tag in cls.CHECKER_TAGS:
            cls.results_dict[tag] = []
        for file_name in [os.path.join(result_dir, x) for x in XML_FILES]:
            logger.verbose('Processing %s file.', file_name)
            try:
                with open(file_name, "r") as f:
                    lines = ['<pkgdiff>']
                    lines.extend(f.readlines())
                    lines.append('</pkgdiff>')
                    pkgdiff_tree = ElementTree.fromstringlist(lines)
                    for tag in cls.CHECKER_TAGS:
                        for pkgdiff in pkgdiff_tree.findall('.//' + tag):
                            files = [x.strip() for x in pkgdiff.text.strip().split('\n')]
                            files = [x.replace(old_version, '*') for x in files]
                            files = [x.replace(new_version, '*') for x in files]
                            cls.results_dict[tag].extend(files)
            except IOError:
                continue
Ejemplo n.º 10
0
    def print_cli_summary(cls, app):
        """Outputs a summary of a rebase-helper run.

        Args:
            app: Application instance.
        """
        cls.print_patches_cli()
        result = results_store.get_result_message()

        cls.print_important_checkers_output()

        logger_summary.heading('\nAvailable logs:')
        logger_summary.info(
            '%s:\n%s', 'Debug log',
            cls.prepend_results_dir_name(app,
                                         os.path.join(LOGS_DIR, DEBUG_LOG)))
        if results_store.get_old_build() is not None:
            logger_summary.info(
                '%s:\n%s', 'Old build logs and (S)RPMs',
                cls.prepend_results_dir_name(app, OLD_BUILD_DIR))
        if results_store.get_new_build() is not None:
            logger_summary.info(
                '%s:\n%s', 'New build logs and (S)RPMs',
                cls.prepend_results_dir_name(app, NEW_BUILD_DIR))
        logger_summary.info('')

        logger_summary.heading('%s:', 'Rebased sources')
        logger_summary.info(
            "%s",
            cls.prepend_results_dir_name(
                app, os.path.relpath(app.rebased_sources_dir,
                                     app.results_dir)))

        patch = results_store.get_changes_patch()
        if 'changes_patch' in patch:
            logger_summary.heading('%s:', 'Generated patch')
            logger_summary.info(
                "%s\n",
                cls.prepend_results_dir_name(
                    app, os.path.basename(patch['changes_patch'])))

        cls.print_report_file_path(app)

        if 'success' in result:
            logger_summary.success('\n%s', result['success'])
Ejemplo n.º 11
0
    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):
            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
            cmd.append(new_pkgs[key])
            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}
Ejemplo n.º 12
0
    def run_check(cls, results_dir, **kwargs):
        cls.results_dir = os.path.join(results_dir, 'rpminspect-srpm')
        cls.prepare_results_dir()

        result = {
            'path': cls.get_checker_output_dir_short(),
            'files': [],
            'checks': {}
        }
        old_pkg = results_store.get_old_build()['srpm']
        new_pkg = results_store.get_new_build()['srpm']
        name = RpmHelper.split_nevra(os.path.basename(old_pkg))['name']
        outfile, pkg_data = cls.run_rpminspect(cls.results_dir, old_pkg,
                                               new_pkg)
        result['files'].append(os.path.basename(outfile))
        result['checks'][name] = pkg_data

        return result
Ejemplo n.º 13
0
    def run_check(cls, results_dir, **kwargs):
        old_headers = [
            RpmHelper.get_header_from_rpm(x)
            for x in results_store.get_old_build().get('rpm', [])
        ]
        new_headers = [
            RpmHelper.get_header_from_rpm(x)
            for x in results_store.get_new_build().get('rpm', [])
        ]
        soname_changes: SonameChanges = collections.defaultdict(
            lambda: collections.defaultdict(list))
        for old in old_headers:
            new = [x for x in new_headers if x.name == old.name]
            if not new:
                logger.warning('New version of package %s was not found!',
                               old.name)
                continue
            else:
                new = new[0]
            old_sonames = cls._get_sonames(old.provides)
            new_sonames = cls._get_sonames(new.provides)
            for old_soname in old_sonames:
                if old_soname in new_sonames:
                    new_sonames.remove(old_soname)
                    continue
                soname = [
                    x for x in new_sonames if os.path.splitext(x)[0] ==
                    os.path.splitext(old_soname)[0]
                ]
                if not soname:
                    soname_changes[old.name]['removed'].append(old_soname)
                else:
                    soname_changes[old.name]['changed'].append({
                        'from': old_soname,
                        'to': soname[0]
                    })
                    new_sonames.remove(soname[0])

            if new_sonames:
                soname_changes[old.name]['added'] = list(new_sonames)

        return dict(soname_changes=soname_changes)
Ejemplo n.º 14
0
    def print_cli_summary(cls, app):
        """
        Print report of the rebase

        :param app: Application instance
        """
        cls.app = app
        cls.print_patches_cli()
        result = results_store.get_result_message()

        cls.print_important_checkers_output()

        logger_output.heading('\nAvailable logs:')
        logger_output.info('%s:\n%s', 'Debug log', cls.prepend_results_dir_name(app.debug_log_file))
        if results_store.get_old_build() is not None:
            logger_output.info('%s:\n%s', 'Old build logs and (S)RPMs', cls.prepend_results_dir_name('old-build'))
        if results_store.get_new_build() is not None:
            logger_output.info('%s:\n%s', 'New build logs and (S)RPMs', cls.prepend_results_dir_name('new-build'))
        logger_output.info('')

        logger_output.heading('%s:', 'Rebased sources')
        logger_output.info("%s", cls.prepend_results_dir_name(os.path.relpath(app.rebased_sources_dir,
                                                                              app.results_dir)))

        patch = results_store.get_changes_patch()
        if 'changes_patch' in patch:
            logger_output.heading('%s:', 'Generated patch')
            logger_output.info("%s\n", cls.prepend_results_dir_name(os.path.basename(patch['changes_patch'])))

        cls.print_report_file_path()

        if not app.conf.patch_only:
            if 'success' in result:
                logger_output.success('\n%s', result['success'])
            # Error is printed out through exception caught in CliHelper.run()
        else:
            if results_store.get_patches()['success']:
                logger_output.success("\nPatching successful")
            elif results_store.get_patches()['success']:
                logger_output.error("\nPatching failed")
Ejemplo n.º 15
0
    def print_cli_summary(cls, app):
        """
        Print report of the rebase

        :param app: Application instance
        """
        cls.app = app
        cls.print_patches_cli()

        ConsoleHelper.cprint('\nAvailable logs:', color='yellow')
        print('{0}:\n{1}'.format('Debug log', app.debug_log_file))
        if results_store.get_old_build() is not None:
            print('{0}:\n{1}'.format(
                'Old build logs and (S)RPMs',
                os.path.join(app.results_dir, 'old-build')))
        if results_store.get_new_build() is not None:
            print('{0}:\n{1}'.format(
                'New build logs and (S)RPMs',
                os.path.join(app.results_dir, 'new-build')))
        print('')

        ConsoleHelper.cprint('%s:' % 'Rebased sources', color='yellow')
        print("%s" % app.rebased_sources_dir)

        ConsoleHelper.cprint('%s:' % 'Generated patch', color='yellow')
        print("%s\n" % os.path.join(app.results_dir, 'changes.patch'))

        cls.print_report_file_path()

        result = results_store.get_result_message()

        if not app.conf.patch_only:
            if 'success' in result:
                ConsoleHelper.cprint('\n%s' % result['success'], color='green')
            # Error is printed out through exception caught in CliHelper.run()
        else:
            if results_store.get_patches()['success']:
                ConsoleHelper.cprint("\nPatching successful", color='green')
            elif results_store.get_patches()['success']:
                ConsoleHelper.cprint("\nPatching failed", color='red')