From cc246ad95e4e894a9dbcd3d1d095e2b2aa80c40f Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Wed, 27 Nov 2024 10:32:31 -0500 Subject: [PATCH] Fix bug where crc-usage crashes when awarded sus are none --- apps/crc_usage.py | 3 +-- apps/utils/keystone.py | 12 +++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/crc_usage.py b/apps/crc_usage.py index 1964a15..1996c5f 100755 --- a/apps/crc_usage.py +++ b/apps/crc_usage.py @@ -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) diff --git a/apps/utils/keystone.py b/apps/utils/keystone.py index 7da135d..4d73f63 100644 --- a/apps/utils/keystone.py +++ b/apps/utils/keystone.py @@ -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 = {} @@ -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