Skip to content

Commit 3fda6ad

Browse files
committed
delete accounts
1 parent df20b4f commit 3fda6ad

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

coldfront/plugins/slurmrest/management/commands/slurmrest_check.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def check_consistency(self, slurm_cluster, coldfront_resource):
139139
continue
140140

141141
else:
142+
# Allocation has been removed in Coldfront!
142143
for association in account.associations:
143144
# Only SLURM devs know whey some associations are two way (account, cluster)
144145
# when most others are 4-way (user, account, cluster, partition)
@@ -150,10 +151,19 @@ def check_consistency(self, slurm_cluster, coldfront_resource):
150151
logger.debug(f"Ignoring user: {username} in account: {account.name}")
151152
continue
152153

153-
logger.warning(
154-
f"SLURM account: {account.name} with user: {username} not found in ColdFront. Removing association.",
154+
logger.info(
155+
f"Deleted SLURM account: {account.name} has user: {username}. Removing association.",
155156
)
156157

158+
try:
159+
slurm_cluster.delete_association_user_account(username, account.name, self.noop)
160+
except RuntimeError:
161+
logging.warning(
162+
f"Could not delete association for user: {username} and account: {account.name}"
163+
)
164+
continue
165+
# Once the SLURM account has no users associated, remove the slurm account as well
166+
157167
def handle(self, *args, **options):
158168

159169
verbosity: int = options["verbosity"]

coldfront/plugins/slurmrest/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from slurm_rest_api_client import Client
99
from slurm_rest_api_client.api.slurm import slurm_v0043_delete_jobs
1010
from slurm_rest_api_client.api.slurmdb import (
11+
slurmdb_v0043_delete_account,
1112
slurmdb_v0043_delete_association,
1213
slurmdb_v0043_get_accounts,
1314
slurmdb_v0043_get_associations,
@@ -169,3 +170,24 @@ def delete_association_user_account(self, username: str, account: str, noop: boo
169170
raise RuntimeError(f"Could not delete association for user: {username} and account: {account}")
170171

171172
return
173+
174+
@retry(
175+
wait=wait_exponential(multiplier=2, min=2, max=10),
176+
stop=stop_after_attempt(3),
177+
retry=retry_if_not_exception_type(ConnectionError),
178+
before_sleep=before_sleep_log(logging.getLogger(__name__), logging.WARNING),
179+
)
180+
def delete_slurm_account(self, account: str, noop: bool = False) -> None:
181+
if noop:
182+
logging.info(f"noop enabled: skip deleting acconut: {account}")
183+
return
184+
185+
account_delete_resp = slurmdb_v0043_delete_account.sync(client=self.root_client, account_name=account)
186+
187+
if not account_delete_resp:
188+
raise ConnectionError(f"Could not delete account: {account}")
189+
if account_delete_resp.errors:
190+
raise RuntimeError(f"Could not delete account: {account}")
191+
for account_removed in account_delete_resp.removed_accounts:
192+
logging.info(f"Removed SLURM account: {account_removed}")
193+
return

0 commit comments

Comments
 (0)