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

python: create new BankFormatter subclass, restructure view-bank to use new class #525

Merged
merged 8 commits into from
Dec 30, 2024

Conversation

cmoussa1
Copy link
Member

@cmoussa1 cmoussa1 commented Nov 4, 2024

Problem

The AccountingFormatter class has good overarching methods for printing the results of a query to the flux-accounting database, but there is some functionality specific to viewing bank information from the database that could use its own subclass.


This PR adds a new subclass called BankFormatter, which contains unique methods for viewing bank/user information in hierarchical and parsable formats with the view-bank command, particularly with the --tree, --users, and -P options. A new --fields option is also added to match the customization available in the list-banks command. It removes the helper functions previously defined in bank_subcommands.py in favor of using this new subclass.

I've added some new unit tests for the output of the reworked view-bank command to the testsuite as well as adjusted a number of expected output files throughout the testsuite to account for the use of the new BankFormatter subclass.

@cmoussa1 cmoussa1 added improvement Upgrades to an already existing feature low priority items that can be worked on at a later date labels Nov 4, 2024
@cmoussa1 cmoussa1 force-pushed the restructure.bank.views branch 2 times, most recently from 49aecd2 to fc18eb6 Compare November 19, 2024 18:26
@cmoussa1 cmoussa1 changed the title [WIP] python: create new BankFormatter subclass, restructure view-bank to use new class python: create new BankFormatter subclass, restructure view-bank to use new class Nov 19, 2024
@cmoussa1 cmoussa1 marked this pull request as ready for review November 19, 2024 18:33
@cmoussa1 cmoussa1 requested a review from wihobbs November 19, 2024 22:50
@cmoussa1 cmoussa1 force-pushed the restructure.bank.views branch from fc18eb6 to 3ae8630 Compare November 26, 2024 19:33
Copy link
Member

@wihobbs wihobbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

if users:
for user in users:
hierarchy += (
f"{indent} {bank}|{user[0]}|{user[1]}|{user[2]}|{user[3]}\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware the magic numbers here (and in the lines below...)

@@ -54,7 +54,7 @@ test_expect_success 'view database hierarchy' '
'

test_expect_success 'view database hierarchy in a parsable format' '
flux account view-bank -P root > small_no_tie_parsable.test &&
flux account view-bank --tree -P root > small_no_tie_parsable.test &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit nit: hierarchies

@cmoussa1 cmoussa1 force-pushed the restructure.bank.views branch from 3ae8630 to bbcfb18 Compare December 30, 2024 18:06
Problem: The AccountingFormatter class has good overarching methods
for printing the results of a query to the flux-accounting database,
but there is some functionality specific to viewing bank information
from the database that could use its own subclass.

Add a new subclass called BankFormatter, which contains unique methods
for viewing bank/user information in hierarchical and parsable formats
with the view-bank command. Remove the helper functions previously
defined in bank_subcommands.py in favor of using this new subclass. Add
a --fields optional argument to allow the user to customize which
columns they want to be returned when looking at a row of information
for a bank.
Problem: view-bank does not have many unit tests, especially for
calling view-bank with custom outputs or viewing information in either
JSON or table format.

Add some unit tests.
Problem: The --users option for the view-bank command lists a lot of
columns for every user row in the association_table, which crowds the
output with potentially unneccessary information when looking at which
users belong to the bank being looked at. The format of this option has
been changed to:

1) be formatted in tables, and
2) only include a couple of columns per user row

Adjust the expected output of the --users optional argument to account
for the use of the BankFormatter subclass.
Problem: The --tree option for the view-bank command still lists the
default information for the bank being viewed *before* printing the
bank hierarchy, which is not necessary when the user passes the --tree
option. Now that the view_bank() function has been reworked to use the
new BankFormatter subclass, these options are more distinct from one
another, and the --tree option no longer includes this info for the
single bank at the top of the output when the --tree option is passed.

Adjust the expected output in the sharness tests to account for the
removal of the default info for the passed-in bank when calling
view-bank with the --tree option.
Problem: The default output of the view-bank command is now JSON by
default, but one of the sharness tests still looks for the old format
before the introduction of the BankFormatter subclass.

Change the expected output to match the new format of calling view-bank
with no optional arguments.
Problem: The parsable option for viewing bank hierarchies in the
flux-accounting database is meant just to be another option for the
--tree option, but now the -P option requires --tree to also be passed
when calling view-bank. There are multiple tests in the flux-accounting
testsuite that call -P without --tree, and thus, these tests fail.

Add --tree to the view-bank -P calls in the testsuite.
Problem: The view-bank command does not support the combination of both
--tree and --fields, but there is no check for this in the testsuite.

Add a test in t1023-flux-account-banks.t that makes sure the
appropriate error message is raised when combining both --tree and
--fields.
Problem: The AccountingFormatter class has good overarching methods
for printing the results of a query to the flux-accounting database,
but there is some functionality specific to viewing bank information
from the database that could use its own subclass.

Add a new subclass called BankFormatter, which contains unique methods
for viewing bank/user information in hierarchical and parsable formats
with the view-bank command. Remove the helper functions previously
defined in bank_subcommands.py in favor of using this new subclass. Add
a --fields optional argument to allow the user to customize which
columns they want to be returned when looking at a row of information
for a bank.
@cmoussa1 cmoussa1 force-pushed the restructure.bank.views branch from bbcfb18 to bd78e16 Compare December 30, 2024 18:18
@cmoussa1
Copy link
Member Author

Thanks @wihobbs! I've rebased this branch to catch up to master; setting MWP here

@mergify mergify bot merged commit 48f56d7 into flux-framework:master Dec 30, 2024
13 checks passed
@cmoussa1 cmoussa1 deleted the restructure.bank.views branch December 30, 2024 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Upgrades to an already existing feature low priority items that can be worked on at a later date merge-when-passing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants