def cure_what_ails_you( instance: EdenInstance, dry_run: bool, mount_table: mtab.MountTable, fs_util: filesystem.FsUtil, process_finder: process_finder.ProcessFinder, out: Optional[ui.Output] = None, ) -> int: if out is None: out = ui.get_output() if not dry_run: fixer = ProblemFixer(out) else: fixer = DryRunFixer(out) check_working_directory(fixer) # check OS type, kernel version etc. check_os.run_operating_system_checks(fixer, instance, out) # check multiple edenfs running with some rogue stale PIDs check_rogue_edenfs.check_many_edenfs_are_running(fixer, process_finder) status = instance.check_health() if status.status == fb_status.ALIVE: run_normal_checks(fixer, instance, out, mount_table, fs_util) elif status.status == fb_status.STARTING: fixer.add_problem(EdenfsStarting()) elif status.status == fb_status.STOPPING: fixer.add_problem(EdenfsStopping()) elif status.status == fb_status.DEAD: run_edenfs_not_healthy_checks(fixer, instance, out, status, mount_table, fs_util) if fixer.num_problems == 0: out.writeln("Eden is not in use.") return 0 else: fixer.add_problem(EdenfsUnexpectedStatus(status)) if fixer.num_problems == 0: out.writeln("No issues detected.", fg=out.GREEN) return 0 def problem_count(num: int) -> str: if num == 1: return "1 problem" return f"{num} problems" if dry_run: out.writeln( f"Discovered {problem_count(fixer.num_problems)} during --dry-run", fg=out.YELLOW, ) return 1 if fixer.num_fixed_problems: out.writeln( f"Successfully fixed {problem_count(fixer.num_fixed_problems)}.", fg=out.YELLOW, ) if fixer.num_failed_fixes: out.writeln(f"Failed to fix {problem_count(fixer.num_failed_fixes)}.", fg=out.RED) if fixer.num_manual_fixes: if fixer.num_manual_fixes == 1: msg = f"1 issue requires manual attention." else: msg = f"{fixer.num_manual_fixes} issues require manual attention." out.writeln(msg, fg=out.YELLOW) if fixer.num_fixed_problems == fixer.num_problems: return 0 out.write( "Ask in the Eden Users group if you need help fixing issues with Eden:\n" "https://fb.facebook.com/groups/eden.users/\n") return 1
def cure_what_ails_you( instance: EdenInstance, dry_run: bool, mount_table: mtab.MountTable, fs_util: filesystem.FsUtil, process_finder: process_finder.ProcessFinder, out: Optional[ui.Output] = None, ) -> int: if out is None: out = ui.get_output() if not dry_run: fixer = ProblemFixer(out) else: fixer = DryRunFixer(out) check_working_directory(fixer) # check OS type, kernel version etc. check_os.run_operating_system_checks(fixer, instance, out) # check multiple edenfs running with some rogue stale PIDs check_rogue_edenfs.check_many_edenfs_are_running(fixer, process_finder) status = instance.check_health() if status.status == fb_status.ALIVE: run_normal_checks(fixer, instance, out, mount_table, fs_util) elif status.status == fb_status.STARTING: fixer.add_problem(EdenfsStarting()) elif status.status == fb_status.STOPPING: fixer.add_problem(EdenfsStopping()) elif status.status == fb_status.DEAD: run_edenfs_not_healthy_checks( fixer, instance, out, status, mount_table, fs_util ) if fixer.num_problems == 0: out.writeln("Eden is not in use.") return 0 else: fixer.add_problem(EdenfsUnexpectedStatus(status)) if fixer.num_problems == 0: out.writeln("No issues detected.", fg=out.GREEN) return 0 def problem_count(num: int) -> str: if num == 1: return "1 problem" return f"{num} problems" if dry_run: out.writeln( f"Discovered {problem_count(fixer.num_problems)} during --dry-run", fg=out.YELLOW, ) return 1 if fixer.num_fixed_problems: out.writeln( f"Successfully fixed {problem_count(fixer.num_fixed_problems)}.", fg=out.YELLOW, ) if fixer.num_failed_fixes: out.writeln( f"Failed to fix {problem_count(fixer.num_failed_fixes)}.", fg=out.RED ) if fixer.num_manual_fixes: if fixer.num_manual_fixes == 1: msg = f"1 issue requires manual attention." else: msg = f"{fixer.num_manual_fixes} issues require manual attention." out.writeln(msg, fg=out.YELLOW) if fixer.num_fixed_problems == fixer.num_problems: return 0 out.write( "Ask in the Eden Users group if you need help fixing issues with Eden:\n" "https://fb.facebook.com/groups/eden.users/\n" ) return 1