Skip to content

Commit

Permalink
Add mount args to validate checkouts for vscode provided workspace fo…
Browse files Browse the repository at this point in the history
…lders

Summary:
We are extending the health-report command to accept mount paths as arguments in order so that can limit health-report to only checking the health of the passed in mounts (i.e. eden health-report --mounts ~/fbsource ~/opsfiles ~/configerator).

In this case vscode will provide th list of worspace folder paths that are checked out by the user  and run health-report only for those set of workpsace folders.

Reviewed By: jdelliot

Differential Revision: D66507034

fbshipit-source-id: 5abc637ce6a339df8da5a15fb03b67275c9a2038
  • Loading branch information
Vini Gupta authored and facebook-github-bot committed Nov 27, 2024
1 parent 668fd89 commit 0aecac4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
30 changes: 22 additions & 8 deletions eden/fs/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,15 @@ def description(self) -> str:
version_info: VersionInfo = VersionInfo()
error_codes: Dict[ErrorCode, str] = {}

def setup_parser(self, parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--mounts",
default=[],
nargs="*",
help="path of the mount points",
dest="mounts",
)

def is_eden_running(self, instance: EdenInstance) -> bool:
health_info = instance.check_health()
if not health_info.is_healthy():
Expand Down Expand Up @@ -1270,21 +1279,25 @@ def are_certs_valid(self) -> bool:
)
return False

def is_repo_mounted(self, instance: EdenInstance) -> bool:
def is_repo_mounted(self, instance: EdenInstance, mounts: List[str]) -> bool:
try:
checkouts_info = doctor_mod.get_checkouts_info(instance)
unmounted_repos = set()
for checkout in checkouts_info.values():
if checkout.state is None:
unmounted_repos.add(str(checkout.path))
if len(unmounted_repos) > 0:
unmounted_repos = {
str(checkout.path)
for path, checkout in checkouts_info.items()
if checkout.state is None and (not mounts or str(path) in mounts)
}

if unmounted_repos:
self.error_codes[HealthReportCmd.ErrorCode.NO_REPO_MOUNT_FOUND] = (
", ".join(unmounted_repos)
)
return False

return True
except Exception as ex:
print(f"Couldn't retrieve EdenFS checkouts info.: {ex}", file=sys.stderr)
return True
return True

@staticmethod
def print_error_codes_json(out: ui.Output) -> None:
Expand All @@ -1309,13 +1322,14 @@ def print_error_codes_json(out: ui.Output) -> None:

def run(self, args: argparse.Namespace) -> int:
instance = get_eden_instance(args)
mounts = args.mounts or []
out = ui.get_output()
exit_code = 0

try:
if (
not self.is_eden_running(instance)
or not self.is_repo_mounted(instance)
or not self.is_repo_mounted(instance, mounts)
or not all(
f()
for f in [
Expand Down
5 changes: 5 additions & 0 deletions eden/fs/cli/test/health_report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def setup(self) -> typing.Tuple[MagicMock, argparse.Namespace]:
home_dir="/home/johndoe",
mount=eden_path,
only_repo_source=True,
mounts=[
"/data/users/vinigupta/configerator_test",
"/data/users/vinigupta/fbsource_test",
"/data/users/vinigupta/opsfiles_test",
],
)
mock_argument_parser = MagicMock(spec=argparse.ArgumentParser)
return (mock_argument_parser, args)
Expand Down

0 comments on commit 0aecac4

Please sign in to comment.