From 6a0d6dfc4f3490dc407c08d106d7740bb5d892e3 Mon Sep 17 00:00:00 2001 From: Tarik Zegmott Date: Thu, 20 Jun 2024 15:16:09 -0400 Subject: [PATCH] fix(cli): check minoc status --- dtcli/ps.py | 8 ++++++++ dtcli/pull.py | 13 ++++++++++--- dtcli/scout.py | 11 +++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dtcli/ps.py b/dtcli/ps.py index eb4cf1f..68e277d 100644 --- a/dtcli/ps.py +++ b/dtcli/ps.py @@ -66,6 +66,14 @@ def ps( except Exception as e: error_console.print(e) return None + + # Check Canfar status. + canfar_up = cadcclient.status() + if not canfar_up: + error_console.print( + "Either Minoc is down or certificate is invalid.", style="bold yellow" + ) + try: files, policies = functions.ps(scope, dataset, verbose, quiet) if isinstance(files, str) or isinstance(policies, str): diff --git a/dtcli/pull.py b/dtcli/pull.py index a487adb..724fec6 100644 --- a/dtcli/pull.py +++ b/dtcli/pull.py @@ -10,7 +10,7 @@ from dtcli.config import procure from dtcli.src.functions import find_missing_dataset_files, get_files -from dtcli.utilities.cadcclient import size +from dtcli.utilities import cadcclient from dtcli.utilities.utilities import set_log_level, validate_scope logger = logging.getLogger("pull") @@ -42,7 +42,7 @@ @click.option("-q", "--quiet", is_flag=True, help="Set log level to ERROR.") @click.option("--force", "-f", is_flag=True, help="Do not prompt for confirmation.") @click.pass_context -def pull( +def pull( # noqa: C901 ctx: click.Context, scope: str, dataset: str, @@ -97,6 +97,13 @@ def pull( error_console.print(e) return None + # Check Canfar status. + canfar_up = cadcclient.status() + if not canfar_up: + error_console.print( + "Either Minoc is down or certificate is invalid.", style="bold yellow" + ) + # Find files missing from localhost. console.print(f"\nSearching for files for {dataset} {scope}...\n") files = find_missing_dataset_files(scope, dataset, directory, verbose) @@ -111,7 +118,7 @@ def pull( if len(files_paths) > 0: common_path = path.commonpath(["/" + f for f in files_paths]) try: - to_download_size = size(common_path) + to_download_size = cadcclient.size(common_path) except SSLError: error_console.print( """ diff --git a/dtcli/scout.py b/dtcli/scout.py index 31133e7..168e55a 100644 --- a/dtcli/scout.py +++ b/dtcli/scout.py @@ -78,6 +78,13 @@ def scout( # noqa: C901 ) return {"error": "No config. Create one with `datatrail config init`."} + # Check Canfar status. + canfar_up = cadcclient.status() + if not canfar_up: + error_console.print( + "Either Minoc is down or certificate is invalid.", style="bold yellow" + ) + # Scout dataset. endpoint = ( f"/query/dataset/scout?name={dataset}" @@ -113,6 +120,10 @@ def scout( # noqa: C901 error_console.print("Query failed.") error_console.print(error) return None + except Exception as error: + error_console.print("Query failed.") + error_console.print(error) + return None data[scope]["observed"]["minoc"] = count keys_missing_in_observed = list(