From 4c71fd2beef2a6e613af95972036a35e086dbf09 Mon Sep 17 00:00:00 2001 From: Nickolas Comeau Date: Mon, 11 Nov 2024 21:39:31 -0500 Subject: [PATCH] Add more descriptive output for when no allocations are found (#272) * add more detailed message specifically for if a research group id was not found * add error messages to crc-sus and crc-proposal-end : * CRC -> CRCD * fix long lines * more long lines apparently * long line --------- Co-authored-by: Daniel Perrefort --- apps/crc_proposal_end.py | 17 ++++++++++++----- apps/crc_sus.py | 14 +++++++++++--- apps/crc_usage.py | 14 ++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/apps/crc_proposal_end.py b/apps/crc_proposal_end.py index 224fa86..5890da7 100755 --- a/apps/crc_proposal_end.py +++ b/apps/crc_proposal_end.py @@ -1,6 +1,6 @@ """Print the end date for an account's proposal. -This application is designed to interface with the CRC banking application +This application is designed to interface with the CRCD banking application and will not work without a running bank installation. """ @@ -15,7 +15,7 @@ class CrcProposalEnd(BaseParser): - """Display the end date for an account's current CRC proposal.""" + """Display the end date for an account's current CRCD proposal.""" def __init__(self) -> None: """Define arguments for the command line interface""" @@ -34,15 +34,22 @@ def app_logic(self, args: Namespace) -> None: Slurm.check_slurm_account_exists(args.account) keystone_session = KeystoneClient(url=KEYSTONE_URL) - keystone_session.login(username=os.environ["USER"], password=getpass("Please enter your CRC login password:\n")) + keystone_session.login(username=os.environ["USER"], + password=getpass("Please enter your CRCD login password:\n")) team_id = get_team_id(keystone_session, args.account) alloc_requests = get_active_requests(keystone_session, team_id) if not alloc_requests: print(f"\033[91m\033[1mNo active allocation information found in accounting system for '{args.account}'!\n") - print("Showing end date for most recently expired Resource Allocation Request:\033[0m") - alloc_requests = [get_most_recent_expired_request(keystone_session, team_id)] + print("Showing end date for most recently expired Resource Allocation Request:\033[0m \n") + try: + alloc_requests = [get_most_recent_expired_request(keystone_session, team_id)] + except IndexError: + print("\033[91m\033[1mNo allocation information found. Either the group does not have any allocations, " + "or you do not have permissions to view them. If you believe this to be a mistake, please submit a " + "help ticket to the CRCD team. \033[0m \n") + exit() for request in alloc_requests: print(f"'{request['title']}' ends on {request['expire']} ") diff --git a/apps/crc_sus.py b/apps/crc_sus.py index a25d478..5cf6d73 100755 --- a/apps/crc_sus.py +++ b/apps/crc_sus.py @@ -59,15 +59,23 @@ def app_logic(self, args: Namespace) -> None: Slurm.check_slurm_account_exists(account_name=args.account) keystone_session = KeystoneClient(url=KEYSTONE_URL) - keystone_session.login(username=os.environ["USER"], password=getpass("Please enter your CRC login password:\n")) + keystone_session.login(username=os.environ["USER"], + password=getpass("Please enter your CRCD login password:\n")) group_id = get_team_id(keystone_session, args.account) alloc_requests = get_active_requests(keystone_session, group_id) if not alloc_requests: print(f"\033[91m\033[1mNo active allocation information found in accounting system for '{args.account}'!\n") - print("Showing remaining service unit amounts for most recently expired Resource Allocation Request:\033[0m") - alloc_requests = [get_most_recent_expired_request(keystone_session, group_id)] + print("Showing remaining service unit amounts for most recently expired Resource Allocation Request:" + "\033[0m \n") + try: + alloc_requests = [get_most_recent_expired_request(keystone_session, group_id)] + except IndexError: + print("\033[91m\033[1mNo allocation information found. Either the group does not have any allocations, " + "or you do not have permissions to view them. If you believe this to be a mistake, please submit " + "a help ticket to the CRCD team. \033[0m \n") + exit() per_cluster_totals = get_per_cluster_totals(keystone_session, alloc_requests, get_enabled_cluster_ids(keystone_session)) diff --git a/apps/crc_usage.py b/apps/crc_usage.py index 0c37a30..1964a15 100755 --- a/apps/crc_usage.py +++ b/apps/crc_usage.py @@ -11,7 +11,6 @@ from prettytable import PrettyTable -from keystone_client import KeystoneClient from .utils.cli import BaseParser from .utils.keystone import * from .utils.system_info import Slurm @@ -98,7 +97,8 @@ def app_logic(self, args: Namespace) -> None: Slurm.check_slurm_account_exists(account_name=args.account) keystone_session = KeystoneClient(url=KEYSTONE_URL) - keystone_session.login(username=os.environ["USER"], password=getpass("Please enter your CRC login password:\n")) + keystone_session.login(username=os.environ["USER"], + password=getpass("Please enter your CRCD login password:\n")) # Gather AllocationRequests from Keystone group_id = get_team_id(keystone_session, args.account) @@ -106,8 +106,14 @@ def app_logic(self, args: Namespace) -> None: if not alloc_requests: print(f"\033[91m\033[1mNo active allocation information found in accounting system for '{args.account}'!\n") - print("Showing usage information for most recently expired Resource Allocation Request: \033[0m") - alloc_requests = [get_most_recent_expired_request(keystone_session, group_id)] + print("Attempting to show the most recently expired Resource Allocation Request info: \033[0m \n") + try: + alloc_requests = [get_most_recent_expired_request(keystone_session, group_id)] + except IndexError: + print("\033[91m\033[1mNo allocation information found. Either the group does not have any allocations, " + "or you do not have permissions to view them. If you believe this to be a mistake, please submit " + "a help ticket to the CRCD team. \033[0m \n") + exit() clusters = get_enabled_cluster_ids(keystone_session)