1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

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 <ja@sernet.de>
Reviewed-by: Björn Baumbach <bb@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Oct 29 18:54:24 UTC 2020 on sn-devel-184
This commit is contained in:
Jule Anger
2020-10-20 09:42:38 +02:00
committed by Jeremy Allison
parent ebd687335b
commit 9214fcec34

View File

@ -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"""