Skip to content

Commit

Permalink
Merge pull request #569 from cmoussa1/add.edit.fair-share
Browse files Browse the repository at this point in the history
`edit-user`: make `fairshare` an editable field for an association
  • Loading branch information
mergify[bot] authored Jan 29, 2025
2 parents 82e6a9a + c291557 commit 3a250a0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bindings/python/fluxacct/accounting/__init__.py.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DB_DIR = "@X_LOCALSTATEDIR@/lib/flux/"
DB_PATH = "@X_LOCALSTATEDIR@/lib/flux/FluxAccounting.db"
DB_SCHEMA_VERSION = 25
DB_SCHEMA_VERSION = 26

# flux-accounting DB table column names
ASSOCIATION_TABLE = [
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/python/fluxacct/accounting/create_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def create_db(
default_bank tinytext NOT NULL,
shares int(11) DEFAULT 1 NOT NULL ON CONFLICT REPLACE DEFAULT 1,
job_usage real DEFAULT 0.0 NOT NULL,
fairshare real DEFAULT 0.5 NOT NULL,
fairshare real DEFAULT 0.5 NOT NULL ON CONFLICT REPLACE DEFAULT 0.5,
max_running_jobs int(11) DEFAULT 5 NOT NULL ON CONFLICT REPLACE DEFAULT 5,
max_active_jobs int(11) DEFAULT 7 NOT NULL ON CONFLICT REPLACE DEFAULT 7,
max_nodes int(11) DEFAULT 2147483647 NOT NULL ON CONFLICT REPLACE DEFAULT 2147483647,
Expand Down
3 changes: 3 additions & 0 deletions src/bindings/python/fluxacct/accounting/user_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def edit_user(conn, username, bank=None, **kwargs):
default_bank: The user's default bank.
shares: The amount of available resources their organization considers the user
should be entitled to use relative to other competing users.
fairshare: The ratio between the amount of resources an association is
allocated versus the amount actually consumed.
max_running_jobs: The max number of running jobs the association can have at any
given time.
max_active_jobs: The max number of both pending and running jobs the association
Expand All @@ -441,6 +443,7 @@ def edit_user(conn, username, bank=None, **kwargs):
"userid",
"default_bank",
"shares",
"fairshare",
"max_running_jobs",
"max_active_jobs",
"max_nodes",
Expand Down
1 change: 1 addition & 0 deletions src/cmd/flux-account-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def edit_user(self, handle, watcher, msg, arg):
userid=msg.payload["userid"],
default_bank=msg.payload["default_bank"],
shares=msg.payload["shares"],
fairshare=msg.payload["fairshare"],
max_running_jobs=msg.payload["max_running_jobs"],
max_active_jobs=msg.payload["max_active_jobs"],
max_nodes=msg.payload["max_nodes"],
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/flux-account.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def add_edit_user_arg(subparsers):
default=None,
metavar="SHARES",
)
subparser_edit_user.add_argument(
"--fairshare",
help="fairshare",
default=None,
metavar="SHARES",
)
subparser_edit_user.add_argument(
"--max-running-jobs",
help="max number of jobs that can be running at the same time",
Expand Down
16 changes: 16 additions & 0 deletions t/python/t1002_user_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ def test_15_add_user_with_nonexistent_project(self):
with self.assertRaises(ValueError):
u.add_user(acct_conn, username="test_user4", bank="A", projects="foo")

# edit a user's fair-share value
def test_16_edit_user_fairshare(self):
cur = acct_conn.cursor()
cur.execute(
"SELECT fairshare FROM association_table WHERE username='test_user5'"
)
fairshare = cur.fetchall()
self.assertEqual(fairshare[0][0], 0.5)

u.edit_user(acct_conn, username="test_user5", fairshare=0.95)
cur.execute(
"SELECT fairshare FROM association_table WHERE username='test_user5'"
)
fairshare = cur.fetchall()
self.assertEqual(fairshare[0][0], 0.95)

# remove database and log file
@classmethod
def tearDownClass(self):
Expand Down
12 changes: 12 additions & 0 deletions t/t1007-flux-account-users.t
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ test_expect_success 'edit a field in a user account' '
flux account edit-user user5011 --shares 50
'

test_expect_success 'edit the fairshare value for a user' '
flux account edit-user user5011 --fairshare 0.99 &&
flux account view-user user5011 > user.out &&
grep "\"fairshare\": 0.99" user.out
'

test_expect_success 'reset the fairshare value for a user' '
flux account edit-user user5011 --fairshare=-1 &&
flux account view-user user5011 > user.out &&
grep "\"fairshare\": 0.5" user.out
'

test_expect_success 'remove a user account' '
flux account delete-user user5012 A &&
flux account view-user user5012 > deleted_user.out &&
Expand Down

0 comments on commit 3a250a0

Please sign in to comment.