Skip to content

Commit

Permalink
Add more descriptive output for when no allocations are found (#272)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Comeani and djperrefort authored Nov 12, 2024
1 parent 2c2bba7 commit 4c71fd2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
17 changes: 12 additions & 5 deletions apps/crc_proposal_end.py
Original file line number Diff line number Diff line change
@@ -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.
"""

Expand All @@ -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"""
Expand All @@ -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']} ")
14 changes: 11 additions & 3 deletions apps/crc_sus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 10 additions & 4 deletions apps/crc_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,16 +97,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"))

# Gather AllocationRequests from Keystone
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 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)

Expand Down

0 comments on commit 4c71fd2

Please sign in to comment.