diff options
author | Joseph Sutton <josephsutton@catalyst.net.nz> | 2023-04-27 10:43:01 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2023-05-05 02:54:31 +0000 |
commit | 4dc9abc777ba923074a840266f944db3789aa3c0 (patch) | |
tree | 07fe33631d2cea86262edf42089b27df32b75fd4 /python | |
parent | 9c4a71de4722064cb0b1c46ac32204d5761fdaec (diff) | |
download | samba-4dc9abc777ba923074a840266f944db3789aa3c0.tar.gz |
tests/krb5: Delete non-resuable accounts as soon as possible
This helps to mitigate Samba’s slow account deletion.
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/tests/krb5/kdc_base_test.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/python/samba/tests/krb5/kdc_base_test.py b/python/samba/tests/krb5/kdc_base_test.py index 7588beb1ee3..74e6dfb406a 100644 --- a/python/samba/tests/krb5/kdc_base_test.py +++ b/python/samba/tests/krb5/kdc_base_test.py @@ -300,6 +300,10 @@ class KDCBaseTest(RawKerberosTest): return ldb.Dn(samdb, str(self._authn_silos_dn)) def tearDown(self): + # Run any cleanups that may modify accounts prior to deleting those + # accounts. + self.doCleanups() + # Clean up any accounts created for single tests. if self._ldb is not None: for dn in reversed(self.test_accounts): @@ -750,7 +754,8 @@ class KDCBaseTest(RawKerberosTest): def create_account(self, samdb, name, account_type=AccountType.USER, spn=None, upn=None, additional_details=None, ou=None, account_control=0, add_dollar=None, - expired_password=False, force_nt4_hash=False): + expired_password=False, force_nt4_hash=False, + preserve=True): '''Create an account for testing. The dn of the created account is added to self.accounts, which is used by tearDownClass to clean up the created accounts. @@ -820,8 +825,17 @@ class KDCBaseTest(RawKerberosTest): details["pwdLastSet"] = "0" if additional_details is not None: details.update(additional_details) - # Save the account name so it can be deleted in tearDownClass - self.accounts.append(dn) + if preserve: + # Mark this account for deletion in tearDownClass() after all the + # tests in this class finish. + self.accounts.append(dn) + else: + # Mark this account for deletion in tearDown() after the current + # test finishes. Because the time complexity of deleting an account + # in Samba scales with the number of accounts, it is faster to + # delete accounts as soon as possible than to keep them around + # until all the tests are finished. + self.test_accounts.append(dn) samdb.add(details) expected_kvno = 1 @@ -1670,13 +1684,13 @@ class KDCBaseTest(RawKerberosTest): if creds is not None: return creds - creds = self.create_account_opts(**account_opts) + creds = self.create_account_opts(use_cache, **account_opts) if use_cache: self.account_cache[cache_key] = creds return creds - def create_account_opts(self, *, + def create_account_opts(self, use_cache, *, account_type, name_prefix, name_suffix, @@ -1779,7 +1793,8 @@ class KDCBaseTest(RawKerberosTest): account_control=user_account_control, add_dollar=add_dollar, force_nt4_hash=force_nt4_hash, - expired_password=expired_password) + expired_password=expired_password, + preserve=use_cache) expected_etypes = None if force_nt4_hash: |