Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug where crc-usage crashes when awarded sus are none #273

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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