summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJule Anger <ja@sernet.de>2020-10-20 09:42:38 +0200
committerJeremy Allison <jra@samba.org>2020-10-29 18:54:24 +0000
commit9214fcec349bbda1c9ceb25f835b7aef5024f61a (patch)
treebf4dd06c6dab90e694fc4542e37eeaaba6c73594 /python
parentebd687335b9accfdbae7dbc65c9882ab4d5c0986 (diff)
downloadsamba-9214fcec349bbda1c9ceb25f835b7aef5024f61a.tar.gz
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
Diffstat (limited to 'python')
-rw-r--r--python/samba/tests/samba_tool/base.py20
1 files changed, 17 insertions, 3 deletions
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"""