def test_store_rpm_deps(self): """ """ # add required stuff to db arch = Arch() arch.name = "noarch" self.db.session.add(arch) build = Build() build.base_package_name = "sample" build.version = "1" build.release = "1" build.epoch = "0" self.db.session.add(build) pkg = Package() pkg.name = "sample" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) self.db.session.flush() # save sample rpm sample_rpm = glob.glob("sample_rpms/sample*.rpm")[0] with open(sample_rpm, mode='rb') as sample: pkg.save_lob("package", sample, truncate=True) # get dependencies res = store_rpm_deps(self.db, pkg, nogpgcheck=True) self.assertIs(res, True) expected_deps = [ ("PROVIDES", "sample", 8), ("PROVIDES", "/sample", 0), ("PROVIDES", "nothing-new", 0), ( "REQUIRES", "nothing", 0, ), ( "CONFLICTS", "surprisingly-nothing", 0, ), ] found_deps = [] for dep in self.db.session.query(PackageDependency).all(): found_deps.append((dep.type, dep.name, dep.flags)) for dep in expected_deps: self.assertIn(dep, found_deps)
def test_yield_query_adaptor(self): """ Checks if YieldQueryAdaptor implements the claimed interface and the implementation is sane. """ a_ia32 = Arch() a_ia32.name = "i386" a_amd64 = Arch() a_amd64.name = "x86_64" a_noarch = Arch() a_noarch.name = "noarch" self.db.session.add(a_ia32) self.db.session.add(a_amd64) self.db.session.add(a_noarch) self.db.session.flush() q = self.db.session.query(Arch) yqa = YieldQueryAdaptor(q, 1) self.assertEqual(len(yqa), 3) self.assertEqual([arch for arch in yqa], [a_ia32, a_amd64, a_noarch])
def run(self, cmdline, db): for archname in cmdline.NAME: arch = get_arch_by_name(db, archname) if arch: self.log_error("Architecture '{0}' already defined" .format(archname)) return 1 self.log_info("Adding architecture '{0}'".format(archname)) new = Arch() new.name = archname db.session.add(new) db.session.flush()
def run(self, cmdline, db): for archname in cmdline.NAME: arch = get_arch_by_name(db, archname) if arch: self.log_error( "Architecture '{0}' already defined".format(archname)) return 1 self.log_info("Adding architecture '{0}'".format(archname)) new = Arch() new.name = archname db.session.add(new) db.session.flush()
def basic_fixtures(self, flush=True): """ Add Arch, OpSys, OpSysRelease and OpSysComponent fixtures Store as self.arch_noarch, self_opsys_fedora, self.release_19, self.comp_kernel, ... """ for arch_name in Init.archs: arch = Arch(name=arch_name) self.db.session.add(arch) setattr(self, "arch_{0}".format(arch_name), arch) centos_sys = OpSys(name="CentOS") self.db.session.add(centos_sys) self.opsys_centos = centos_sys releases = [] versions = ["6.7", "6.8", "7.1", "7.2", "7.3", "7.7"] for ver in versions: rel = OpSysRelease(opsys=centos_sys, version=ver, status="ACTIVE") releases.append(rel) self.db.session.add(rel) setattr(self, "release_{0}".format(ver), rel) sys = OpSys(name="Fedora") self.db.session.add(sys) self.opsys_fedora = sys releases = [] for ver in range(17, 21): rel = OpSysRelease(opsys=sys, version=ver, status="ACTIVE") releases.append(rel) self.db.session.add(rel) setattr(self, "release_{0}".format(ver), rel) for cname in [ "faf", "systemd", "kernel", "ibus-table", "eclipse", "will-crash", "ibus-table-ruby", "xorg-x11-drv-nouveau" ]: comp = OpSysComponent(opsys=sys, name=cname) self.db.session.add(comp) comp = OpSysComponent(opsys=centos_sys, name=cname) self.db.session.add(comp) setattr(self, "comp_{0}".format(cname), comp) for rel in releases: rcomp = OpSysReleaseComponent(release=rel, component=comp) self.db.session.add(rcomp) if flush: self.db.session.flush()
def arches(self): self.begin('Arches') for arch in data.ARCH: self.add(Arch(name=arch)) self.commit()
def test_store_rpm_deps(self): """ """ # add required stuff to db arch = Arch() arch.name = "noarch" self.db.session.add(arch) build = Build() build.base_package_name = "sample" build.version = "1" build.release = "1" build.epoch = "0" self.db.session.add(build) pkg = Package() pkg.name = "sample" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) self.db.session.flush() # save sample rpm with open("sample_rpms/sample-1.0-1.fc18.noarch.rpm", mode='rb') as sample: pkg.save_lob("package", sample, truncate=True) # get dependencies store_rpm_deps(self.db, pkg, nogpgcheck=True) expected_deps = [ ("PROVIDES", "sample", 8), ("PROVIDES", "/sample", 0), ("PROVIDES", "nothing-new", 0), ( "REQUIRES", "nothing", 0, ), ( "CONFLICTS", "surprisingly-nothing", 0, ), ] found_deps = [] for dep in self.db.session.query(PackageDependency).all(): found_deps.append((dep.type, dep.name, dep.flags)) for dep in expected_deps: self.assertIn(dep, found_deps) build = Build() build.base_package_name = "sample-broken" build.version = "1" build.release = "1" build.epoch = 0 self.db.session.add(build) pkg = Package() pkg.name = "sample-broken" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) self.db.session.flush() with open("sample_rpms/sample-broken-1-1.el7.noarch.rpm", mode='rb') as sample: pkg.save_lob("package", sample, truncate=True) with self.assertRaises(FafError): store_rpm_deps(self.db, pkg, nogpgcheck=True) # Safety flush self.db.session.flush() query = self.db.session.query(PackageDependency) # Filter out rich RPM dependencies dependencies = filter(lambda x: "rpmlib" not in x.name, query.all()) # The transaction was rolled back and nothing new was added self.assertCountEqual( map(lambda x: (x.type, x.name, x.flags), dependencies), expected_deps)
def test_get_packages_and_their_reports_unknown_packages(self): """ """ # add required stuff to db arch = Arch() arch.name = "noarch" self.db.session.add(arch) arch1 = Arch() arch1.name = "x86_64" self.db.session.add(arch1) build = Build() build.base_package_name = "sample" build.version = "1" build.release = "1" build.epoch = "0" self.db.session.add(build) pkg = Package() pkg.name = "sample" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) #print(pkg.nevra()) #different arch pkg2 = Package() pkg2.name = "sample" pkg2.pkgtype = "rpm" pkg2.arch = arch1 pkg2.build = build self.db.session.add(pkg2) #print(pkg2.nevra()) build2 = Build() build2.base_package_name = "sample" build2.version = "1" build2.release = "2" build2.epoch = "0" self.db.session.add(build2) pkg3 = Package() pkg3.name = "sample" pkg3.pkgtype = "rpm" pkg3.arch = arch pkg3.build = build2 self.db.session.add(pkg3) #print(pkg3.nevra()) problem = Problem() self.db.session.add(problem) opsys = OpSys() opsys.name = "Fedora" self.db.session.add(opsys) opsys_component = OpSysComponent() opsys_component.name = "core" opsys_component.opsys = opsys self.db.session.add(opsys_component) report = Report() report.type = "type" report.count = 2 report.problem = problem report.component = opsys_component self.db.session.add(report) report_unknown = ReportUnknownPackage() report_unknown.report = report report_unknown.name = pkg.name report_unknown.epoch = pkg.build.epoch report_unknown.version = pkg.build.version report_unknown.release = pkg.build.release report_unknown.arch = pkg.arch report_unknown.count = 1 self.db.session.add(report_unknown) report_unknown2 = ReportUnknownPackage() report_unknown2.report = report report_unknown2.name = pkg2.name report_unknown2.epoch = pkg2.build.epoch report_unknown2.version = pkg2.build.version report_unknown2.release = pkg2.build.release report_unknown2.arch = pkg2.arch report_unknown2.count = 1 self.db.session.add(report_unknown2) report_unknown3 = ReportUnknownPackage() report_unknown3.report = report report_unknown3.name = "nonsense" report_unknown3.epoch = pkg.build.epoch report_unknown3.version = pkg.build.version report_unknown3.release = pkg.build.release report_unknown3.arch = pkg.arch report_unknown3.count = 1 self.db.session.add(report_unknown3) self.db.session.flush() packages_and_their_reports_unknown_packages = \ get_packages_and_their_reports_unknown_packages(self.db).all() self.assertEqual(len(packages_and_their_reports_unknown_packages), 2) self.assertIn((pkg, report_unknown), packages_and_their_reports_unknown_packages) self.assertIn((pkg2, report_unknown2), packages_and_their_reports_unknown_packages)
def test_get_packages_and_their_reports_unknown_packages(self): """ """ # add required stuff to db arch = Arch() arch.name = "noarch" self.db.session.add(arch) arch1 = Arch() arch1.name = "x86_64" self.db.session.add(arch1) build = Build() build.base_package_name = "sample" build.version = "1" build.release = "1" build.epoch = "0" self.db.session.add(build) pkg = Package() pkg.name = "sample" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) #print(pkg.nevra()) #different arch pkg2 = Package() pkg2.name = "sample" pkg2.pkgtype = "rpm" pkg2.arch = arch1 pkg2.build = build self.db.session.add(pkg2) #print(pkg2.nevra()) build2 = Build() build2.base_package_name = "sample" build2.version = "1" build2.release = "2" build2.epoch = "0" self.db.session.add(build2) pkg3 = Package() pkg3.name = "sample" pkg3.pkgtype = "rpm" pkg3.arch = arch pkg3.build = build2 self.db.session.add(pkg3) #print(pkg3.nevra()) problem = Problem() self.db.session.add(problem) opsys = OpSys() opsys.name = "Fedora" self.db.session.add(opsys) opsys_component = OpSysComponent() opsys_component.name = "core" opsys_component.opsys = opsys self.db.session.add(opsys_component) report = Report() report.type = "type" report.count = 2 report.problem = problem report.component = opsys_component self.db.session.add(report) report_unknown = ReportUnknownPackage() report_unknown.report = report report_unknown.name = pkg.name report_unknown.epoch = pkg.build.epoch report_unknown.version = pkg.build.version report_unknown.release = pkg.build.release report_unknown.arch = pkg.arch report_unknown.count = 1 self.db.session.add(report_unknown) report_unknown2 = ReportUnknownPackage() report_unknown2.report = report report_unknown2.name = pkg2.name report_unknown2.epoch = pkg2.build.epoch report_unknown2.version = pkg2.build.version report_unknown2.release = pkg2.build.release report_unknown2.arch = pkg2.arch report_unknown2.count = 1 self.db.session.add(report_unknown2) report_unknown3 = ReportUnknownPackage() report_unknown3.report = report report_unknown3.name = "nonsense" report_unknown3.epoch = pkg.build.epoch report_unknown3.version = pkg.build.version report_unknown3.release = pkg.build.release report_unknown3.arch = pkg.arch report_unknown3.count = 1 self.db.session.add(report_unknown3) self.db.session.flush() packages_and_their_reports_unknown_packages = \ get_packages_and_their_reports_unknown_packages(self.db).all() self.assertEqual(len(packages_and_their_reports_unknown_packages), 2) self.assertIn( (pkg, report_unknown), packages_and_their_reports_unknown_packages) self.assertIn( (pkg2, report_unknown2), packages_and_their_reports_unknown_packages)
def test_store_rpm_provides(self): """ """ # add required stuff to db arch = Arch() arch.name = "noarch" self.db.session.add(arch) build = Build() build.base_package_name = "sample" build.version = "1" build.release = "1" build.epoch = "0" self.db.session.add(build) pkg = Package() pkg.name = "sample" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) self.db.session.flush() # save sample rpm with open("sample_rpms/sample-1.0-1.fc18.noarch.rpm", mode='rb') as sample: pkg.save_lob("package", sample, truncate=True) # get dependencies store_rpm_provides(self.db, pkg, nogpgcheck=True) expected_deps = [ ("PROVIDES", "sample", 8), ("PROVIDES", "/sample", 0), ("PROVIDES", "nothing-new", 0), ] found_deps = [] for dep in self.db.session.query(PackageDependency).all(): found_deps.append((dep.type, dep.name, dep.flags)) self.assertCountEqual(found_deps, expected_deps) build = Build() build.base_package_name = "sample-broken" build.version = "1" build.release = "1" build.epoch = 0 self.db.session.add(build) pkg = Package() pkg.name = "sample-broken" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) self.db.session.flush() with open("sample_rpms/sample-broken-1-1.fc22.noarch.rpm", mode='rb') as rpm_file: pkg.save_lob("package", rpm_file, truncate=True) with self.assertLogs(level=logging.WARNING) as captured_logs: store_rpm_provides(self.db, pkg, nogpgcheck=True) self.assertEqual(captured_logs.output, [ "WARNING:faf.pyfaf.faf_rpm:Unparsable EVR ‘%{epoch}:1’ of " "zabbix in Provides of sample-broken: EVR string " "contains a non-numeric epoch: %{epoch}. Skipping" ]) # Safety flush self.db.session.flush() query = self.db.session.query(PackageDependency) # Filter out rich RPM dependencies dependencies = filter(lambda x: "rpmlib" not in x.name, query.all()) # Only provides that were correctly formatted were added expected_deps.extend([ ("PROVIDES", "sample-broken", 8), ("PROVIDES", "happiness", 0), ("PROVIDES", "joy", 0), ("PROVIDES", "love", 0), ]) self.assertCountEqual( ((x.type, x.name, x.flags) for x in dependencies), expected_deps) build = Build() build.base_package_name = "sample-provides-too-long" build.version = "1" build.release = "1" build.epoch = 0 self.db.session.add(build) pkg = Package() pkg.name = "sample-provides-too-long" pkg.pkgtype = "rpm" pkg.arch = arch pkg.build = build self.db.session.add(pkg) self.db.session.flush() with open("sample_rpms/sample-provides-too-long-1-1.fc33.noarch.rpm", mode='rb') as rpm_file: pkg.save_lob("package", rpm_file, truncate=True) with self.assertLogs(level=logging.WARNING) as captured_logs: store_rpm_provides(self.db, pkg, nogpgcheck=True) self.assertEqual(captured_logs.output, [ "WARNING:faf.pyfaf.faf_rpm:Provides item in RPM header of " "sample-provides-too-long longer than 1024 characters. " "Skipping" ]) # Safety flush self.db.session.flush() query = self.db.session.query(PackageDependency) # Filter out rich RPM dependencies dependencies = filter(lambda x: "rpmlib" not in x.name, query.all()) # Only provides that were correctly formatted were added expected_deps.extend([ ("PROVIDES", "sample-provides-too-long", 8), ("PROVIDES", "one-thing", 0), ("PROVIDES", "another-thing", 0), ("PROVIDES", "penultimate-item", 0), ("PROVIDES", "the-last-one", 0), ]) self.assertCountEqual( ((x.type, x.name, x.flags) for x in dependencies), expected_deps)