From: Jule Anger Date: Tue, 20 Oct 2020 07:42:38 +0000 (+0200) Subject: tests: avoid returning an already used ID in randomXid() X-Git-Tag: talloc-2.3.2~88 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9214fcec349bbda1c9ceb25f835b7aef5024f61a;p=thirdparty%2Fsamba.git tests: avoid returning an already used ID in randomXid() The error 'uidNumber xxx is already being used.' in the samba tool tests occurs when the random.randint functions returns the same value twice and therefore a user or group with an already used gid or uid should be created. Avoid this error by adding a list that stores the used IDs, so that the randomXid function can check wheter a value is already used before returning it. Signed-off-by: Jule Anger Reviewed-by: Björn Baumbach Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Oct 29 18:54:24 UTC 2020 on sn-devel-184 --- diff --git a/python/samba/tests/samba_tool/base.py b/python/samba/tests/samba_tool/base.py index 536fbfc1617..00e742e7c5b 100644 --- a/python/samba/tests/samba_tool/base.py +++ b/python/samba/tests/samba_tool/base.py @@ -125,10 +125,24 @@ class SambaToolCmdTest(samba.tests.BlackboxTestCase): return name def randomXid(self): - # pick some hopefully unused, high UID/GID range to avoid interference + # pick some unused, high UID/GID range to avoid interference # from the system the test runs on - xid = random.randint(4711000, 4799000) - return xid + + # initialize a list to store used IDs + try: + self.used_xids + except AttributeError: + self.used_xids = [] + + # try to get an unused ID + failed = 0 + while failed < 50: + xid = random.randint(4711000, 4799000) + if xid not in self.used_xids: + self.used_xids += [xid] + return xid + failed += 1 + assert False, "No Xid are available" def assertWithin(self, val1, val2, delta, msg=""): """Assert that val1 is within delta of val2, useful for time computations"""