77
88from slurm_rest_api_client import Client
99from slurm_rest_api_client .api .slurm import slurm_v0043_delete_jobs
10- from slurm_rest_api_client .api .slurmdb import slurmdb_v0043_get_accounts , slurmdb_v0043_post_associations
10+ from slurm_rest_api_client .api .slurmdb import (
11+ slurmdb_v0043_get_accounts ,
12+ slurmdb_v0043_get_associations ,
13+ slurmdb_v0043_post_associations ,
14+ )
1115from slurm_rest_api_client .models .v0043_account import V0043Account
1216from slurm_rest_api_client .models .v0043_assoc import V0043Assoc
1317from slurm_rest_api_client .models .v0043_assoc_max import V0043AssocMax
@@ -105,13 +109,12 @@ def delete_association_user_account(self, username: str, account: str, noop: boo
105109 logging .debug (f"deletion status: { status } " )
106110 if jobs_delete_resp .errors :
107111 for error in jobs_delete_resp .errors :
108- logging .warning (f"error deleting job: { error } " )
112+ logging .error (f"error deleting job: { error } " )
109113 raise RuntimeError (f"Could not delete jobs for user: { username } with account: { account } " )
110114 else :
111115 raise ConnectionError (f"Could not delete jobs for user: { username } with account: { account } " )
112116
113117 # set maxsubmit to 0 as root
114-
115118 max_submit_assoc : V0043Assoc = V0043Assoc (
116119 user = username ,
117120 account = account ,
@@ -121,4 +124,38 @@ def delete_association_user_account(self, username: str, account: str, noop: boo
121124 maxsubmit_set_resp = slurmdb_v0043_post_associations .sync (client = self .root_client , body = body_max_submit )
122125 if maxsubmit_set_resp :
123126 logger .info ("resp" )
127+ if maxsubmit_set_resp .errors :
128+ for error in maxsubmit_set_resp .errors :
129+ logging .error (f"error posting association: { error } " )
130+ raise RuntimeError (f"Could not set maxsubmit=0 for user: { username } with account: { account } " )
131+ else :
132+ raise ConnectionError (f"Could not set maxsubmit=0 for user: { username } with account: { account } " )
133+
134+ default_assoc_get_resp = slurmdb_v0043_get_associations .sync (
135+ client = self .root_client , filter_to_only_defaults = str (True )
136+ )
137+ if not default_assoc_get_resp :
138+ raise ConnectionError (f"Could not get default association for user: { username } " )
139+ if default_assoc_get_resp .errors :
140+ raise RuntimeError (f"Could not get default association for user: { username } " )
141+
142+ default_account_for_this_user = default_assoc_get_resp .associations [0 ].account
143+ if default_account_for_this_user == account :
144+ logger .info (
145+ f"User: { username } has set the account: { account } as their default. Re-setting their default account."
146+ )
147+ # Assuming that everyone on the cluster is part of the account "users"!
148+ set_default_account_accoc : V0043Assoc = V0043Assoc (user = username , account = "users" , is_default = True )
149+ default_assoc_set_body : V0043OpenapiAssocsResp = V0043OpenapiAssocsResp (
150+ associations = [set_default_account_accoc ]
151+ )
152+
153+ default_assoc_set_resp = slurmdb_v0043_post_associations .sync (
154+ client = self .root_client , body = default_assoc_set_body
155+ )
156+ if not default_assoc_set_resp :
157+ raise ConnectionError (f"Could not set default association for user: { username } " )
158+ if default_assoc_set_resp .errors :
159+ raise RuntimeError (f"Could not set default association for user: { username } " )
160+
124161 return
0 commit comments