Commit 57a219d6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Define get<NodeType>UUID in base test class to fit better with implementation.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1460 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a41b720e
......@@ -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()
......
......@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment