diff --git a/neo/tests/__init__.py b/neo/tests/__init__.py index c2177417dfe52f028cbbebfda863df6eedf9f80d..75db0a0030da3e3a604cb5f1c56a5dd52325de76 100644 --- a/neo/tests/__init__.py +++ b/neo/tests/__init__.py @@ -31,13 +31,6 @@ DB_ADMIN = 'root' DB_PASSWD = None DB_USER = 'test' -def getNewUUID(): - """ Return a valid UUID """ - uuid = protocol.INVALID_UUID - while uuid == protocol.INVALID_UUID: - uuid = os.urandom(16) - return uuid - class NeoTestBase(unittest.TestCase): """ Base class for neo tests, implements common checks """ @@ -90,11 +83,30 @@ class NeoTestBase(unittest.TestCase): 'getAdapter': 'MySQL', }) - # XXX: according to changes with namespaced UUIDs, it would be better to - # implement get<NodeType>UUID() methods + def _makeUUID(self, prefix): + """ + Retuns a 16-bytes UUID according to namespace 'prefix' + """ + assert len(prefix) == 1 + uuid = protocol.INVALID_UUID + while uuid[1:] == protocol.INVALID_UUID[1:]: + uuid = prefix + os.urandom(15) + return uuid + def getNewUUID(self): - self.uuid = getNewUUID() - return self.uuid + return self._makeUUID('\0') + + def getClientUUID(self): + return self._makeUUID('C') + + def getMasterUUID(self): + return self._makeUUID('M') + + def getStorageUUID(self): + return self._makeUUID('S') + + def getAdminUUID(self): + return self._makeUUID('A') def getNextTID(self, ltid): tm = time() diff --git a/neo/tests/functional/__init__.py b/neo/tests/functional/__init__.py index f32942c80641f821cc414d09d523a3a756f0137b..b468afa71bf8f4de7af1a8ff003b4a3450b85a2b 100644 --- a/neo/tests/functional/__init__.py +++ b/neo/tests/functional/__init__.py @@ -29,7 +29,6 @@ import traceback from neo.neoctl.neoctl import NeoCTL, NotReadyException from neo.protocol import ClusterStates, NodeTypes, CellStates from neo.client.Storage import Storage -from neo.tests import getNewUUID from neo.util import dump NEO_MASTER = 'neomaster' @@ -196,11 +195,8 @@ class NEOCluster(object): return port def __allocateUUID(self): - uuid_set = self.uuid_set - uuid = None - while uuid is None or uuid in uuid_set: - uuid = getNewUUID() - uuid_set.add(uuid) + uuid = os.urandom(16) + self.uuid_set.add(uuid) return uuid def setupDB(self):