Skip to content

Commit b229549

Browse files
authored
Merge pull request #99 from CHIMEFRB/98-bug-pull-failing-to-calculate-size-at-canfar-shouldnt-stop-users-pulling-data
fix(cli): check for luskan status
2 parents a5a1963 + 405a3c2 commit b229549

4 files changed

Lines changed: 58 additions & 28 deletions

File tree

dtcli/ps.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ def ps(
6868
return None
6969

7070
# Check Canfar status.
71-
canfar_up = cadcclient.status()
72-
if not canfar_up:
71+
minoc_up, luskan_up = cadcclient.status()
72+
if not minoc_up:
7373
error_console.print(
7474
"Either Minoc is down or certificate is invalid.", style="bold yellow"
7575
)
76+
elif not luskan_up:
77+
error_console.print(
78+
"Either Luskan is down or certificate is invalid.", style="bold yellow"
79+
)
7680

7781
try:
7882
files, policies = functions.ps(scope, dataset, verbose, quiet)

dtcli/pull.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ def pull( # noqa: C901
9898
return None
9999

100100
# Check Canfar status.
101-
canfar_up = cadcclient.status()
102-
if not canfar_up:
101+
minoc_up, luskan_up = cadcclient.status()
102+
if not minoc_up:
103103
error_console.print(
104104
"Either Minoc is down or certificate is invalid.", style="bold yellow"
105105
)
106+
elif not luskan_up:
107+
error_console.print(
108+
"Either Luskan is down or certificate is invalid.", style="bold yellow"
109+
)
106110

107111
# Find files missing from localhost.
108112
console.print(f"\nSearching for files for {dataset} {scope}...\n")
@@ -114,8 +118,7 @@ def pull( # noqa: C901
114118
console.print("No files found at minoc.", style="bold red")
115119
return None
116120
files_paths = [f.replace("cadc:CHIMEFRB", "") for f in files["missing"]]
117-
to_download_size = 0.0
118-
if len(files_paths) > 0:
121+
if len(files_paths) > 0 and luskan_up:
119122
common_path = path.commonpath(["/" + f for f in files_paths])
120123
try:
121124
to_download_size = cadcclient.size(common_path)
@@ -127,6 +130,10 @@ def pull( # noqa: C901
127130
"""
128131
)
129132
return None
133+
elif not luskan_up:
134+
to_download_size = -1
135+
else:
136+
to_download_size = 0
130137
console.print(
131138
f" - {len(files['existing'])} files found at {site}.",
132139
style="green",
@@ -135,10 +142,16 @@ def pull( # noqa: C901
135142
f" - {len(files['missing'])} files can be downloaded from minoc.",
136143
style="yellow",
137144
)
138-
console.print(
139-
f" - Size to download: {to_download_size:.2f} GB.\n",
140-
style="yellow",
141-
)
145+
if luskan_up:
146+
console.print(
147+
f" - Size to download: {to_download_size:.2f} GB.\n",
148+
style="yellow",
149+
)
150+
else:
151+
console.print(
152+
" - Size to download: [red]Unable to query Luskan[/red].",
153+
style="yellow",
154+
)
142155

143156
# Confirm download.
144157
if force:

dtcli/scout.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ def scout( # noqa: C901
7979
return {"error": "No config. Create one with `datatrail config init`."}
8080

8181
# Check Canfar status.
82-
canfar_up = cadcclient.status()
83-
if not canfar_up:
82+
minoc_up, luskan_up = cadcclient.status()
83+
if not minoc_up:
8484
error_console.print(
8585
"Either Minoc is down or certificate is invalid.", style="bold yellow"
8686
)
87+
elif not luskan_up:
88+
error_console.print(
89+
"Either Luskan is down or certificate is invalid.", style="bold yellow"
90+
)
8791

8892
# Scout dataset.
8993
endpoint = (

dtcli/utilities/cadcclient.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,30 +369,39 @@ def query(
369369

370370

371371
def status(
372-
url: str = "https://ws-uv.canfar.net/minoc/capabilities",
373372
certfile: Optional[str] = None,
374-
) -> bool:
373+
) -> Tuple[bool, bool]:
375374
"""Check the status of Minoc.
376375
377376
Args:
378-
url: Minoc capabilities HEAD endpoint.
379377
certfile: Canfar certificate file.
380378
381379
Returns:
382380
bool: True if Minoc is up, False otherwise.
383381
"""
382+
urls: List[str] = [
383+
"https://ws-uv.canfar.net/minoc/capabilities",
384+
"https://ws-uv.canfar.net/luskan/capabilities",
385+
]
384386
if not certfile:
385387
certfile = procure(key="vospace_certfile")
386-
response = requests.get(url, cert=certfile, allow_redirects=True)
387-
try:
388-
response.raise_for_status()
389-
except HTTPError as error:
390-
logger.error(error)
391-
logger.error("Canfar is down.")
392-
return False
393-
authorised = response.headers.get("x-vo-authenticated")
394-
if isinstance(authorised, str):
395-
return True
396-
else:
397-
logger.error("Canfar certificate is not valid.")
398-
return False
388+
minoc_status = False
389+
luskan_status = False
390+
for index, url in enumerate(urls):
391+
response = requests.get(url, cert=certfile, allow_redirects=True)
392+
try:
393+
response.raise_for_status()
394+
authorised = response.headers.get("x-vo-authenticated")
395+
if isinstance(authorised, str):
396+
if index == 0:
397+
minoc_status = True
398+
else:
399+
luskan_status = True
400+
else:
401+
raise TypeError
402+
except HTTPError as error:
403+
logger.error(error)
404+
logger.error(f"{url.split('/')[3]} is down.")
405+
except TypeError:
406+
logger.error("Canfar certificate is not valid.")
407+
return minoc_status, luskan_status

0 commit comments

Comments
 (0)