Skip to content

Commit

Permalink
Tweak logic so user looses all accounts if they loose jasmin-login.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanning9 committed Sep 11, 2024
1 parent f1d0101 commit 95b2420
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions jasmin_slurm_sync/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ def expected_slurm_accounts(self) -> set[str]:
for x in self.ldap_user["description"]
if x in known_tags
)
return set(expected_tags)
# Check that the user is in the required SLURM accounts for sync.
# Otherwise, if they don't have the required accounts, we expect them
# to be in NO accounts.
if expected_tags >= self.settings.required_slurm_accounts:
return set(expected_tags)
logger.warning(
"User is not in required accounts: %s so will be removed from ALL acounts that the script manages.",
self.settings.required_slurm_accounts - self.expected_slurm_accounts,
)
return set()

@property
def to_be_added(self) -> set[str]:
Expand All @@ -70,7 +79,7 @@ def add_user_to_account(self, account: str) -> None:
]
if self.args.dry_run:
logger.warning(
"Not adding user %s to account %s, because we are in dry run mode.",
"Would add user %s to account %s, but we are in dry run mode so not doing anything.",
self.username,
account,
)
Expand Down Expand Up @@ -103,7 +112,7 @@ def remove_user_from_account(self, account: str) -> None:
]
if self.args.dry_run:
logger.warning(
"Not removing user %s from account %s, because we are in dry run mode.",
"Would remove user %s from account %s, but we are in dry run mode so not doing anything.",
self.username,
account,
)
Expand All @@ -125,14 +134,6 @@ def remove_user_from_account(self, account: str) -> None:

def sync_slurm_accounts(self) -> None:
"""Do a full sync of the user's SLURM accounts."""
# Check the user is going to be in the required slurm accounts.
if not self.expected_slurm_accounts >= self.settings.required_slurm_accounts:
logger.warning(
"User is not in required accounts: %s so won't be synced.",
self.settings.required_slurm_accounts - self.expected_slurm_accounts,
)
raise errors.NotInRequiredAccounts

# Check if there are any accounts to be added or removed so we don't have to check things if
# we have no work to do.
if self.to_be_added or self.to_be_removed:
Expand Down

0 comments on commit 95b2420

Please sign in to comment.