in dcrpm/dcrpm.py [0:0]
def run(self):
# type: () -> bool
if not self.has_free_disk_space():
self.status_logger.error("not_enough_disk")
self.logger.error("Need at least %sB free to continue" % self.args.minspace)
return False
# Check old yum transactions.
if self.args.clean_yum_transactions and self.stale_yum_transactions_exist():
self.logger.info("Cleaning old yum transaction")
self.rpmutil.clean_yum_transactions()
# Check stuck yum.
if self.args.check_stuck_yum:
result = Yum().check_stuck(dry_run=self.args.dry_run)
if not result:
self.logger.error("Failed to unstuck yum processes")
# Detect database backend
backend = self.rpmutil.get_db_backend()
# Start main checks.
for i in range(self.args.max_passes):
self.logger.debug("Running pass: %d", i)
try:
# Optional forensic data collection
if self.args.forensic:
if backend == "bdb":
self.logger.info(
"Running forensic data collection (db_stat -CA)"
)
self.rpmutil.db_stat()
else:
self.logger.warning(
"Forensics data collection is not supported on %s" % backend
)
# Kill any straggler rpm query processes
self.logger.info("Searching for spinning rpm query processes")
self.rpmutil.kill_spinning_rpm_query_processes()
# Exercise single indexes
self.logger.info("Sanity checking rpmdb indexes")
self.rpmutil.check_rpmdb_indexes()
self.logger.info("Rpmdb indexes OK")
# Black box check - does rpm -qa even work?
self.logger.info("Running black box check (rpm -qa)")
self.rpmutil.check_rpm_qa()
self.logger.info("Black box check OK")
if self.args.dbpath == "/var/lib/rpm":
if self.args.run_yum_check:
self.logger.info("Running yum check")
Yum().run_yum_check()
self.logger.info("Yum check ok")
if self.args.run_yum_clean and not self.args.run_yum_check:
self.logger.info("Running yum clean expire-cache")
Yum().run_yum_clean()
self.logger.info("Yum clean ok")
else:
self.logger.info(
"Skipping yum sanity checks because "
"custom dbpath has been provided"
)
self.logger.info("Running silent corruption check (rpm -q)")
self.rpmutil.query("coreutils")
self.logger.info("Silent corruption check OK")
# Check tables (mismatch for -qa vs. -q).
self.logger.info(
"Running table checks (attempting to query each package)"
)
self.rpmutil.check_tables()
self.logger.info("Table checks OK")
# Verify tables (db_verify for each file).
if backend == "bdb":
self.logger.info("Verifying each table in %s", self.args.dbpath)
if not self.call_verify_tables():
continue
else:
self.logger.warning(
"Table verification is not implemented for %s" % backend
)
# Need to run db_recover.
except DBNeedsRecovery:
self.logger.error("DB needs recovery")
try:
if backend == "bdb":
self.run_recovery()
else:
self.logger.warning(
"Recovery is not implemented for %s" % backend
)
self.rpmutil.check_rpmdb_indexes()
continue
except (DBNeedsRebuild, DBNeedsRecovery):
self.logger.error("DB needs rebuild")
self.run_rebuild()
continue
# Need to run rpm --rebuilddb.
except DBNeedsRebuild:
self.logger.error("DB needs rebuild")
self.run_rebuild()
continue
# Everything else.
except DcRPMException as e:
self.logger.warning("Got other exception: %s", e)
continue
# All's well - return early!
self.logger.info("Ran a pass without detecting any problems. Exiting.")
return True
# Ran out of attempts.
self.status_logger.error("")
self.logger.error("Unable to repair RPM database")
return False