Commit 27ceb80f authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix bug where new UUID was never stored in the database, since it can change

when the primary master supplied a new UUID. Database manager use 'REPLACE' SQL
statement instead of 'INSERT' to avoid DuplicateEntry errors. Tests updated.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@454 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 9735d7d0
...@@ -25,6 +25,7 @@ from neo.connection import ClientConnection ...@@ -25,6 +25,7 @@ from neo.connection import ClientConnection
from neo.protocol import Packet from neo.protocol import Packet
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.verification import VerificationEventHandler from neo.storage.verification import VerificationEventHandler
from neo.util import dump
class BootstrapEventHandler(StorageEventHandler): class BootstrapEventHandler(StorageEventHandler):
"""This class deals with events for a bootstrap phase.""" """This class deals with events for a bootstrap phase."""
...@@ -190,6 +191,8 @@ class BootstrapEventHandler(StorageEventHandler): ...@@ -190,6 +191,8 @@ class BootstrapEventHandler(StorageEventHandler):
if your_uuid != INVALID_UUID and app.uuid != your_uuid: if your_uuid != INVALID_UUID and app.uuid != your_uuid:
# got an uuid from the primary master # got an uuid from the primary master
app.uuid = your_uuid app.uuid = your_uuid
app.dm.setUUID(app.uuid)
logging.info('Got a new UUID from master : %s' % dump(app.uuid))
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
......
...@@ -183,7 +183,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -183,7 +183,7 @@ class MySQLDatabaseManager(DatabaseManager):
e = self.escape e = self.escape
key = e(str(key)) key = e(str(key))
value = e(str(value)) value = e(str(value))
q("""INSERT config VALUES ('%s', '%s')""" % (key, value)) q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value))
def getUUID(self): def getUUID(self):
return self.getConfiguration('uuid') return self.getConfiguration('uuid')
......
...@@ -198,8 +198,8 @@ class StorageMySQSLdbTests(unittest.TestCase): ...@@ -198,8 +198,8 @@ class StorageMySQSLdbTests(unittest.TestCase):
self.assertEquals(get_call(), None) self.assertEquals(get_call(), None)
set_call(value) set_call(value)
self.assertEquals(get_call(), value) self.assertEquals(get_call(), value)
self.assertRaises(MySQLdb.IntegrityError, set_call, value * 2) set_call(value * 2)
self.assertEquals(get_call(), value) self.assertEquals(get_call(), value * 2)
def test_12_UUID(self): def test_12_UUID(self):
self.checkConfigEntry( self.checkConfigEntry(
...@@ -225,8 +225,8 @@ class StorageMySQSLdbTests(unittest.TestCase): ...@@ -225,8 +225,8 @@ class StorageMySQSLdbTests(unittest.TestCase):
self.assertEquals(self.db.getPTID(), INVALID_PTID) self.assertEquals(self.db.getPTID(), INVALID_PTID)
self.db.setPTID(test) self.db.setPTID(test)
self.assertEquals(self.db.getPTID(), test) self.assertEquals(self.db.getPTID(), test)
self.assertRaises(MySQLdb.IntegrityError, self.db.setPTID, test * 2) self.db.setPTID(test * 2)
self.assertEquals(self.db.getPTID(), test) self.assertEquals(self.db.getPTID(), test * 2)
def test_16_getPartitionTable(self): def test_16_getPartitionTable(self):
# insert an entry and check it # insert an entry and check it
......
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