Skip to content

Commit

Permalink
Fix bug where crc-usage crashes when awarded sus are none
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Nov 27, 2024
1 parent 4c71fd2 commit cc246ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions apps/crc_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def print_summary_table(alloc_requests: [dict], account_name: str, per_request_t

@staticmethod
def print_usage_table(account_name: str, awarded_totals: dict, earliest_date: date) -> None:
"""Build and print a human-readable usage table for the slurm account with info from Keystone and
sreport"""
"""Build and print a human-readable usage table for the slurm account with info from Keystone and sreport"""

# Initialize table for summary of usage
usage_table = PrettyTable(header=False, padding_width=2, max_table_width=79, min_table_width=79)
Expand Down
12 changes: 7 additions & 5 deletions apps/utils/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ def get_enabled_cluster_ids(session: KeystoneClient) -> dict():


def get_per_cluster_totals(session: KeystoneClient,
alloc_requests: [dict],
clusters: dict,
per_request: bool = False) -> dict:
alloc_requests: [dict],
clusters: dict,
per_request: bool = False
) -> dict:
"""Gather the awarded totals across the given requests on each cluster into a dictionary"""

per_cluster_totals = {}
Expand All @@ -86,11 +87,12 @@ def get_per_cluster_totals(session: KeystoneClient,
per_cluster_totals[request['id']] = {}
for allocation in get_request_allocations(session, request['id']):
cluster = clusters[allocation['cluster']]
awarded = allocation['awarded'] if allocation['awarded'] is not None else 0
if per_request:
per_cluster_totals[request['id']].setdefault(cluster, 0)
per_cluster_totals[request['id']][cluster] += allocation['awarded']
per_cluster_totals[request['id']][cluster] += awarded
else:
per_cluster_totals.setdefault(cluster, 0)
per_cluster_totals[cluster] += allocation['awarded']
per_cluster_totals[cluster] += awarded

return per_cluster_totals

0 comments on commit cc246ad

Please sign in to comment.