def _save_packages(self, db, db_report, packages, count=1): for package in packages: role = "RELATED" if "package_role" in package: if package["package_role"] == "affected": role = "CRASHED" elif package["package_role"] == "selinux_policy": role = "SELINUX_POLICY" db_package = get_package_by_nevra(db, name=package["name"], epoch=package["epoch"], version=package["version"], release=package["release"], arch=package["architecture"]) if db_package is None: self.log_warn("Package {0}-{1}:{2}-{3}.{4} not found in " "storage".format(package["name"], package["epoch"], package["version"], package["release"], package["architecture"])) db_unknown_pkg = get_unknown_package(db, db_report, role, package["name"], package["epoch"], package["version"], package["release"], package["architecture"]) if db_unknown_pkg is None: db_arch = get_arch_by_name(db, package["architecture"]) if db_arch is None: continue db_unknown_pkg = ReportUnknownPackage() db_unknown_pkg.report = db_report db_unknown_pkg.name = package["name"] db_unknown_pkg.epoch = package["epoch"] db_unknown_pkg.version = package["version"] db_unknown_pkg.release = package["release"] db_unknown_pkg.arch = db_arch db_unknown_pkg.type = role db_unknown_pkg.count = 0 db.session.add(db_unknown_pkg) db_unknown_pkg.count += count continue db_reportpackage = get_reportpackage(db, db_report, db_package) if db_reportpackage is None: db_reportpackage = ReportPackage() db_reportpackage.report = db_report db_reportpackage.installed_package = db_package db_reportpackage.count = 0 db_reportpackage.type = role db.session.add(db_reportpackage) db_reportpackage.count += count
def _save_packages(self, db, db_report, packages, count=1): for package in packages: role = "RELATED" if "package_role" in package: if package["package_role"] == "affected": role = "CRASHED" elif package["package_role"] == "selinux_policy": role = "SELINUX_POLICY" db_package = get_package_by_nevra(db, name=package["name"], epoch=package["epoch"], version=package["version"], release=package["release"], arch=package["architecture"]) if db_package is None: self.log_warn("Package {0}-{1}:{2}-{3}.{4} not found in " "storage".format(package["name"], package["epoch"], package["version"], package["release"], package["architecture"])) db_unknown_pkg = get_unknown_package(db, db_report, role, package["name"], package["epoch"], package["version"], package["release"], package["architecture"]) if db_unknown_pkg is None: db_arch = get_arch_by_name(db, package["architecture"]) if db_arch is None: continue db_unknown_pkg = ReportUnknownPackage() db_unknown_pkg.report = db_report db_unknown_pkg.name = package["name"] db_unknown_pkg.epoch = package["epoch"] db_unknown_pkg.version = package["version"] db_unknown_pkg.release = package["release"] db_unknown_pkg.semver = to_semver(package["version"]) db_unknown_pkg.semrel = to_semver(package["release"]) db_unknown_pkg.arch = db_arch db_unknown_pkg.type = role db_unknown_pkg.count = 0 db.session.add(db_unknown_pkg) db_unknown_pkg.count += count continue db_reportpackage = get_reportpackage(db, db_report, db_package) if db_reportpackage is None: db_reportpackage = ReportPackage() db_reportpackage.report = db_report db_reportpackage.installed_package = db_package db_reportpackage.count = 0 db_reportpackage.type = role db.session.add(db_reportpackage) db_reportpackage.count += count
def run(self, cmdline, db): self.log_info("Querying reports with unknown packages...") reports_pkgs = get_packages_and_their_reports_unknown_packages(db) for (package_unknown_report, report_unknown_package) in reports_pkgs.yield_per(100): self.log_info("Found package {0} belonging to ReportUnknownPackage" " id {1}".format(str(package_unknown_report), report_unknown_package.id)) existing_report_package = get_reportpackage( db, report_unknown_package.report, package_unknown_report) if existing_report_package is not None: # Delete ReportUnknownPackage # if corresponding ReportPackage exists existing_report_package.count += report_unknown_package.count db.session.delete(report_unknown_package) db.session.flush() self.log_info("Existing ReportPackage found, " "ReportUnknownPackage deleted.") else: # Corresponding ReportPackage doesn't exist report_package = ReportPackage( report_id=report_unknown_package.report_id, type=report_unknown_package.type, installed_package_id=package_unknown_report.id, count=report_unknown_package.count) db.session.add(report_package) db.session.delete(report_unknown_package) db.session.flush() self.log_info("Created new ReportPackage, " "ReportUnknownPackage deleted.")
def run(self, cmdline, db) -> None: self.log_info("Querying reports with unknown packages...") reports_pkgs = get_packages_and_their_reports_unknown_packages(db) for (package_unknown_report, report_unknown_package) in reports_pkgs.yield_per(100): self.log_info("Found package {0} belonging to ReportUnknownPackage" " id {1}".format(str(package_unknown_report), report_unknown_package.id)) existing_report_package = get_reportpackage( db, report_unknown_package.report, package_unknown_report) if existing_report_package is not None: # Delete ReportUnknownPackage # if corresponding ReportPackage exists existing_report_package.count += report_unknown_package.count db.session.delete(report_unknown_package) db.session.flush() self.log_info("Existing ReportPackage found, " "ReportUnknownPackage deleted.") else: # Corresponding ReportPackage doesn't exist report_package = ReportPackage( report_id=report_unknown_package.report_id, type=report_unknown_package.type, installed_package_id=package_unknown_report.id, count=report_unknown_package.count) db.session.add(report_package) db.session.delete(report_unknown_package) db.session.flush() self.log_info("Created new ReportPackage, " "ReportUnknownPackage deleted.")