Commit 10598deb authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove trailing whitespaces.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1420 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent fb85bde4
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
...@@ -118,7 +118,7 @@ class Application(object): ...@@ -118,7 +118,7 @@ class Application(object):
nm.createMaster(address=address) nm.createMaster(address=address)
# search, find, connect and identify to the primary master # search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, NodeTypes.ADMIN, bootstrap = BootstrapManager(self, self.name, NodeTypes.ADMIN,
self.uuid, self.server) self.uuid, self.server)
data = bootstrap.getPrimaryConnection(self.connector_handler) data = bootstrap.getPrimaryConnection(self.connector_handler)
(node, conn, uuid, num_partitions, num_replicas) = data (node, conn, uuid, num_partitions, num_replicas) = data
......
...@@ -27,7 +27,7 @@ class AdminEventHandler(EventHandler): ...@@ -27,7 +27,7 @@ class AdminEventHandler(EventHandler):
"""This class deals with events for administrating cluster.""" """This class deals with events for administrating cluster."""
def askPartitionList(self, conn, packet, min_offset, max_offset, uuid): def askPartitionList(self, conn, packet, min_offset, max_offset, uuid):
logging.info("ask partition list from %s to %s for %s" % logging.info("ask partition list from %s to %s for %s" %
(min_offset, max_offset, dump(uuid))) (min_offset, max_offset, dump(uuid)))
app = self.app app = self.app
# check we have one pt otherwise ask it to PMN # check we have one pt otherwise ask it to PMN
...@@ -43,7 +43,7 @@ class AdminEventHandler(EventHandler): ...@@ -43,7 +43,7 @@ class AdminEventHandler(EventHandler):
'uuid' : uuid, 'uuid' : uuid,
'msg_id' : packet.getId()}) 'msg_id' : packet.getId()})
else: else:
app.sendPartitionTable(conn, min_offset, max_offset, uuid, app.sendPartitionTable(conn, min_offset, max_offset, uuid,
packet.getId()) packet.getId())
...@@ -96,10 +96,10 @@ class AdminEventHandler(EventHandler): ...@@ -96,10 +96,10 @@ class AdminEventHandler(EventHandler):
'master.') 'master.')
# required it from PMN first # required it from PMN first
msg_id = self.app.master_conn.ask(Packets.AskClusterState()) msg_id = self.app.master_conn.ask(Packets.AskClusterState())
self.app.dispatcher.register(msg_id, conn, self.app.dispatcher.register(msg_id, conn,
{'msg_id' : packet.getId()}) {'msg_id' : packet.getId()})
else: else:
conn.answer(Packets.AnswerClusterState(self.app.cluster_state), conn.answer(Packets.AnswerClusterState(self.app.cluster_state),
packet.getId()) packet.getId())
def askPrimary(self, conn, packet): def askPrimary(self, conn, packet):
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -26,14 +26,14 @@ from neo.connection import ClientConnection ...@@ -26,14 +26,14 @@ from neo.connection import ClientConnection
NO_SERVER = ('0.0.0.0', 0) NO_SERVER = ('0.0.0.0', 0)
class BootstrapManager(EventHandler): class BootstrapManager(EventHandler):
""" """
Manage the bootstrap stage, lookup for the primary master then connect to it Manage the bootstrap stage, lookup for the primary master then connect to it
""" """
def __init__(self, app, name, node_type, uuid=None, server=NO_SERVER): def __init__(self, app, name, node_type, uuid=None, server=NO_SERVER):
""" """
Manage the bootstrap stage of a non-master node, it lookup for the Manage the bootstrap stage of a non-master node, it lookup for the
primary master node, connect to it then returns when the master node primary master node, connect to it then returns when the master node
is ready. is ready.
""" """
EventHandler.__init__(self, app) EventHandler.__init__(self, app)
...@@ -72,7 +72,7 @@ class BootstrapManager(EventHandler): ...@@ -72,7 +72,7 @@ class BootstrapManager(EventHandler):
def notReady(self, conn, packet, message): def notReady(self, conn, packet, message):
""" """
The primary master send this message when it is still not ready to The primary master send this message when it is still not ready to
handle the client node. handle the client node.
Close connection and restart. Close connection and restart.
""" """
# master are still electing on of them # master are still electing on of them
...@@ -134,7 +134,7 @@ class BootstrapManager(EventHandler): ...@@ -134,7 +134,7 @@ class BootstrapManager(EventHandler):
# retry until identified to the primary # retry until identified to the primary
while self.primary is None or conn.getUUID() != self.primary.getUUID(): while self.primary is None or conn.getUUID() != self.primary.getUUID():
if self.current is None: if self.current is None:
# conn closed # conn closed
conn = None conn = None
# select a master # select a master
master_list = nm.getMasterList() master_list = nm.getMasterList()
...@@ -147,7 +147,7 @@ class BootstrapManager(EventHandler): ...@@ -147,7 +147,7 @@ class BootstrapManager(EventHandler):
# open the connection # open the connection
addr = self.current.getAddress() addr = self.current.getAddress()
conn = ClientConnection(em, self, addr, connector_handler) conn = ClientConnection(em, self, addr, connector_handler)
# still processing # still processing
em.poll(1) em.poll(1)
node = nm.getByUUID(conn.getUUID()) node = nm.getByUUID(conn.getUUID())
return (node, conn, self.uuid, self.num_partitions, self.num_replicas) return (node, conn, self.uuid, self.num_partitions, self.num_replicas)
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -63,7 +63,7 @@ class Storage(BaseStorage.BaseStorage, ...@@ -63,7 +63,7 @@ class Storage(BaseStorage.BaseStorage,
def tpc_begin(self, transaction, tid=None, status=' '): def tpc_begin(self, transaction, tid=None, status=' '):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
return self.app.tpc_begin(transaction=transaction, tid=tid, return self.app.tpc_begin(transaction=transaction, tid=tid,
status=status) status=status)
def tpc_vote(self, transaction): def tpc_vote(self, transaction):
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -47,7 +47,7 @@ from neo.client.mq import MQ ...@@ -47,7 +47,7 @@ from neo.client.mq import MQ
from neo.util import u64, parseMasterList from neo.util import u64, parseMasterList
class ConnectionClosed(Exception): class ConnectionClosed(Exception):
pass pass
...@@ -94,7 +94,7 @@ class ConnectionPool(object): ...@@ -94,7 +94,7 @@ class ConnectionPool(object):
conn.unlock() conn.unlock()
try: try:
app._waitMessage(conn, msg_id, app._waitMessage(conn, msg_id,
handler=app.storage_bootstrap_handler) handler=app.storage_bootstrap_handler)
except ConnectionClosed: except ConnectionClosed:
logging.error('Connection to storage node %s failed', node) logging.error('Connection to storage node %s failed', node)
...@@ -213,7 +213,7 @@ class ThreadContext(object): ...@@ -213,7 +213,7 @@ class ThreadContext(object):
return thread_data[name] return thread_data[name]
except KeyError: except KeyError:
raise AttributeError, name raise AttributeError, name
def __setattr__(self, name, value): def __setattr__(self, name, value):
thread_data = self.__getThreadData() thread_data = self.__getThreadData()
thread_data[name] = value thread_data[name] = value
...@@ -408,7 +408,7 @@ class Application(object): ...@@ -408,7 +408,7 @@ class Application(object):
self.trying_master_node = master_list[0] self.trying_master_node = master_list[0]
index += 1 index += 1
# Connect to master # Connect to master
conn = MTClientConnection(self.em, self.notifications_handler, conn = MTClientConnection(self.em, self.notifications_handler,
addr=self.trying_master_node.getAddress(), addr=self.trying_master_node.getAddress(),
connector_handler=self.connector_handler, connector_handler=self.connector_handler,
dispatcher=self.dispatcher) dispatcher=self.dispatcher)
...@@ -420,12 +420,12 @@ class Application(object): ...@@ -420,12 +420,12 @@ class Application(object):
logging.error('Connection to master node %s failed', logging.error('Connection to master node %s failed',
self.trying_master_node) self.trying_master_node)
continue continue
msg_id = conn.ask(self.local_var.queue, msg_id = conn.ask(self.local_var.queue,
Packets.AskPrimary()) Packets.AskPrimary())
finally: finally:
conn.unlock() conn.unlock()
try: try:
self._waitMessage(conn, msg_id, self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler) handler=self.primary_bootstrap_handler)
except ConnectionClosed: except ConnectionClosed:
continue continue
...@@ -449,7 +449,7 @@ class Application(object): ...@@ -449,7 +449,7 @@ class Application(object):
finally: finally:
conn.unlock() conn.unlock()
try: try:
self._waitMessage(conn, msg_id, self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler) handler=self.primary_bootstrap_handler)
except ConnectionClosed: except ConnectionClosed:
self.primary_master_node = None self.primary_master_node = None
...@@ -473,7 +473,7 @@ class Application(object): ...@@ -473,7 +473,7 @@ class Application(object):
Packets.AskNodeInformation()) Packets.AskNodeInformation())
finally: finally:
conn.unlock() conn.unlock()
self._waitMessage(conn, msg_id, self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler) handler=self.primary_bootstrap_handler)
conn.lock() conn.lock()
try: try:
...@@ -481,14 +481,14 @@ class Application(object): ...@@ -481,14 +481,14 @@ class Application(object):
Packets.AskPartitionTable([])) Packets.AskPartitionTable([]))
finally: finally:
conn.unlock() conn.unlock()
self._waitMessage(conn, msg_id, self._waitMessage(conn, msg_id,
handler=self.primary_bootstrap_handler) handler=self.primary_bootstrap_handler)
ready = self.uuid is not None and self.pt is not None \ ready = self.uuid is not None and self.pt is not None \
and self.pt.operational() and self.pt.operational()
logging.info("connected to primary master node %s" % logging.info("connected to primary master node %s" %
self.primary_master_node) self.primary_master_node)
return conn return conn
def registerDB(self, db, limit): def registerDB(self, db, limit):
self._db = db self._db = db
...@@ -580,9 +580,9 @@ class Application(object): ...@@ -580,9 +580,9 @@ class Application(object):
break break
if self.local_var.asked_object == 0: if self.local_var.asked_object == 0:
# We didn't got any object from all storage node because of # We didn't got any object from all storage node because of
# connection error # connection error
logging.warning('oid %s not found because of connection failure', logging.warning('oid %s not found because of connection failure',
dump(oid)) dump(oid))
raise NEOStorageNotFoundError() raise NEOStorageNotFoundError()
...@@ -658,7 +658,7 @@ class Application(object): ...@@ -658,7 +658,7 @@ class Application(object):
self._askPrimary(Packets.AskBeginTransaction(tid)) self._askPrimary(Packets.AskBeginTransaction(tid))
if self.local_var.tid is None: if self.local_var.tid is None:
raise NEOStorageError('tpc_begin failed') raise NEOStorageError('tpc_begin failed')
self.local_var.txn = transaction self.local_var.txn = transaction
def store(self, oid, serial, data, version, transaction): def store(self, oid, serial, data, version, transaction):
...@@ -680,7 +680,7 @@ class Application(object): ...@@ -680,7 +680,7 @@ class Application(object):
self.local_var.object_stored_counter = 0 self.local_var.object_stored_counter = 0
for cell in cell_list: for cell in cell_list:
conn = self.cp.getConnForCell(cell) conn = self.cp.getConnForCell(cell)
if conn is None: if conn is None:
continue continue
self.local_var.object_stored = 0 self.local_var.object_stored = 0
...@@ -696,20 +696,20 @@ class Application(object): ...@@ -696,20 +696,20 @@ class Application(object):
if self.local_var.data_dict.has_key(oid): if self.local_var.data_dict.has_key(oid):
# One storage already accept the object, is it normal ?? # One storage already accept the object, is it normal ??
# remove from dict and raise ConflictError, don't care of # remove from dict and raise ConflictError, don't care of
# previous node which already store data as it would be # previous node which already store data as it would be
# resent again if conflict is resolved or txn will be # resent again if conflict is resolved or txn will be
# aborted # aborted
del self.local_var.data_dict[oid] del self.local_var.data_dict[oid]
self.local_var.conflict_serial = self.local_var.object_stored[1] self.local_var.conflict_serial = self.local_var.object_stored[1]
raise NEOStorageConflictError raise NEOStorageConflictError
# increase counter so that we know if a node has stored the object # increase counter so that we know if a node has stored the object
# or not # or not
self.local_var.object_stored_counter += 1 self.local_var.object_stored_counter += 1
if self.local_var.object_stored_counter == 0: if self.local_var.object_stored_counter == 0:
# no storage nodes were available # no storage nodes were available
raise NEOStorageError('tpc_store failed') raise NEOStorageError('tpc_store failed')
# Store object in tmp cache # Store object in tmp cache
self.local_var.data_dict[oid] = data self.local_var.data_dict[oid] = data
...@@ -729,14 +729,14 @@ class Application(object): ...@@ -729,14 +729,14 @@ class Application(object):
cell_list = self._getCellListForTID(self.local_var.tid, writable=True) cell_list = self._getCellListForTID(self.local_var.tid, writable=True)
self.local_var.voted_counter = 0 self.local_var.voted_counter = 0
for cell in cell_list: for cell in cell_list:
logging.debug("voting object %s %s" %(cell.getAddress(), logging.debug("voting object %s %s" %(cell.getAddress(),
cell.getState())) cell.getState()))
conn = self.cp.getConnForCell(cell) conn = self.cp.getConnForCell(cell)
if conn is None: if conn is None:
continue continue
self.local_var.txn_voted = False self.local_var.txn_voted = False
p = Packets.AskStoreTransaction(self.local_var.tid, p = Packets.AskStoreTransaction(self.local_var.tid,
user, desc, ext, oid_list) user, desc, ext, oid_list)
try: try:
self._askStorage(conn, p) self._askStorage(conn, p)
...@@ -761,7 +761,7 @@ class Application(object): ...@@ -761,7 +761,7 @@ class Application(object):
for oid in self.local_var.data_dict.iterkeys(): for oid in self.local_var.data_dict.iterkeys():
cell_set |= set(self._getCellListForOID(oid, writable=True)) cell_set |= set(self._getCellListForOID(oid, writable=True))
# select nodes where transaction was stored # select nodes where transaction was stored
cell_set |= set(self._getCellListForTID(self.local_var.tid, cell_set |= set(self._getCellListForTID(self.local_var.tid,
writable=True)) writable=True))
# cancel transaction one all those nodes # cancel transaction one all those nodes
...@@ -869,12 +869,12 @@ class Application(object): ...@@ -869,12 +869,12 @@ class Application(object):
self.store(oid, transaction_id, data, None, txn) self.store(oid, transaction_id, data, None, txn)
except NEOStorageConflictError, serial: except NEOStorageConflictError, serial:
if serial <= self.local_var.tid: if serial <= self.local_var.tid:
new_data = wrapper.tryToResolveConflict(oid, new_data = wrapper.tryToResolveConflict(oid,
self.local_var.tid, serial, data) self.local_var.tid, serial, data)
if new_data is not None: if new_data is not None:
self.store(oid, self.local_var.tid, new_data, None, txn) self.store(oid, self.local_var.tid, new_data, None, txn)
continue continue
raise ConflictError(oid = oid, serials = (self.local_var.tid, raise ConflictError(oid = oid, serials = (self.local_var.tid,
serial), serial),
data = data) data = data)
return self.local_var.tid, oid_list return self.local_var.tid, oid_list
...@@ -897,7 +897,7 @@ class Application(object): ...@@ -897,7 +897,7 @@ class Application(object):
continue continue
try: try:
conn.ask(self.local_var.queue, Packets.AskTIDs(first, last, conn.ask(self.local_var.queue, Packets.AskTIDs(first, last,
protocol.INVALID_PARTITION)) protocol.INVALID_PARTITION))
finally: finally:
conn.unlock() conn.unlock()
...@@ -929,7 +929,7 @@ class Application(object): ...@@ -929,7 +929,7 @@ class Application(object):
if conn is not None: if conn is not None:
self.local_var.txn_info = 0 self.local_var.txn_info = 0
try: try:
self._askStorage(conn, self._askStorage(conn,
Packets.AskTransactionInformation(tid)) Packets.AskTransactionInformation(tid))
except ConnectionClosed: except ConnectionClosed:
continue continue
...@@ -951,7 +951,7 @@ class Application(object): ...@@ -951,7 +951,7 @@ class Application(object):
# Check we return at least one element, otherwise call # Check we return at least one element, otherwise call
# again but extend offset # again but extend offset
if len(undo_info) == 0 and not block: if len(undo_info) == 0 and not block:
undo_info = self.undoLog(first=first, last=last*5, filter=filter, undo_info = self.undoLog(first=first, last=last*5, filter=filter,
block=1) block=1)
return undo_info return undo_info
...@@ -1006,7 +1006,7 @@ class Application(object): ...@@ -1006,7 +1006,7 @@ class Application(object):
# ask transaction information # ask transaction information
self.local_var.txn_info = None self.local_var.txn_info = None
try: try:
self._askStorage(conn, self._askStorage(conn,
Packets.AskTransactionInformation(serial)) Packets.AskTransactionInformation(serial))
except ConnectionClosed: except ConnectionClosed:
continue continue
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -21,7 +21,7 @@ class NeoStorage(BaseConfig): ...@@ -21,7 +21,7 @@ class NeoStorage(BaseConfig):
def open(self): def open(self):
from Storage import Storage from Storage import Storage
return Storage(master_nodes=self.config.master_nodes, return Storage(master_nodes=self.config.master_nodes,
name=self.config.name, connector = self.config.connector) name=self.config.name, connector = self.config.connector)
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
from ZODB import POSException from ZODB import POSException
class NEOStorageError(POSException.StorageError): class NEOStorageError(POSException.StorageError):
pass pass
class NEOStorageConflictError(NEOStorageError): class NEOStorageConflictError(NEOStorageError):
pass pass
class NEOStorageNotFoundError(NEOStorageError): class NEOStorageNotFoundError(NEOStorageError):
pass pass
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -54,7 +54,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -54,7 +54,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
# got an uuid from the primary master # got an uuid from the primary master
app.uuid = your_uuid app.uuid = your_uuid
# Always create partition table # Always create partition table
app.pt = PartitionTable(num_partitions, num_replicas) app.pt = PartitionTable(num_partitions, num_replicas)
def answerPrimary(self, conn, packet, primary_uuid, def answerPrimary(self, conn, packet, primary_uuid,
...@@ -85,13 +85,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -85,13 +85,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
# The primary master node is not a primary master node # The primary master node is not a primary master node
# any longer. # any longer.
app.primary_master_node = None app.primary_master_node = None
app.trying_master_node = None app.trying_master_node = None
conn.close() conn.close()
def answerPartitionTable(self, conn, packet, ptid, row_list): def answerPartitionTable(self, conn, packet, ptid, row_list):
pass pass
def answerNodeInformation(self, conn, packet): def answerNodeInformation(self, conn, packet):
pass pass
...@@ -106,7 +106,7 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -106,7 +106,7 @@ class PrimaryNotificationsHandler(BaseHandler):
app.master_conn = None app.master_conn = None
app.primary_master_node = None app.primary_master_node = None
else: else:
logging.warn('app.master_conn is %s, but we are closing %s', logging.warn('app.master_conn is %s, but we are closing %s',
app.master_conn, conn) app.master_conn, conn)
super(PrimaryNotificationsHandler, self).connectionClosed(conn) super(PrimaryNotificationsHandler, self).connectionClosed(conn)
...@@ -146,7 +146,7 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -146,7 +146,7 @@ class PrimaryNotificationsHandler(BaseHandler):
finally: finally:
app._cache_lock_release() app._cache_lock_release()
# For the two methods below, we must not use app._getPartitionTable() # For the two methods below, we must not use app._getPartitionTable()
# to avoid a dead lock. It is safe to not check the master connection # to avoid a dead lock. It is safe to not check the master connection
# because it's in the master handler, so the connection is already # because it's in the master handler, so the connection is already
# established. # established.
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -29,7 +29,7 @@ class StorageEventHandler(BaseHandler): ...@@ -29,7 +29,7 @@ class StorageEventHandler(BaseHandler):
assert node is not None assert node is not None
# Remove from pool connection # Remove from pool connection
app.cp.removeConnection(node) app.cp.removeConnection(node)
app.dispatcher.unregister(conn) app.dispatcher.unregister(conn)
def connectionLost(self, conn, new_state): def connectionLost(self, conn, new_state):
self._dealWithStorageFailure(conn) self._dealWithStorageFailure(conn)
...@@ -51,7 +51,7 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -51,7 +51,7 @@ class StorageBootstrapHandler(AnswerBaseHandler):
def notReady(self, conn, packet, message): def notReady(self, conn, packet, message):
app = self.app app = self.app
app.setNodeNotReady() app.setNodeNotReady()
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
...@@ -74,11 +74,11 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -74,11 +74,11 @@ class StorageBootstrapHandler(AnswerBaseHandler):
class StorageAnswersHandler(AnswerBaseHandler): class StorageAnswersHandler(AnswerBaseHandler):
""" Handle all messages related to ZODB operations """ """ Handle all messages related to ZODB operations """
def answerObject(self, conn, packet, oid, start_serial, end_serial, def answerObject(self, conn, packet, oid, start_serial, end_serial,
compression, checksum, data): compression, checksum, data):
app = self.app app = self.app
app.local_var.asked_object = (oid, start_serial, end_serial, app.local_var.asked_object = (oid, start_serial, end_serial,
compression, checksum, data) compression, checksum, data)
def answerStoreObject(self, conn, packet, conflicting, oid, serial): def answerStoreObject(self, conn, packet, conflicting, oid, serial):
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
...@@ -37,12 +37,12 @@ class Element(object): ...@@ -37,12 +37,12 @@ class Element(object):
This class defines an element of a FIFO buffer. This class defines an element of a FIFO buffer.
""" """
pass pass
class FIFO(object): class FIFO(object):
""" """
This class implements a FIFO buffer. This class implements a FIFO buffer.
""" """
def __init__(self): def __init__(self):
self._head = None self._head = None
self._tail = None self._tail = None
...@@ -56,10 +56,10 @@ class FIFO(object): ...@@ -56,10 +56,10 @@ class FIFO(object):
self.element = None self.element = None
self.key = None self.key = None
self.expire_time = None self.expire_time = None
def __len__(self): def __len__(self):
return self._len return self._len
def append(self): def append(self):
element = Element() element = Element()
element.next = None element.next = None
...@@ -74,10 +74,10 @@ class FIFO(object): ...@@ -74,10 +74,10 @@ class FIFO(object):
def head(self): def head(self):
return self._head return self._head
def tail(self): def tail(self):
return self._tail return self._tail
def shift(self): def shift(self):
element = self._head element = self._head
if element is None: if element is None:
...@@ -86,26 +86,26 @@ class FIFO(object): ...@@ -86,26 +86,26 @@ class FIFO(object):
del element.next del element.next
del element.prev del element.prev
return element return element
def __delitem__(self, element): def __delitem__(self, element):
if element.next is None: if element.next is None:
self._tail = element.prev self._tail = element.prev
else: else:
element.next.prev = element.prev element.next.prev = element.prev
if element.prev is None: if element.prev is None:
self._head = element.next self._head = element.next
else: else:
element.prev.next = element.next element.prev.next = element.next
self._len -= 1 self._len -= 1
class Data(object): class Data(object):
""" """
Data for each element in a FIFO buffer. Data for each element in a FIFO buffer.
""" """
pass pass
def sizeof(o): def sizeof(o):
"""This function returns the estimated size of an object.""" """This function returns the estimated size of an object."""
if isinstance(o, tuple): if isinstance(o, tuple):
...@@ -116,22 +116,22 @@ def sizeof(o): ...@@ -116,22 +116,22 @@ def sizeof(o):
class MQ(object): class MQ(object):
""" """
This class manages cached data by a variant of Multi-Queue. This class manages cached data by a variant of Multi-Queue.
This class caches various sizes of objects. Here are some considerations: This class caches various sizes of objects. Here are some considerations:
- Expired objects are not really deleted immediately. But if GC is invoked too often, - Expired objects are not really deleted immediately. But if GC is invoked too often,
it degrades the performance significantly. it degrades the performance significantly.
- If large objects are cached, the number of cached objects decreases. This might affect - If large objects are cached, the number of cached objects decreases. This might affect
the cache hit ratio. It might be better to tweak a buffer level according to the size of the cache hit ratio. It might be better to tweak a buffer level according to the size of
an object. an object.
- Stored values must be strings. - Stored values must be strings.
- The size calculation is not accurate. - The size calculation is not accurate.
""" """
def __init__(self, life_time=10000, buffer_levels=9, def __init__(self, life_time=10000, buffer_levels=9,
max_history_size=100000, max_size=20*1024*1024): max_history_size=100000, max_size=20*1024*1024):
self._history_buffer = FIFO() self._history_buffer = FIFO()
self._cache_buffers = [] self._cache_buffers = []
...@@ -144,16 +144,16 @@ class MQ(object): ...@@ -144,16 +144,16 @@ class MQ(object):
self._max_history_size = max_history_size self._max_history_size = max_history_size
self._max_size = max_size self._max_size = max_size
self._size = 0 self._size = 0
def has_key(self, key): def has_key(self, key):
if key in self._data: if key in self._data:
data = self._data[key] data = self._data[key]
if data.level >= 0: if data.level >= 0:
return 1 return 1
return 0 return 0
__contains__ = has_key __contains__ = has_key
def fetch(self, key): def fetch(self, key):
""" """
Fetch a value associated with the key. Fetch a value associated with the key.
...@@ -165,15 +165,15 @@ class MQ(object): ...@@ -165,15 +165,15 @@ class MQ(object):
self.store(key, value) self.store(key, value)
return value return value
raise KeyError(key) raise KeyError(key)
__getitem__ = fetch __getitem__ = fetch
def get(self, key, d=None): def get(self, key, d=None):
try: try:
return self.fetch(key) return self.fetch(key)
except KeyError: except KeyError:
return d return d
def _evict(self, key): def _evict(self, key):
""" """
Evict an element to the history buffer. Evict an element to the history buffer.
...@@ -190,7 +190,7 @@ class MQ(object): ...@@ -190,7 +190,7 @@ class MQ(object):
if len(self._history_buffer) > self._max_history_size: if len(self._history_buffer) > self._max_history_size:
element = self._history_buffer.shift() element = self._history_buffer.shift()
del self._data[element.data.key] del self._data[element.data.key]
def store(self, key, value): def store(self, key, value):
cache_buffers = self._cache_buffers cache_buffers = self._cache_buffers
...@@ -203,8 +203,8 @@ class MQ(object): ...@@ -203,8 +203,8 @@ class MQ(object):
del self._history_buffer[element] del self._history_buffer[element]
except KeyError: except KeyError:
counter = 1 counter = 1
# XXX It might be better to adjust the level according to the object # XXX It might be better to adjust the level according to the object
# size. # size.
level = min(int(log(counter, 2)), self._buffer_levels - 1) level = min(int(log(counter, 2)), self._buffer_levels - 1)
element = cache_buffers[level].append() element = cache_buffers[level].append()
...@@ -219,7 +219,7 @@ class MQ(object): ...@@ -219,7 +219,7 @@ class MQ(object):
self._data[key] = data self._data[key] = data
self._size += sizeof(value) self._size += sizeof(value)
del value del value
self._time += 1 self._time += 1
# Expire old elements. # Expire old elements.
...@@ -239,7 +239,7 @@ class MQ(object): ...@@ -239,7 +239,7 @@ class MQ(object):
data.element = element data.element = element
else: else:
self._evict(data.key) self._evict(data.key)
# Limit the size. # Limit the size.
size = self._size size = self._size
max_size = self._max_size max_size = self._max_size
...@@ -256,9 +256,9 @@ class MQ(object): ...@@ -256,9 +256,9 @@ class MQ(object):
if size <= max_size: if size <= max_size:
break break
self._size = size self._size = size
__setitem__ = store __setitem__ = store
def invalidate(self, key): def invalidate(self, key):
if id in self._data: if id in self._data:
data = self._data[key] data = self._data[key]
...@@ -269,14 +269,14 @@ class MQ(object): ...@@ -269,14 +269,14 @@ class MQ(object):
raise KeyError, "%s was not found in the cache" % key raise KeyError, "%s was not found in the cache" % key
__delitem__ = invalidate __delitem__ = invalidate
# Here is a test. # Here is a test.
if __name__ == '__main__': if __name__ == '__main__':
import hotshot, hotshot.stats import hotshot, hotshot.stats
def test(): def test():
cache = MQ(life_time=100, buffer_levels=9, max_history_size=10000, cache = MQ(life_time=100, buffer_levels=9, max_history_size=10000,
max_size=2*1024*1024) max_size=2*1024*1024)
for i in xrange(10000): for i in xrange(10000):
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -20,7 +20,7 @@ from neo.util import bin, parseMasterList ...@@ -20,7 +20,7 @@ from neo.util import bin, parseMasterList
class ConfigurationManager(object): class ConfigurationManager(object):
""" """
Configuration manager that load options from a configuration file and Configuration manager that load options from a configuration file and
command line arguments command line arguments
""" """
...@@ -52,7 +52,7 @@ class ConfigurationManager(object): ...@@ -52,7 +52,7 @@ class ConfigurationManager(object):
return [] return []
# load master node list except itself # load master node list except itself
return parseMasterList(masters, except_node=self.getBind()) return parseMasterList(masters, except_node=self.getBind())
def getBind(self): def getBind(self):
""" Get the address to bind to """ """ Get the address to bind to """
bind = self.__get('bind') bind = self.__get('bind')
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -70,9 +70,9 @@ class BaseConnection(object): ...@@ -70,9 +70,9 @@ class BaseConnection(object):
if connector is not None: if connector is not None:
self.connector_handler = connector.__class__ self.connector_handler = connector.__class__
event_manager.register(self) event_manager.register(self)
else: else:
self.connector_handler = connector_handler self.connector_handler = connector_handler
def lock(self): def lock(self):
return 1 return 1
...@@ -104,7 +104,7 @@ class BaseConnection(object): ...@@ -104,7 +104,7 @@ class BaseConnection(object):
if self.connector is not None: if self.connector is not None:
em.removeReader(self) em.removeReader(self)
em.removeWriter(self) em.removeWriter(self)
em.unregister(self) em.unregister(self)
self.connector.shutdown() self.connector.shutdown()
self.connector.close() self.connector.close()
self.connector = None self.connector = None
...@@ -202,7 +202,7 @@ class Connection(BaseConnection): ...@@ -202,7 +202,7 @@ class Connection(BaseConnection):
return next_id return next_id
def close(self): def close(self):
logging.debug('closing a connector for %s (%s:%d)', logging.debug('closing a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr)) dump(self.uuid), *(self.addr))
BaseConnection.close(self) BaseConnection.close(self)
for event in self.event_dict.itervalues(): for event in self.event_dict.itervalues():
...@@ -213,7 +213,7 @@ class Connection(BaseConnection): ...@@ -213,7 +213,7 @@ class Connection(BaseConnection):
def abort(self): def abort(self):
"""Abort dealing with this connection.""" """Abort dealing with this connection."""
logging.debug('aborting a connector for %s (%s:%d)', logging.debug('aborting a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr)) dump(self.uuid), *(self.addr))
self.aborted = True self.aborted = True
...@@ -307,14 +307,14 @@ class Connection(BaseConnection): ...@@ -307,14 +307,14 @@ class Connection(BaseConnection):
self.handler.connectionClosed(self) self.handler.connectionClosed(self)
return return
self.read_buf += data self.read_buf += data
except ConnectorTryAgainException: except ConnectorTryAgainException:
pass pass
except ConnectorConnectionRefusedException: except ConnectorConnectionRefusedException:
# should only occur while connecting # should only occur while connecting
self.close() self.close()
self.handler.connectionFailed(self) self.handler.connectionFailed(self)
except ConnectorConnectionClosedException: except ConnectorConnectionClosedException:
# connection resetted by peer, according to the man, this error # connection resetted by peer, according to the man, this error
# should not occurs but it seems it's false # should not occurs but it seems it's false
logging.debug('Connection reset by peer: %r', self.connector) logging.debug('Connection reset by peer: %r', self.connector)
self.close() self.close()
...@@ -350,7 +350,7 @@ class Connection(BaseConnection): ...@@ -350,7 +350,7 @@ class Connection(BaseConnection):
# unhandled connector exception # unhandled connector exception
self.close() self.close()
self.handler.connectionClosed(self) self.handler.connectionClosed(self)
raise raise
def _addPacket(self, packet): def _addPacket(self, packet):
"""Add a packet into the write buffer.""" """Add a packet into the write buffer."""
...@@ -405,8 +405,8 @@ class Connection(BaseConnection): ...@@ -405,8 +405,8 @@ class Connection(BaseConnection):
@not_closed @not_closed
def ask(self, packet, timeout=5, additional_timeout=30): def ask(self, packet, timeout=5, additional_timeout=30):
""" """
Send a packet with a new ID and register the expectation of an answer Send a packet with a new ID and register the expectation of an answer
""" """
msg_id = self._getNextId() msg_id = self._getNextId()
packet.setId(msg_id) packet.setId(msg_id)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -52,13 +52,13 @@ class SocketConnector: ...@@ -52,13 +52,13 @@ class SocketConnector:
self.remote_addr = accepted_from self.remote_addr = accepted_from
self.is_listening = False self.is_listening = False
self.is_closed = False self.is_closed = False
if s is None: if s is None:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
else: else:
self.socket = s self.socket = s
# always use non-blocking sockets # always use non-blocking sockets
self.socket.setblocking(0) self.socket.setblocking(0)
def makeClientConnection(self, addr): def makeClientConnection(self, addr):
self.is_closed = False self.is_closed = False
self.remote_addr = addr self.remote_addr = addr
...@@ -92,8 +92,8 @@ class SocketConnector: ...@@ -92,8 +92,8 @@ class SocketConnector:
return self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) return self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
def getDescriptor(self): def getDescriptor(self):
# this descriptor must only be used by the event manager, where it # this descriptor must only be used by the event manager, where it
# guarantee unicity only while the connector is opened and registered # guarantee unicity only while the connector is opened and registered
# in epoll # in epoll
return self.socket.fileno() return self.socket.fileno()
...@@ -135,7 +135,7 @@ class SocketConnector: ...@@ -135,7 +135,7 @@ class SocketConnector:
raise ConnectorTryAgainException raise ConnectorTryAgainException
if err == errno.ECONNRESET: if err == errno.ECONNRESET:
raise ConnectorConnectionClosedException raise ConnectorConnectionClosedException
raise ConnectorException, 'send failed: %s:%s' % (err, errmsg) raise ConnectorException, 'send failed: %s:%s' % (err, errmsg)
def close(self): def close(self):
self.is_closed = True self.is_closed = True
...@@ -167,18 +167,18 @@ class SocketConnector: ...@@ -167,18 +167,18 @@ class SocketConnector:
registerConnectorHandler(SocketConnector) registerConnectorHandler(SocketConnector)
class ConnectorException(Exception): class ConnectorException(Exception):
pass pass
class ConnectorTryAgainException(ConnectorException): class ConnectorTryAgainException(ConnectorException):
pass pass
class ConnectorInProgressException(ConnectorException): class ConnectorInProgressException(ConnectorException):
pass pass
class ConnectorConnectionClosedException(ConnectorException): class ConnectorConnectionClosedException(ConnectorException):
pass pass
class ConnectorConnectionRefusedException(ConnectorException): class ConnectorConnectionRefusedException(ConnectorException):
pass pass
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -81,7 +81,7 @@ class Epoll(object): ...@@ -81,7 +81,7 @@ class Epoll(object):
timeout *= 1000 timeout *= 1000
timeout = int(timeout) timeout = int(timeout)
while 1: while 1:
n = epoll_wait(self.efd, byref(self.events), self.maxevents, n = epoll_wait(self.efd, byref(self.events), self.maxevents,
timeout) timeout)
if n == -1: if n == -1:
e = errno.value e = errno.value
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -52,7 +52,7 @@ class IdleEvent(object): ...@@ -52,7 +52,7 @@ class IdleEvent(object):
# long, although being responsive at network level. # long, although being responsive at network level.
conn.lock() conn.lock()
try: try:
logging.info('timeout for %r with %s:%d', logging.info('timeout for %r with %s:%d',
self._id, *(conn.getAddress())) self._id, *(conn.getAddress()))
conn.close() conn.close()
conn.getHandler().timeoutExpired(conn) conn.getHandler().timeoutExpired(conn)
...@@ -143,7 +143,7 @@ class SelectEventManager(object): ...@@ -143,7 +143,7 @@ class SelectEventManager(object):
self._addPendingConnection(to_process) self._addPendingConnection(to_process)
def _poll(self, timeout = 1): def _poll(self, timeout = 1):
rlist, wlist, xlist = select(self.reader_set, self.writer_set, rlist, wlist, xlist = select(self.reader_set, self.writer_set,
self.exc_list, timeout) self.exc_list, timeout)
for s in rlist: for s in rlist:
conn = self.connection_dict[s] conn = self.connection_dict[s]
...@@ -175,7 +175,7 @@ class SelectEventManager(object): ...@@ -175,7 +175,7 @@ class SelectEventManager(object):
t = time() t = time()
if t - self.prev_time >= 1: if t - self.prev_time >= 1:
self.prev_time = t self.prev_time = t
event_list.sort(key = lambda event: event.getTime(), event_list.sort(key = lambda event: event.getTime(),
reverse = True) reverse = True)
while event_list: while event_list:
event = event_list.pop() event = event_list.pop()
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -15,20 +15,20 @@ ...@@ -15,20 +15,20 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class NeoException(Exception): class NeoException(Exception):
pass pass
class ElectionFailure(NeoException): class ElectionFailure(NeoException):
pass pass
class PrimaryFailure(NeoException): class PrimaryFailure(NeoException):
pass pass
class VerificationFailure(NeoException): class VerificationFailure(NeoException):
pass pass
class OperationFailure(NeoException): class OperationFailure(NeoException):
pass pass
class DatabaseFailure(NeoException): class DatabaseFailure(NeoException):
pass pass
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -34,10 +34,10 @@ class EventHandler(object): ...@@ -34,10 +34,10 @@ class EventHandler(object):
"""Called when a packet is malformed.""" """Called when a packet is malformed."""
args = (conn.getAddress()[0], conn.getAddress()[1], message) args = (conn.getAddress()[0], conn.getAddress()[1], message)
if packet is None: if packet is None:
# if decoding fail, there's no packet instance # if decoding fail, there's no packet instance
logging.error('malformed packet from %s:%d: %s', *args) logging.error('malformed packet from %s:%d: %s', *args)
else: else:
logging.error('malformed packet %s from %s:%d: %s', logging.error('malformed packet %s from %s:%d: %s',
packet.getType(), *args) packet.getType(), *args)
response = protocol.protocolError(message) response = protocol.protocolError(message)
if packet is not None: if packet is not None:
...@@ -270,7 +270,7 @@ class EventHandler(object): ...@@ -270,7 +270,7 @@ class EventHandler(object):
def askTransactionInformation(self, conn, packet, tid): def askTransactionInformation(self, conn, packet, tid):
raise UnexpectedPacketError raise UnexpectedPacketError
def answerTransactionInformation(self, conn, packet, tid, def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list): user, desc, ext, oid_list):
raise UnexpectedPacketError raise UnexpectedPacketError
......
...@@ -48,7 +48,7 @@ class LockUser(object): ...@@ -48,7 +48,7 @@ class LockUser(object):
return isinstance(other, self.__class__) and self.ident == other.ident return isinstance(other, self.__class__) and self.ident == other.ident
def __repr__(self): def __repr__(self):
return '%s@%s:%s %s' % (self.ident, self.caller[0], self.caller[1], return '%s@%s:%s %s' % (self.ident, self.caller[0], self.caller[1],
self.caller[3]) self.caller[3])
def formatStack(self): def formatStack(self):
...@@ -60,7 +60,7 @@ class VerboseLockBase(object): ...@@ -60,7 +60,7 @@ class VerboseLockBase(object):
self.debug_lock = debug_lock self.debug_lock = debug_lock
self.owner = None self.owner = None
self.waiting = [] self.waiting = []
self._note('%s@%X created by %r', self.__class__.__name__, id(self), self._note('%s@%X created by %r', self.__class__.__name__, id(self),
LockUser(1)) LockUser(1))
def _note(self, fmt, *args): def _note(self, fmt, *args):
...@@ -85,7 +85,7 @@ class VerboseLockBase(object): ...@@ -85,7 +85,7 @@ class VerboseLockBase(object):
self._note('[%r]%s.acquire(%s): Deadlock detected: ' \ self._note('[%r]%s.acquire(%s): Deadlock detected: ' \
' I already own this lock:%r', me, self, blocking, owner) ' I already own this lock:%r', me, self, blocking, owner)
else: else:
self._note('[%r]%s.acquire(%s): debug lock triggered: %r', self._note('[%r]%s.acquire(%s): debug lock triggered: %r',
me, self, blocking, owner) me, self, blocking, owner)
self._note('Owner traceback:\n%s', owner.formatStack()) self._note('Owner traceback:\n%s', owner.formatStack())
self._note('My traceback:\n%s', me.formatStack()) self._note('My traceback:\n%s', me.formatStack())
...@@ -95,7 +95,7 @@ class VerboseLockBase(object): ...@@ -95,7 +95,7 @@ class VerboseLockBase(object):
finally: finally:
self.owner = me self.owner = me
self.waiting.remove(me) self.waiting.remove(me)
self._note('[%r]%s.acquire(%s) Lock granted. Waiting: %r', self._note('[%r]%s.acquire(%s) Lock granted. Waiting: %r',
me, self, blocking, self.waiting) me, self, blocking, self.waiting)
def release(self): def release(self):
...@@ -111,7 +111,7 @@ class VerboseLockBase(object): ...@@ -111,7 +111,7 @@ class VerboseLockBase(object):
class VerboseRLock(VerboseLockBase): class VerboseRLock(VerboseLockBase):
def __init__(self, verbose=None, debug_lock=False): def __init__(self, verbose=None, debug_lock=False):
super(VerboseRLock, self).__init__(reentrant=True, super(VerboseRLock, self).__init__(reentrant=True,
debug_lock=debug_lock) debug_lock=debug_lock)
self.lock = threading_RLock() self.lock = threading_RLock()
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -28,7 +28,7 @@ class PacketLogger(EventHandler): ...@@ -28,7 +28,7 @@ class PacketLogger(EventHandler):
def dispatch(self, conn, packet, direction): def dispatch(self, conn, packet, direction):
"""This is a helper method to handle various packet types.""" """This is a helper method to handle various packet types."""
# default log message # default log message
klass = packet.getType() klass = packet.getType()
uuid = dump(conn.getUUID()) uuid = dump(conn.getUUID())
ip, port = conn.getAddress() ip, port = conn.getAddress()
...@@ -188,7 +188,7 @@ class PacketLogger(EventHandler): ...@@ -188,7 +188,7 @@ class PacketLogger(EventHandler):
def askTransactionInformation(self, conn, packet, tid): def askTransactionInformation(self, conn, packet, tid):
pass pass
def answerTransactionInformation(self, conn, packet, tid, def answerTransactionInformation(self, conn, packet, tid,
user, desc, ext, oid_list): user, desc, ext, oid_list):
pass pass
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -73,7 +73,7 @@ class Application(object): ...@@ -73,7 +73,7 @@ class Application(object):
self.cluster_state = None self.cluster_state = None
# Generate an UUID for self # Generate an UUID for self
uuid = config.getUUID() uuid = config.getUUID()
if uuid is None or uuid == '': if uuid is None or uuid == '':
uuid = self.getNewUUID(NodeTypes.MASTER) uuid = self.getNewUUID(NodeTypes.MASTER)
self.uuid = uuid self.uuid = uuid
...@@ -105,7 +105,7 @@ class Application(object): ...@@ -105,7 +105,7 @@ class Application(object):
self.nm.createMaster(address=address) self.nm.createMaster(address=address)
# Make a listening port. # Make a listening port.
self.listening_conn = ListeningConnection(self.em, None, self.listening_conn = ListeningConnection(self.em, None,
addr = self.server, connector_handler = self.connector_handler) addr = self.server, connector_handler = self.connector_handler)
self.cluster_state = ClusterStates.BOOTING self.cluster_state = ClusterStates.BOOTING
...@@ -157,7 +157,7 @@ class Application(object): ...@@ -157,7 +157,7 @@ class Application(object):
if node.isRunning(): if node.isRunning():
self.unconnected_master_node_set.add(node.getAddress()) self.unconnected_master_node_set.add(node.getAddress())
# Wait at most 20 seconds at bootstrap. Otherwise, wait at most # Wait at most 20 seconds at bootstrap. Otherwise, wait at most
# 10 seconds to avoid stopping the whole cluster for a long time. # 10 seconds to avoid stopping the whole cluster for a long time.
# Note that even if not all master are up in the first 20 seconds # Note that even if not all master are up in the first 20 seconds
# this is not an issue because the first up will timeout and take # this is not an issue because the first up will timeout and take
...@@ -227,7 +227,7 @@ class Application(object): ...@@ -227,7 +227,7 @@ class Application(object):
if conn.getAddress() != addr: if conn.getAddress() != addr:
conn.close() conn.close()
# But if there is no such connection, something wrong # But if there is no such connection, something wrong
# happened. # happened.
for conn in em.getClientList(): for conn in em.getClientList():
if conn.getAddress() == addr: if conn.getAddress() == addr:
...@@ -326,7 +326,7 @@ class Application(object): ...@@ -326,7 +326,7 @@ class Application(object):
row_list.append((offset, self.pt.getRow(offset))) row_list.append((offset, self.pt.getRow(offset)))
# Split the packet if too huge. # Split the packet if too huge.
if len(row_list) == 1000: if len(row_list) == 1000:
conn.notify(Packets.SendPartitionTable(self.pt.getID(), conn.notify(Packets.SendPartitionTable(self.pt.getID(),
row_list)) row_list))
del row_list[:] del row_list[:]
if row_list: if row_list:
...@@ -373,16 +373,16 @@ class Application(object): ...@@ -373,16 +373,16 @@ class Application(object):
def recoverStatus(self): def recoverStatus(self):
""" """
Recover the status about the cluster. Obtain the last OID, the last Recover the status about the cluster. Obtain the last OID, the last
TID, and the last Partition Table ID from storage nodes, then get TID, and the last Partition Table ID from storage nodes, then get
back the latest partition table or make a new table from scratch, back the latest partition table or make a new table from scratch,
if this is the first time. if this is the first time.
""" """
logging.info('begin the recovery of the status') logging.info('begin the recovery of the status')
self.changeClusterState(ClusterStates.RECOVERING) self.changeClusterState(ClusterStates.RECOVERING)
em = self.em em = self.em
self.loid = None self.loid = None
self.ltid = None self.ltid = None
self.pt.setID(None) self.pt.setID(None)
...@@ -565,7 +565,7 @@ class Application(object): ...@@ -565,7 +565,7 @@ class Application(object):
self.changeClusterState(ClusterStates.RUNNING) self.changeClusterState(ClusterStates.RUNNING)
# This dictionary is used to hold information on transactions being # This dictionary is used to hold information on transactions being
# finished. # finished.
self.finishing_transaction_dict = {} self.finishing_transaction_dict = {}
...@@ -574,12 +574,12 @@ class Application(object): ...@@ -574,12 +574,12 @@ class Application(object):
try: try:
em.poll(1) em.poll(1)
except OperationFailure: except OperationFailure:
# If not operational, send Stop Operation packets to storage # If not operational, send Stop Operation packets to storage
# nodes and client nodes. Abort connections to client nodes. # nodes and client nodes. Abort connections to client nodes.
logging.critical('No longer operational, stopping the service') logging.critical('No longer operational, stopping the service')
for conn in em.getConnectionList(): for conn in em.getConnectionList():
node = nm.getByUUID(conn.getUUID()) node = nm.getByUUID(conn.getUUID())
if node is not None and (node.isStorage() if node is not None and (node.isStorage()
or node.isClient()): or node.isClient()):
conn.notify(Packets.StopOperation()) conn.notify(Packets.StopOperation())
if node.isClient(): if node.isClient():
...@@ -589,7 +589,7 @@ class Application(object): ...@@ -589,7 +589,7 @@ class Application(object):
return return
def playPrimaryRole(self): def playPrimaryRole(self):
logging.info('play the primary role with %s (%s:%d)', logging.info('play the primary role with %s (%s:%d)',
dump(self.uuid), *(self.server)) dump(self.uuid), *(self.server))
# all incoming connections identify through this handler # all incoming connections identify through this handler
...@@ -610,7 +610,7 @@ class Application(object): ...@@ -610,7 +610,7 @@ class Application(object):
conn.setHandler(handler) conn.setHandler(handler)
# If I know any storage node, make sure that they are not in the # If I know any storage node, make sure that they are not in the
# running state, because they are not connected at this stage. # running state, because they are not connected at this stage.
for node in nm.getStorageList(): for node in nm.getStorageList():
if node.isRunning(): if node.isRunning():
...@@ -630,7 +630,7 @@ class Application(object): ...@@ -630,7 +630,7 @@ class Application(object):
""" """
I play a secondary role, thus only wait for a primary master to fail. I play a secondary role, thus only wait for a primary master to fail.
""" """
logging.info('play the secondary role with %s (%s:%d)', logging.info('play the secondary role with %s (%s:%d)',
dump(self.uuid), *(self.server)) dump(self.uuid), *(self.server))
...@@ -647,8 +647,8 @@ class Application(object): ...@@ -647,8 +647,8 @@ class Application(object):
self.em.poll(1) self.em.poll(1)
def changeClusterState(self, state): def changeClusterState(self, state):
""" """
Change the cluster state and apply right handler on each connections Change the cluster state and apply right handler on each connections
""" """
if self.cluster_state == state: if self.cluster_state == state:
return return
...@@ -737,7 +737,7 @@ class Application(object): ...@@ -737,7 +737,7 @@ class Application(object):
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
node = self.nm.getByUUID(c.getUUID()) node = self.nm.getByUUID(c.getUUID())
if node.isClient(): if node.isClient():
node_list = [(node.getType(), node.getAddress(), node_list = [(node.getType(), node.getAddress(),
node.getUUID(), NodeStates.DOWN)] node.getUUID(), NodeStates.DOWN)]
c.notify(Packets.NotifyNodeInformation(node_list)) c.notify(Packets.NotifyNodeInformation(node_list))
# then ask storages and master nodes to shutdown # then ask storages and master nodes to shutdown
...@@ -745,7 +745,7 @@ class Application(object): ...@@ -745,7 +745,7 @@ class Application(object):
for c in self.em.getConnectionList(): for c in self.em.getConnectionList():
node = self.nm.getByUUID(c.getUUID()) node = self.nm.getByUUID(c.getUUID())
if node.isStorage() or node.isMaster(): if node.isStorage() or node.isMaster():
node_list = [(node.getType(), node.getAddress(), node_list = [(node.getType(), node.getAddress(),
node.getUUID(), NodeStates.DOWN)] node.getUUID(), NodeStates.DOWN)]
c.notify(Packets.NotifyNodeInformation(node_list)) c.notify(Packets.NotifyNodeInformation(node_list))
# then shutdown # then shutdown
...@@ -764,7 +764,7 @@ class Application(object): ...@@ -764,7 +764,7 @@ class Application(object):
# if node is unknown, it has been forget when the current # if node is unknown, it has been forget when the current
# partition was validated by the admin # partition was validated by the admin
# Here the uuid is not cleared to allow lookup pending nodes by # Here the uuid is not cleared to allow lookup pending nodes by
# uuid from the test framework. It's safe since nodes with a # uuid from the test framework. It's safe since nodes with a
# conflicting UUID are rejected in the identification handler. # conflicting UUID are rejected in the identification handler.
state = NodeStates.PENDING state = NodeStates.PENDING
handler = verification.VerificationHandler handler = verification.VerificationHandler
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -86,7 +86,7 @@ class BaseServiceHandler(MasterHandler): ...@@ -86,7 +86,7 @@ class BaseServiceHandler(MasterHandler):
node = self.app.nm.getByUUID(conn.getUUID()) node = self.app.nm.getByUUID(conn.getUUID())
assert node is not None assert node is not None
if new_state != NodeStates.BROKEN: if new_state != NodeStates.BROKEN:
new_state = DISCONNECTED_STATE_DICT.get(node.getType(), new_state = DISCONNECTED_STATE_DICT.get(node.getType(),
NodeStates.DOWN) NodeStates.DOWN)
if node.getState() == new_state: if node.getState() == new_state:
return return
......
...@@ -43,7 +43,7 @@ class AdministrationHandler(MasterHandler): ...@@ -43,7 +43,7 @@ class AdministrationHandler(MasterHandler):
self.app.shutdown() self.app.shutdown()
def setNodeState(self, conn, packet, uuid, state, modify_partition_table): def setNodeState(self, conn, packet, uuid, state, modify_partition_table):
logging.info("set node state for %s-%s : %s" % logging.info("set node state for %s-%s : %s" %
(dump(uuid), state, modify_partition_table)) (dump(uuid), state, modify_partition_table))
app = self.app app = self.app
node = app.nm.getByUUID(uuid) node = app.nm.getByUUID(uuid)
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -125,7 +125,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -125,7 +125,7 @@ class ClientElectionHandler(ElectionHandler):
if conn.getAddress() != address: if conn.getAddress() != address:
# The server address is different! Then why was # The server address is different! Then why was
# the connection successful? # the connection successful?
logging.error('%s:%d is waiting for %s:%d', logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address) conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node) app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress()) app.negotiating_master_node_set.discard(node.getAddress())
...@@ -171,7 +171,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -171,7 +171,7 @@ class ClientElectionHandler(ElectionHandler):
# told me at the moment. # told me at the moment.
if n.getUUID() is None or n.getUUID() != uuid: if n.getUUID() is None or n.getUUID() != uuid:
n.setUUID(uuid) n.setUUID(uuid)
if primary_uuid is not None: if primary_uuid is not None:
# The primary master is defined. # The primary master is defined.
if app.primary_master_node is not None \ if app.primary_master_node is not None \
...@@ -200,8 +200,8 @@ class ClientElectionHandler(ElectionHandler): ...@@ -200,8 +200,8 @@ class ClientElectionHandler(ElectionHandler):
# Request a node idenfitication. # Request a node idenfitication.
conn.ask(Packets.RequestIdentification( conn.ask(Packets.RequestIdentification(
NodeTypes.MASTER, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server, app.server,
app.name app.name
)) ))
...@@ -251,11 +251,11 @@ class ServerElectionHandler(ElectionHandler): ...@@ -251,11 +251,11 @@ class ServerElectionHandler(ElectionHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
p = Packets.AcceptIdentification( p = Packets.AcceptIdentification(
NodeTypes.MASTER, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server, app.server,
app.pt.getPartitions(), app.pt.getPartitions(),
app.pt.getReplicas(), app.pt.getReplicas(),
uuid uuid
) )
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -57,9 +57,9 @@ class IdentificationHandler(MasterHandler): ...@@ -57,9 +57,9 @@ class IdentificationHandler(MasterHandler):
node.setAddress(address) node.setAddress(address)
node.setRunning() node.setRunning()
# ask the app the node identification, if refused, an exception is # ask the app the node identification, if refused, an exception is
# raised # raised
result = self.app.identifyNode(node_type, uuid, node) result = self.app.identifyNode(node_type, uuid, node)
(uuid, node, state, handler, node_ctor) = result (uuid, node, state, handler, node_ctor) = result
if uuid is None: if uuid is None:
# no valid uuid, give it one # no valid uuid, give it one
...@@ -75,7 +75,7 @@ class IdentificationHandler(MasterHandler): ...@@ -75,7 +75,7 @@ class IdentificationHandler(MasterHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
conn.setHandler(handler) conn.setHandler(handler)
# answer # answer
args = (NodeTypes.MASTER, app.uuid, app.server, args = (NodeTypes.MASTER, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getPartitions(), app.pt.getReplicas(), uuid)
conn.answer(Packets.AcceptIdentification(*args), packet.getId()) conn.answer(Packets.AcceptIdentification(*args), packet.getId())
# trigger the event # trigger the event
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -52,7 +52,7 @@ class RecoveryHandler(MasterHandler): ...@@ -52,7 +52,7 @@ class RecoveryHandler(MasterHandler):
# load unknown storage nodes # load unknown storage nodes
for offset, row in row_list: for offset, row in row_list:
for uuid, state in row: for uuid, state in row:
node = app.nm.getByUUID(uuid) node = app.nm.getByUUID(uuid)
if node is None: if node is None:
app.nm.createStorage(uuid=uuid) app.nm.createStorage(uuid=uuid)
# load partition in memory # load partition in memory
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -44,7 +44,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -44,7 +44,7 @@ class StorageServiceHandler(BaseServiceHandler):
def askLastIDs(self, conn, packet): def askLastIDs(self, conn, packet):
app = self.app app = self.app
conn.answer(Packets.AnswerLastIDs(app.loid, app.ltid, app.pt.getID()), conn.answer(Packets.AnswerLastIDs(app.loid, app.ltid, app.pt.getID()),
packet.getId()) packet.getId())
def askUnfinishedTransactions(self, conn, packet): def askUnfinishedTransactions(self, conn, packet):
...@@ -80,7 +80,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -80,7 +80,7 @@ class StorageServiceHandler(BaseServiceHandler):
p = Packets.NotifyTransactionFinished(tid) p = Packets.NotifyTransactionFinished(tid)
c.answer(p, t.getMessageId()) c.answer(p, t.getMessageId())
else: else:
p = Packets.InvalidateObjects(t.getOIDList(), p = Packets.InvalidateObjects(t.getOIDList(),
tid) tid)
c.notify(p) c.notify(p)
elif node.isStorage(): elif node.isStorage():
...@@ -110,20 +110,20 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -110,20 +110,20 @@ class StorageServiceHandler(BaseServiceHandler):
continue continue
offset = cell[0] offset = cell[0]
logging.debug("node %s is up for offset %s" % logging.debug("node %s is up for offset %s" %
(dump(node.getUUID()), offset)) (dump(node.getUUID()), offset))
# check the storage said it is up to date for a partition it was # check the storage said it is up to date for a partition it was
# assigne to # assigne to
for xcell in app.pt.getCellList(offset): for xcell in app.pt.getCellList(offset):
if xcell.getNode().getUUID() == node.getUUID() and \ if xcell.getNode().getUUID() == node.getUUID() and \
xcell.getState() not in (CellStates.OUT_OF_DATE, xcell.getState() not in (CellStates.OUT_OF_DATE,
CellStates.UP_TO_DATE): CellStates.UP_TO_DATE):
msg = "node %s telling that it is UP TO DATE for offset \ msg = "node %s telling that it is UP TO DATE for offset \
%s but where %s for that offset" % (dump(node.getUUID()), %s but where %s for that offset" % (dump(node.getUUID()),
offset, xcell.getState()) offset, xcell.getState())
raise ProtocolError(msg) raise ProtocolError(msg)
app.pt.setCell(offset, node, CellStates.UP_TO_DATE) app.pt.setCell(offset, node, CellStates.UP_TO_DATE)
new_cell_list.append(cell) new_cell_list.append(cell)
...@@ -132,7 +132,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -132,7 +132,7 @@ class StorageServiceHandler(BaseServiceHandler):
for feeding_cell in app.pt.getCellList(offset): for feeding_cell in app.pt.getCellList(offset):
if feeding_cell.getState() == CellStates.FEEDING: if feeding_cell.getState() == CellStates.FEEDING:
app.pt.removeCell(offset, feeding_cell.getNode()) app.pt.removeCell(offset, feeding_cell.getNode())
new_cell_list.append((offset, feeding_cell.getUUID(), new_cell_list.append((offset, feeding_cell.getUUID(),
CellStates.DISCARDED)) CellStates.DISCARDED))
break break
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -40,7 +40,7 @@ class VerificationHandler(BaseServiceHandler): ...@@ -40,7 +40,7 @@ class VerificationHandler(BaseServiceHandler):
def answerUnfinishedTransactions(self, conn, packet, tid_list): def answerUnfinishedTransactions(self, conn, packet, tid_list):
uuid = conn.getUUID() uuid = conn.getUUID()
logging.info('got unfinished transactions %s from %s:%d', logging.info('got unfinished transactions %s from %s:%d',
tid_list, *(conn.getAddress())) tid_list, *(conn.getAddress()))
app = self.app app = self.app
if app.asking_uuid_dict.get(uuid, True): if app.asking_uuid_dict.get(uuid, True):
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -47,7 +47,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -47,7 +47,7 @@ class PartitionTable(neo.pt.PartitionTable):
raise RuntimeError, 'cannot make a partition table with an ' \ raise RuntimeError, 'cannot make a partition table with an ' \
'empty storage node list' 'empty storage node list'
# Take it into account that the number of storage nodes may be less # Take it into account that the number of storage nodes may be less
# than the number of replicas. # than the number of replicas.
repeats = min(self.nr + 1, len(node_list)) repeats = min(self.nr + 1, len(node_list))
index = 0 index = 0
...@@ -136,7 +136,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -136,7 +136,7 @@ class PartitionTable(neo.pt.PartitionTable):
if num_cells <= self.nr: if num_cells <= self.nr:
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE)) row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(), cell_list.append((offset, node.getUUID(),
CellStates.OUT_OF_DATE)) CellStates.OUT_OF_DATE))
node_count += 1 node_count += 1
else: else:
...@@ -145,18 +145,18 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -145,18 +145,18 @@ class PartitionTable(neo.pt.PartitionTable):
# If there is a feeding cell already or it is # If there is a feeding cell already or it is
# out-of-date, just drop the node. # out-of-date, just drop the node.
row.remove(max_cell) row.remove(max_cell)
cell_list.append((offset, max_cell.getUUID(), cell_list.append((offset, max_cell.getUUID(),
CellStates.DISCARDED)) CellStates.DISCARDED))
self.count_dict[max_cell.getNode()] -= 1 self.count_dict[max_cell.getNode()] -= 1
else: else:
# Otherwise, use it as a feeding cell for safety. # Otherwise, use it as a feeding cell for safety.
max_cell.setState(CellStates.FEEDING) max_cell.setState(CellStates.FEEDING)
cell_list.append((offset, max_cell.getUUID(), cell_list.append((offset, max_cell.getUUID(),
CellStates.FEEDING)) CellStates.FEEDING))
# Don't count a feeding cell. # Don't count a feeding cell.
self.count_dict[max_cell.getNode()] -= 1 self.count_dict[max_cell.getNode()] -= 1
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE)) row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
cell_list.append((offset, node.getUUID(), cell_list.append((offset, node.getUUID(),
CellStates.OUT_OF_DATE)) CellStates.OUT_OF_DATE))
node_count += 1 node_count += 1
...@@ -223,7 +223,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -223,7 +223,7 @@ class PartitionTable(neo.pt.PartitionTable):
row.remove(cell) row.remove(cell)
if not cell.isFeeding(): if not cell.isFeeding():
self.count_dict[cell.getNode()] -= 1 self.count_dict[cell.getNode()] -= 1
changed_cell_list.append((offset, cell.getUUID(), changed_cell_list.append((offset, cell.getUUID(),
CellStates.DISCARDED)) CellStates.DISCARDED))
# Add cells, if a row contains less than the number of replicas. # Add cells, if a row contains less than the number of replicas.
...@@ -237,7 +237,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -237,7 +237,7 @@ class PartitionTable(neo.pt.PartitionTable):
if node is None: if node is None:
break break
row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE)) row.append(neo.pt.Cell(node, CellStates.OUT_OF_DATE))
changed_cell_list.append((offset, node.getUUID(), changed_cell_list.append((offset, node.getUUID(),
CellStates.OUT_OF_DATE)) CellStates.OUT_OF_DATE))
self.count_dict[node] += 1 self.count_dict[node] += 1
num_cells += 1 num_cells += 1
...@@ -256,7 +256,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -256,7 +256,7 @@ class PartitionTable(neo.pt.PartitionTable):
for cell in row: for cell in row:
if not cell.getNode().isRunning() and not cell.isOutOfDate(): if not cell.getNode().isRunning() and not cell.isOutOfDate():
cell.setState(CellStates.OUT_OF_DATE) cell.setState(CellStates.OUT_OF_DATE)
cell_list.append((offset, cell.getUUID(), cell_list.append((offset, cell.getUUID(),
CellStates.OUT_OF_DATE)) CellStates.OUT_OF_DATE))
return cell_list return cell_list
...@@ -193,11 +193,11 @@ class Application(object): ...@@ -193,11 +193,11 @@ class Application(object):
def execute(self, args): def execute(self, args):
"""Execute the command given.""" """Execute the command given."""
# print node type : print list of node of the given type # print node type : print list of node of the given type
# (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...) # (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...)
# set node uuid state [1|0] : set the node for the given uuid to the # set node uuid state [1|0] : set the node for the given uuid to the
# state (RUNNING, DOWN...) and modify the partition if asked # state (RUNNING, DOWN...) and modify the partition if asked
# set cluster name [shutdown|operational] : either shutdown the # set cluster name [shutdown|operational] : either shutdown the
# cluster or mark it as operational # cluster or mark it as operational
current_action = action_dict current_action = action_dict
level = 0 level = 0
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -24,7 +24,7 @@ from neo.protocol import NodeTypes, NodeStates ...@@ -24,7 +24,7 @@ from neo.protocol import NodeTypes, NodeStates
class Node(object): class Node(object):
"""This class represents a node.""" """This class represents a node."""
def __init__(self, manager, address=None, uuid=None, def __init__(self, manager, address=None, uuid=None,
state=NodeStates.UNKNOWN): state=NodeStates.UNKNOWN):
self._state = state self._state = state
self._address = address self._address = address
...@@ -64,7 +64,7 @@ class Node(object): ...@@ -64,7 +64,7 @@ class Node(object):
def __repr__(self): def __repr__(self):
return '<%s(uuid=%s, address=%s, state=%s)>' % ( return '<%s(uuid=%s, address=%s, state=%s)>' % (
self.__class__.__name__, self.__class__.__name__,
dump(self._uuid), dump(self._uuid),
self._address, self._address,
self._state, self._state,
...@@ -91,13 +91,13 @@ class Node(object): ...@@ -91,13 +91,13 @@ class Node(object):
return self._state == NodeStates.RUNNING return self._state == NodeStates.RUNNING
def isTemporarilyDown(self): def isTemporarilyDown(self):
# FIXME: is it like 'unconnected' or UNKNOWN state ? # FIXME: is it like 'unconnected' or UNKNOWN state ?
return self._state == NodeStates.TEMPORARILY_DOWN return self._state == NodeStates.TEMPORARILY_DOWN
def isDown(self): def isDown(self):
# FIXME: is it like 'unconnected' or 'forgotten' ? # FIXME: is it like 'unconnected' or 'forgotten' ?
return self._state == NodeStates.DOWN return self._state == NodeStates.DOWN
def isBroken(self): def isBroken(self):
return self._state == NodeStates.BROKEN return self._state == NodeStates.BROKEN
...@@ -151,19 +151,19 @@ class MasterNode(Node): ...@@ -151,19 +151,19 @@ class MasterNode(Node):
class StorageNode(Node): class StorageNode(Node):
"""This class represents a storage node.""" """This class represents a storage node."""
def isStorage(self): def isStorage(self):
return True return True
class ClientNode(Node): class ClientNode(Node):
"""This class represents a client node.""" """This class represents a client node."""
def isClient(self): def isClient(self):
return True return True
class AdminNode(Node): class AdminNode(Node):
"""This class represents an admin node.""" """This class represents an admin node."""
def isAdmin(self): def isAdmin(self):
return True return True
...@@ -194,7 +194,7 @@ class NodeManager(object): ...@@ -194,7 +194,7 @@ class NodeManager(object):
def add(self, node): def add(self, node):
if node in self._node_set: if node in self._node_set:
return return
self._node_set.add(node) self._node_set.add(node)
self._updateAddress(node, None) self._updateAddress(node, None)
self._updateUUID(node, None) self._updateUUID(node, None)
self.__updateSet(self._type_dict, None, node.__class__, node) self.__updateSet(self._type_dict, None, node.__class__, node)
...@@ -305,7 +305,7 @@ class NodeManager(object): ...@@ -305,7 +305,7 @@ class NodeManager(object):
def createClient(self, **kw): def createClient(self, **kw):
""" Create and register a new client """ """ Create and register a new client """
return self._createNode(ClientNode, **kw) return self._createNode(ClientNode, **kw)
def createAdmin(self, **kw): def createAdmin(self, **kw):
""" Create and register a new admin """ """ Create and register a new admin """
return self._createNode(AdminNode, **kw) return self._createNode(AdminNode, **kw)
...@@ -315,7 +315,7 @@ class NodeManager(object): ...@@ -315,7 +315,7 @@ class NodeManager(object):
if klass is None: if klass is None:
raise RuntimeError('Unknown node type : %s' % node_type) raise RuntimeError('Unknown node type : %s' % node_type)
return self._createNode(klass, **kw) return self._createNode(klass, **kw)
def clear(self, filter=None): def clear(self, filter=None):
self._node_set.clear() self._node_set.clear()
self._type_dict.clear() self._type_dict.clear()
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -82,9 +82,9 @@ node_state_prefix_dict = { ...@@ -82,9 +82,9 @@ node_state_prefix_dict = {
} }
# used for logging # used for logging
cell_state_prefix_dict = { cell_state_prefix_dict = {
CellStates.UP_TO_DATE: 'U', CellStates.UP_TO_DATE: 'U',
CellStates.OUT_OF_DATE: 'O', CellStates.OUT_OF_DATE: 'O',
CellStates.FEEDING: 'F', CellStates.FEEDING: 'F',
CellStates.DISCARDED: 'D', CellStates.DISCARDED: 'D',
} }
...@@ -97,14 +97,14 @@ INVALID_PTID = '\0' * 8 ...@@ -97,14 +97,14 @@ INVALID_PTID = '\0' * 8
INVALID_SERIAL = INVALID_TID INVALID_SERIAL = INVALID_TID
INVALID_PARTITION = 0xffffffff INVALID_PARTITION = 0xffffffff
UUID_NAMESPACES = { UUID_NAMESPACES = {
NodeTypes.STORAGE: 'S', NodeTypes.STORAGE: 'S',
NodeTypes.MASTER: 'M', NodeTypes.MASTER: 'M',
NodeTypes.CLIENT: 'C', NodeTypes.CLIENT: 'C',
NodeTypes.ADMIN: 'A', NodeTypes.ADMIN: 'A',
} }
class ProtocolError(Exception): class ProtocolError(Exception):
""" Base class for protocol errors, close the connection """ """ Base class for protocol errors, close the connection """
pass pass
...@@ -112,17 +112,17 @@ class PacketMalformedError(ProtocolError): ...@@ -112,17 +112,17 @@ class PacketMalformedError(ProtocolError):
""" Close the connection and set the node as broken""" """ Close the connection and set the node as broken"""
pass pass
class UnexpectedPacketError(ProtocolError): class UnexpectedPacketError(ProtocolError):
""" Close the connection and set the node as broken""" """ Close the connection and set the node as broken"""
pass pass
class NotReadyError(ProtocolError): class NotReadyError(ProtocolError):
""" Just close the connection """ """ Just close the connection """
pass pass
class BrokenNodeDisallowedError(ProtocolError): class BrokenNodeDisallowedError(ProtocolError):
""" Just close the connection """ """ Just close the connection """
pass pass
# packet parser # packet parser
...@@ -147,7 +147,7 @@ def _decodeNodeType(original_node_type): ...@@ -147,7 +147,7 @@ def _decodeNodeType(original_node_type):
def _decodeErrorCode(original_error_code): def _decodeErrorCode(original_error_code):
error_code = ErrorCodes.get(original_error_code) error_code = ErrorCodes.get(original_error_code)
if error_code is None: if error_code is None:
raise PacketMalformedError('invalid error code %d' % raise PacketMalformedError('invalid error code %d' %
original_error_code) original_error_code)
return error_code return error_code
...@@ -203,10 +203,10 @@ def _readString(buf, name, offset=0): ...@@ -203,10 +203,10 @@ def _readString(buf, name, offset=0):
class Packet(object): class Packet(object):
""" """
Base class for any packet definition. Base class for any packet definition.
Each subclass should override _encode() and _decode() and return a string or Each subclass should override _encode() and _decode() and return a string or
a tuple respectively. a tuple respectively.
""" """
_body = None _body = None
...@@ -222,7 +222,7 @@ class Packet(object): ...@@ -222,7 +222,7 @@ class Packet(object):
body = '' body = ''
self._body = body self._body = body
self._args = args self._args = args
def decode(self): def decode(self):
assert self._body is not None assert self._body is not None
try: try:
...@@ -284,20 +284,20 @@ class Packet(object): ...@@ -284,20 +284,20 @@ class Packet(object):
class Ping(Packet): class Ping(Packet):
""" """
Check if a peer is still alive. Any -> Any. Check if a peer is still alive. Any -> Any.
""" """
pass pass
class Pong(Packet): class Pong(Packet):
""" """
Notify being alive. Any -> Any. Notify being alive. Any -> Any.
""" """
pass pass
class RequestIdentification(Packet): class RequestIdentification(Packet):
""" """
Request a node identification. This must be the first packet for any Request a node identification. This must be the first packet for any
connection. Any -> Any. connection. Any -> Any.
""" """
...@@ -320,7 +320,7 @@ class RequestIdentification(Packet): ...@@ -320,7 +320,7 @@ class RequestIdentification(Packet):
class AcceptIdentification(Packet): class AcceptIdentification(Packet):
""" """
Accept a node identification. This should be a reply to Request Node Accept a node identification. This should be a reply to Request Node
Identification. Any -> Any. Identification. Any -> Any.
""" """
def _encode(self, node_type, uuid, address, def _encode(self, node_type, uuid, address,
...@@ -338,19 +338,19 @@ class AcceptIdentification(Packet): ...@@ -338,19 +338,19 @@ class AcceptIdentification(Packet):
node_type = _decodeNodeType(node_type) node_type = _decodeNodeType(node_type)
uuid = _decodeUUID(uuid) uuid = _decodeUUID(uuid)
your_uuid == _decodeUUID(uuid) your_uuid == _decodeUUID(uuid)
return (node_type, uuid, address, num_partitions, num_replicas, return (node_type, uuid, address, num_partitions, num_replicas,
your_uuid) your_uuid)
class AskPrimary(Packet): class AskPrimary(Packet):
""" """
Ask a current primary master node. This must be the second message when Ask a current primary master node. This must be the second message when
connecting to a master node. Any -> M. connecting to a master node. Any -> M.
""" """
pass pass
class AnswerPrimary(Packet): class AnswerPrimary(Packet):
""" """
Reply to Ask Primary Master. This message includes a list of known master Reply to Ask Primary Master. This message includes a list of known master
nodes to make sure that a peer has the same information. M -> Any. nodes to make sure that a peer has the same information. M -> Any.
""" """
def _encode(self, primary_uuid, known_master_list): def _encode(self, primary_uuid, known_master_list):
...@@ -374,7 +374,7 @@ class AnswerPrimary(Packet): ...@@ -374,7 +374,7 @@ class AnswerPrimary(Packet):
return (primary_uuid, known_master_list) return (primary_uuid, known_master_list)
class AnnouncePrimary(Packet): class AnnouncePrimary(Packet):
""" """
Announce a primary master node election. PM -> SM. Announce a primary master node election. PM -> SM.
""" """
pass pass
...@@ -386,19 +386,19 @@ class ReelectPrimary(Packet): ...@@ -386,19 +386,19 @@ class ReelectPrimary(Packet):
pass pass
class AskLastIDs(Packet): class AskLastIDs(Packet):
""" """
Ask the last OID, the last TID and the last Partition Table ID that Ask the last OID, the last TID and the last Partition Table ID that
a storage node stores. Used to recover information. PM -> S, S -> PM. a storage node stores. Used to recover information. PM -> S, S -> PM.
""" """
pass pass
class AnswerLastIDs(Packet): class AnswerLastIDs(Packet):
""" """
Reply to Ask Last IDs. S -> PM, PM -> S. Reply to Ask Last IDs. S -> PM, PM -> S.
""" """
def _encode(self, loid, ltid, lptid): def _encode(self, loid, ltid, lptid):
# in this case, loid is a valid OID but considered as invalid. This is # in this case, loid is a valid OID but considered as invalid. This is
# not an issue because the OID 0 is hard coded and will never be # not an issue because the OID 0 is hard coded and will never be
# generated # generated
if loid is None: if loid is None:
loid = INVALID_OID loid = INVALID_OID
...@@ -412,7 +412,7 @@ class AnswerLastIDs(Packet): ...@@ -412,7 +412,7 @@ class AnswerLastIDs(Packet):
return (loid, ltid, lptid) return (loid, ltid, lptid)
class AskPartitionTable(Packet): class AskPartitionTable(Packet):
""" """
Ask rows in a partition table that a storage node stores. Used to recover Ask rows in a partition table that a storage node stores. Used to recover
information. PM -> S. information. PM -> S.
""" """
...@@ -431,7 +431,7 @@ class AskPartitionTable(Packet): ...@@ -431,7 +431,7 @@ class AskPartitionTable(Packet):
return (offset_list,) return (offset_list,)
class AnswerPartitionTable(Packet): class AnswerPartitionTable(Packet):
""" """
Answer rows in a partition table. S -> PM. Answer rows in a partition table. S -> PM.
""" """
def _encode(self, ptid, row_list): def _encode(self, ptid, row_list):
...@@ -464,7 +464,7 @@ class AnswerPartitionTable(Packet): ...@@ -464,7 +464,7 @@ class AnswerPartitionTable(Packet):
return (ptid, row_list) return (ptid, row_list)
class SendPartitionTable(Packet): class SendPartitionTable(Packet):
""" """
Send rows in a partition table to update other nodes. PM -> S, C. Send rows in a partition table to update other nodes. PM -> S, C.
""" """
def _encode(self, ptid, row_list): def _encode(self, ptid, row_list):
...@@ -497,8 +497,8 @@ class SendPartitionTable(Packet): ...@@ -497,8 +497,8 @@ class SendPartitionTable(Packet):
return (ptid, row_list) return (ptid, row_list)
class NotifyPartitionChanges(Packet): class NotifyPartitionChanges(Packet):
""" """
Notify a subset of a partition table. This is used to notify changes. Notify a subset of a partition table. This is used to notify changes.
PM -> S, C. PM -> S, C.
""" """
def _encode(self, ptid, cell_list): def _encode(self, ptid, cell_list):
...@@ -522,14 +522,14 @@ class NotifyPartitionChanges(Packet): ...@@ -522,14 +522,14 @@ class NotifyPartitionChanges(Packet):
class StartOperation(Packet): class StartOperation(Packet):
""" """
Tell a storage nodes to start an operation. Until a storage node receives Tell a storage nodes to start an operation. Until a storage node receives
this message, it must not serve client nodes. PM -> S. this message, it must not serve client nodes. PM -> S.
""" """
pass pass
class StopOperation(Packet): class StopOperation(Packet):
""" """
Tell a storage node to stop an operation. Once a storage node receives Tell a storage node to stop an operation. Once a storage node receives
this message, it must not serve client nodes. PM -> S. this message, it must not serve client nodes. PM -> S.
""" """
pass pass
...@@ -559,7 +559,7 @@ class AnswerUnfinishedTransactions(Packet): ...@@ -559,7 +559,7 @@ class AnswerUnfinishedTransactions(Packet):
class AskObjectPresent(Packet): class AskObjectPresent(Packet):
""" """
Ask if an object is present. If not present, OID_NOT_FOUND should be Ask if an object is present. If not present, OID_NOT_FOUND should be
returned. PM -> S. returned. PM -> S.
""" """
def _decode(self, body): def _decode(self, body):
...@@ -693,7 +693,7 @@ class UnlockInformation(Packet): ...@@ -693,7 +693,7 @@ class UnlockInformation(Packet):
return _encodeTID(tid) return _encodeTID(tid)
def _decode(self, body): def _decode(self, body):
(tid, ) = unpack('8s', body) (tid, ) = unpack('8s', body)
return (_decodeTID(tid), ) return (_decodeTID(tid), )
class AskNewOIDs(Packet): class AskNewOIDs(Packet):
...@@ -885,7 +885,7 @@ class AnswerTransactionInformation(Packet): ...@@ -885,7 +885,7 @@ class AnswerTransactionInformation(Packet):
Answer information (user, description) about a transaction. S -> Any. Answer information (user, description) about a transaction. S -> Any.
""" """
def _encode(self, tid, user, desc, ext, oid_list): def _encode(self, tid, user, desc, ext, oid_list):
body = [pack('!8sHHHL', tid, len(user), len(desc), len(ext), body = [pack('!8sHHHL', tid, len(user), len(desc), len(ext),
len(oid_list))] len(oid_list))]
body.append(user) body.append(user)
body.append(desc) body.append(desc)
...@@ -1112,8 +1112,8 @@ class AnswerNewNodes(Packet): ...@@ -1112,8 +1112,8 @@ class AnswerNewNodes(Packet):
return (uuid_list, ) return (uuid_list, )
class NotifyNodeInformation(Packet): class NotifyNodeInformation(Packet):
""" """
Notify information about one or more nodes. Any -> PM, PM -> Any. Notify information about one or more nodes. Any -> PM, PM -> Any.
""" """
def _encode(self, node_list): def _encode(self, node_list):
body = [pack('!L', len(node_list))] body = [pack('!L', len(node_list))]
...@@ -1122,7 +1122,7 @@ class NotifyNodeInformation(Packet): ...@@ -1122,7 +1122,7 @@ class NotifyNodeInformation(Packet):
address = _encodeAddress(address) address = _encodeAddress(address)
body.append(pack('!H6s16sH', node_type, address, uuid, state)) body.append(pack('!H6s16sH', node_type, address, uuid, state))
return ''.join(body) return ''.join(body)
def _decode(self, body): def _decode(self, body):
(n,) = unpack('!L', body[:4]) (n,) = unpack('!L', body[:4])
node_list = [] node_list = []
...@@ -1200,8 +1200,8 @@ class NotifyLastOID(Packet): ...@@ -1200,8 +1200,8 @@ class NotifyLastOID(Packet):
class Error(Packet): class Error(Packet):
""" """
Error is a special type of message, because this can be sent against Error is a special type of message, because this can be sent against
any other message, even if such a message does not expect a reply any other message, even if such a message does not expect a reply
usually. Any -> Any. usually. Any -> Any.
""" """
def _encode(self, code, message): def _encode(self, code, message):
...@@ -1224,7 +1224,7 @@ def register(code, cls): ...@@ -1224,7 +1224,7 @@ def register(code, cls):
class PacketRegistry(dict): class PacketRegistry(dict):
""" """
Packet registry that check packet code unicity and provide an index Packet registry that check packet code unicity and provide an index
""" """
...@@ -1272,7 +1272,7 @@ class PacketRegistry(dict): ...@@ -1272,7 +1272,7 @@ class PacketRegistry(dict):
StartOperation = register(0x000B, StartOperation) StartOperation = register(0x000B, StartOperation)
StopOperation = register(0x000C, StopOperation) StopOperation = register(0x000C, StopOperation)
AskUnfinishedTransactions = register(0x000D, AskUnfinishedTransactions) AskUnfinishedTransactions = register(0x000D, AskUnfinishedTransactions)
AnswerUnfinishedTransactions = register(0x800d, AnswerUnfinishedTransactions = register(0x800d,
AnswerUnfinishedTransactions) AnswerUnfinishedTransactions)
AskObjectPresent = register(0x000f, AskObjectPresent) AskObjectPresent = register(0x000f, AskObjectPresent)
AnswerObjectPresent = register(0x800f, AnswerObjectPresent) AnswerObjectPresent = register(0x800f, AnswerObjectPresent)
...@@ -1298,7 +1298,7 @@ class PacketRegistry(dict): ...@@ -1298,7 +1298,7 @@ class PacketRegistry(dict):
AskTIDs = register(0x001C, AskTIDs) AskTIDs = register(0x001C, AskTIDs)
AnswerTIDs = register(0x801D, AnswerTIDs) AnswerTIDs = register(0x801D, AnswerTIDs)
AskTransactionInformation = register(0x001E, AskTransactionInformation) AskTransactionInformation = register(0x001E, AskTransactionInformation)
AnswerTransactionInformation = register(0x801E, AnswerTransactionInformation = register(0x801E,
AnswerTransactionInformation) AnswerTransactionInformation)
AskObjectHistory = register(0x001F, AskObjectHistory) AskObjectHistory = register(0x001F, AskObjectHistory)
AnswerObjectHistory = register(0x801F, AnswerObjectHistory) AnswerObjectHistory = register(0x801F, AnswerObjectHistory)
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -180,7 +180,7 @@ class PartitionTable(object): ...@@ -180,7 +180,7 @@ class PartitionTable(object):
break break
def load(self, ptid, row_list, nm): def load(self, ptid, row_list, nm):
""" """
Load the partition table with the specified PTID, discard all previous Load the partition table with the specified PTID, discard all previous
content and can be done in multiple calls content and can be done in multiple calls
""" """
...@@ -190,7 +190,7 @@ class PartitionTable(object): ...@@ -190,7 +190,7 @@ class PartitionTable(object):
for offset, row in row_list: for offset, row in row_list:
assert offset < self.getPartitions() and not self.hasOffset(offset) assert offset < self.getPartitions() and not self.hasOffset(offset)
for uuid, state in row: for uuid, state in row:
node = nm.getByUUID(uuid) node = nm.getByUUID(uuid)
# XXX: the node should be known before we receive the partition # XXX: the node should be known before we receive the partition
# table, so remove this assert when this is checked. # table, so remove this assert when this is checked.
assert node is not None assert node is not None
...@@ -207,7 +207,7 @@ class PartitionTable(object): ...@@ -207,7 +207,7 @@ class PartitionTable(object):
return return
self.id = ptid self.id = ptid
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
node = nm.getByUUID(uuid) node = nm.getByUUID(uuid)
assert node is not None assert node is not None
self.setCell(offset, node, state) self.setCell(offset, node, state)
logging.debug('partition table updated') logging.debug('partition table updated')
...@@ -256,7 +256,7 @@ class PartitionTable(object): ...@@ -256,7 +256,7 @@ class PartitionTable(object):
line.append('X' * len(node_list)) line.append('X' * len(node_list))
else: else:
cell = [] cell = []
cell_dict = dict([(node_dict.get(x.getUUID(), None), x) cell_dict = dict([(node_dict.get(x.getUUID(), None), x)
for x in row]) for x in row])
for node in xrange(len(node_list)): for node in xrange(len(node_list)):
if node in cell_dict: if node in cell_dict:
...@@ -268,7 +268,7 @@ class PartitionTable(object): ...@@ -268,7 +268,7 @@ class PartitionTable(object):
logging.debug('pt: %08d: %s', offset - len(line) + 1, logging.debug('pt: %08d: %s', offset - len(line) + 1,
'|'.join(line)) '|'.join(line))
def operational(self): def operational(self):
if not self.filled(): if not self.filled():
return False return False
for row in self.partition_list: for row in self.partition_list:
......
...@@ -42,7 +42,7 @@ class Application(object): ...@@ -42,7 +42,7 @@ class Application(object):
# set the cluster name # set the cluster name
self.name = config.getCluster() self.name = config.getCluster()
# set the bind address # set the bind address
self.server = config.getBind() self.server = config.getBind()
logging.debug('IP address is %s, port is %d', *(self.server)) logging.debug('IP address is %s, port is %d', *(self.server))
...@@ -50,7 +50,7 @@ class Application(object): ...@@ -50,7 +50,7 @@ class Application(object):
# load master node list # load master node list
self.master_node_list = config.getMasters() self.master_node_list = config.getMasters()
logging.debug('master nodes are %s', self.master_node_list) logging.debug('master nodes are %s', self.master_node_list)
# Internal attributes. # Internal attributes.
self.em = EventManager() self.em = EventManager()
self.nm = NodeManager() self.nm = NodeManager()
...@@ -108,7 +108,7 @@ class Application(object): ...@@ -108,7 +108,7 @@ class Application(object):
raise RuntimeError('name does not match with the database') raise RuntimeError('name does not match with the database')
ptid = dm.getPTID() ptid = dm.getPTID()
logging.info("Configuration: uuid=%s, ptid=%s, name=%s, np=%s, nr=%s" \ logging.info("Configuration: uuid=%s, ptid=%s, name=%s, np=%s, nr=%s" \
% (dump(self.uuid), dump(ptid), name, num_partitions, % (dump(self.uuid), dump(ptid), name, num_partitions,
num_replicas)) num_replicas))
def loadPartitionTable(self): def loadPartitionTable(self):
...@@ -137,7 +137,7 @@ class Application(object): ...@@ -137,7 +137,7 @@ class Application(object):
# Make a listening port # Make a listening port
handler = identification.IdentificationHandler(self) handler = identification.IdentificationHandler(self)
self.listening_conn = ListeningConnection(self.em, handler, self.listening_conn = ListeningConnection(self.em, handler,
addr=self.server, connector_handler=self.connector_handler) addr=self.server, connector_handler=self.connector_handler)
# Connect to a primary master node, verify data, and # Connect to a primary master node, verify data, and
...@@ -228,7 +228,7 @@ class Application(object): ...@@ -228,7 +228,7 @@ class Application(object):
self.has_node_information = False self.has_node_information = False
self.has_partition_table = False self.has_partition_table = False
self.pt.clear() self.pt.clear()
self.master_conn.ask(Packets.AskNodeInformation()) self.master_conn.ask(Packets.AskNodeInformation())
self.master_conn.ask(Packets.AskPartitionTable(())) self.master_conn.ask(Packets.AskPartitionTable(()))
while not self.has_node_information or not self.has_partition_table: while not self.has_node_information or not self.has_partition_table:
self.em.poll(1) self.em.poll(1)
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -105,7 +105,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -105,7 +105,7 @@ class MySQLDatabaseManager(DatabaseManager):
return self.query(query) return self.query(query)
raise DatabaseFailure('MySQL error %d: %s' % (m[0], m[1])) raise DatabaseFailure('MySQL error %d: %s' % (m[0], m[1]))
return r return r
def escape(self, s): def escape(self, s):
"""Escape special characters in a string.""" """Escape special characters in a string."""
return self.conn.escape_string(s) return self.conn.escape_string(s)
...@@ -326,9 +326,9 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -326,9 +326,9 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query q = self.query
self.begin() self.begin()
try: try:
q("""DELETE FROM obj WHERE MOD(oid, %d) = %d""" % q("""DELETE FROM obj WHERE MOD(oid, %d) = %d""" %
(num_partitions, offset)) (num_partitions, offset))
q("""DELETE FROM trans WHERE MOD(tid, %d) = %d""" % q("""DELETE FROM trans WHERE MOD(tid, %d) = %d""" %
(num_partitions, offset)) (num_partitions, offset))
except: except:
self.rollback() self.rollback()
...@@ -436,7 +436,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -436,7 +436,7 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query q = self.query
r = q("""SELECT DISTINCT oid FROM obj WHERE MOD(oid, %d) in (%s) r = q("""SELECT DISTINCT oid FROM obj WHERE MOD(oid, %d) in (%s)
ORDER BY oid DESC LIMIT %d,%d""" \ ORDER BY oid DESC LIMIT %d,%d""" \
% (num_partitions, ','.join([str(p) for p in partition_list]), % (num_partitions, ','.join([str(p) for p in partition_list]),
offset, length)) offset, length))
return [util.p64(t[0]) for t in r] return [util.p64(t[0]) for t in r]
...@@ -454,8 +454,8 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -454,8 +454,8 @@ class MySQLDatabaseManager(DatabaseManager):
q = self.query q = self.query
r = q("""SELECT tid FROM trans WHERE MOD(tid, %d) in (%s) r = q("""SELECT tid FROM trans WHERE MOD(tid, %d) in (%s)
ORDER BY tid DESC LIMIT %d,%d""" \ ORDER BY tid DESC LIMIT %d,%d""" \
% (num_partitions, % (num_partitions,
','.join([str(p) for p in partition_list]), ','.join([str(p) for p in partition_list]),
offset, length)) offset, length))
return [util.p64(t[0]) for t in r] return [util.p64(t[0]) for t in r]
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -37,7 +37,7 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -37,7 +37,7 @@ class BaseMasterHandler(BaseStorageHandler):
raise PrimaryFailure('re-election occurs') raise PrimaryFailure('re-election occurs')
def notifyClusterInformation(self, conn, packet, state): def notifyClusterInformation(self, conn, packet, state):
logging.error('ignoring notify cluster information in %s' % logging.error('ignoring notify cluster information in %s' %
self.__class__.__name__) self.__class__.__name__)
def notifyLastOID(self, conn, packet, oid): def notifyLastOID(self, conn, packet, oid):
...@@ -105,7 +105,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -105,7 +105,7 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
if t is None: if t is None:
p = protocol.tidNotFound('%s does not exist' % dump(tid)) p = protocol.tidNotFound('%s does not exist' % dump(tid))
else: else:
p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3], p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3],
t[0]) t[0])
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -38,7 +38,7 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -38,7 +38,7 @@ class IdentificationHandler(BaseStorageHandler):
node = app.nm.getByUUID(uuid) node = app.nm.getByUUID(uuid)
# choose the handler according to the node type # choose the handler according to the node type
if node_type == NodeTypes.CLIENT: if node_type == NodeTypes.CLIENT:
from neo.storage.handlers.client import ClientOperationHandler from neo.storage.handlers.client import ClientOperationHandler
handler = ClientOperationHandler handler = ClientOperationHandler
if node is None: if node is None:
node = app.nm.createClient() node = app.nm.createClient()
...@@ -58,7 +58,7 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -58,7 +58,7 @@ class IdentificationHandler(BaseStorageHandler):
conn.setHandler(handler) conn.setHandler(handler)
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
args = (NodeTypes.STORAGE, app.uuid, app.server, args = (NodeTypes.STORAGE, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getPartitions(), app.pt.getReplicas(), uuid)
# accept the identification and trigger an event # accept the identification and trigger an event
conn.answer(Packets.AcceptIdentification(*args), packet.getId()) conn.answer(Packets.AcceptIdentification(*args), packet.getId())
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -57,13 +57,13 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -57,13 +57,13 @@ class ReplicationHandler(BaseStorageHandler):
# And, ask more TIDs. # And, ask more TIDs.
app.replicator.tid_offset += 1000 app.replicator.tid_offset += 1000
offset = app.replicator.tid_offset offset = app.replicator.tid_offset
p = Packets.AskTIDs(offset, offset + 1000, p = Packets.AskTIDs(offset, offset + 1000,
app.replicator.current_partition.getRID()) app.replicator.current_partition.getRID())
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
else: else:
# If no more TID, a replication of transactions is finished. # If no more TID, a replication of transactions is finished.
# So start to replicate objects now. # So start to replicate objects now.
p = Packets.AskOIDs(0, 1000, p = Packets.AskOIDs(0, 1000,
app.replicator.current_partition.getRID()) app.replicator.current_partition.getRID())
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
app.replicator.oid_offset = 0 app.replicator.oid_offset = 0
...@@ -92,7 +92,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -92,7 +92,7 @@ class ReplicationHandler(BaseStorageHandler):
# Nothing remains, so the replication for this partition is # Nothing remains, so the replication for this partition is
# finished. # finished.
app.replicator.replication_done = True app.replicator.replication_done = True
def answerObjectHistory(self, conn, packet, oid, history_list): def answerObjectHistory(self, conn, packet, oid, history_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn: if app.replicator.current_connection is not conn:
...@@ -123,7 +123,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -123,7 +123,7 @@ class ReplicationHandler(BaseStorageHandler):
# Otherwise, acquire more OIDs. # Otherwise, acquire more OIDs.
app.replicator.oid_offset += 1000 app.replicator.oid_offset += 1000
offset = app.replicator.oid_offset offset = app.replicator.oid_offset
p = Packets.AskOIDs(offset, offset + 1000, p = Packets.AskOIDs(offset, offset + 1000,
app.replicator.current_partition.getRID()) app.replicator.current_partition.getRID())
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -83,7 +83,7 @@ class VerificationHandler(BaseMasterHandler): ...@@ -83,7 +83,7 @@ class VerificationHandler(BaseMasterHandler):
if t is None: if t is None:
p = protocol.tidNotFound('%s does not exist' % dump(tid)) p = protocol.tidNotFound('%s does not exist' % dump(tid))
else: else:
p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3], p = Packets.AnswerTransactionInformation(tid, t[1], t[2], t[3],
t[0]) t[0])
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -51,7 +51,7 @@ class Partition(object): ...@@ -51,7 +51,7 @@ class Partition(object):
class Replicator(object): class Replicator(object):
"""This class handles replications of objects and transactions. """This class handles replications of objects and transactions.
Assumptions: Assumptions:
- Client nodes recognize partition changes reasonably quickly. - Client nodes recognize partition changes reasonably quickly.
...@@ -126,7 +126,7 @@ class Replicator(object): ...@@ -126,7 +126,7 @@ class Replicator(object):
partition.setCriticalTID(tid) partition.setCriticalTID(tid)
del self.critical_tid_dict[msg_id] del self.critical_tid_dict[msg_id]
except KeyError: except KeyError:
logging.debug("setCriticalTID raised KeyError for msg_id %s" % logging.debug("setCriticalTID raised KeyError for msg_id %s" %
(msg_id, )) (msg_id, ))
def _askCriticalTID(self): def _askCriticalTID(self):
...@@ -152,7 +152,7 @@ class Replicator(object): ...@@ -152,7 +152,7 @@ class Replicator(object):
# Choose a storage node for the source. # Choose a storage node for the source.
app = self.app app = self.app
try: try:
cell_list = app.pt.getCellList(self.current_partition.getRID(), cell_list = app.pt.getCellList(self.current_partition.getRID(),
readable=True) readable=True)
node_list = [cell.getNode() for cell in cell_list node_list = [cell.getNode() for cell in cell_list
if cell.getNodeState() == NodeStates.RUNNING] if cell.getNodeState() == NodeStates.RUNNING]
...@@ -165,7 +165,7 @@ class Replicator(object): ...@@ -165,7 +165,7 @@ class Replicator(object):
addr = node.getAddress() addr = node.getAddress()
if addr is None: if addr is None:
logging.error("no address known for the selected node %s" % logging.error("no address known for the selected node %s" %
(dump(node.getUUID()), )) (dump(node.getUUID()), ))
return return
if self.current_connection is not None: if self.current_connection is not None:
...@@ -178,9 +178,9 @@ class Replicator(object): ...@@ -178,9 +178,9 @@ class Replicator(object):
if self.current_connection is None: if self.current_connection is None:
handler = replication.ReplicationHandler(app) handler = replication.ReplicationHandler(app)
self.current_connection = ClientConnection(app.em, handler, self.current_connection = ClientConnection(app.em, handler,
addr = addr, connector_handler = app.connector_handler) addr = addr, connector_handler = app.connector_handler)
p = Packets.RequestIdentification(NodeTypes.STORAGE, p = Packets.RequestIdentification(NodeTypes.STORAGE,
app.uuid, app.server, app.name) app.uuid, app.server, app.name)
self.current_connection.ask(p) self.current_connection.ask(p)
...@@ -196,8 +196,8 @@ class Replicator(object): ...@@ -196,8 +196,8 @@ class Replicator(object):
self.partition_dict.pop(self.current_partition.getRID()) self.partition_dict.pop(self.current_partition.getRID())
# Notify to a primary master node that my cell is now up-to-date. # Notify to a primary master node that my cell is now up-to-date.
conn = self.primary_master_connection conn = self.primary_master_connection
p = Packets.NotifyPartitionChanges(app.pt.getID(), p = Packets.NotifyPartitionChanges(app.pt.getID(),
[(self.current_partition.getRID(), app.uuid, [(self.current_partition.getRID(), app.uuid,
CellStates.UP_TO_DATE)]) CellStates.UP_TO_DATE)])
conn.notify(p) conn.notify(p)
except KeyError: except KeyError:
...@@ -209,7 +209,7 @@ class Replicator(object): ...@@ -209,7 +209,7 @@ class Replicator(object):
# TID to a primary master node. # TID to a primary master node.
if self.new_partition_dict: if self.new_partition_dict:
self._askCriticalTID() self._askCriticalTID()
if self.current_partition is None: if self.current_partition is None:
# I need to choose something. # I need to choose something.
if self.waiting_for_unfinished_tids: if self.waiting_for_unfinished_tids:
...@@ -236,7 +236,7 @@ class Replicator(object): ...@@ -236,7 +236,7 @@ class Replicator(object):
self._askUnfinishedTIDs() self._askUnfinishedTIDs()
else: else:
if self.replication_done: if self.replication_done:
logging.info('replication is done for %s' % logging.info('replication is done for %s' %
(self.current_partition.getRID(), )) (self.current_partition.getRID(), ))
self._finishReplication() self._finishReplication()
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -53,12 +53,12 @@ class NeoTestBase(unittest.TestCase): ...@@ -53,12 +53,12 @@ class NeoTestBase(unittest.TestCase):
database = "%s%d" % (prefix, i) database = "%s%d" % (prefix, i)
cursor.execute('DROP DATABASE IF EXISTS %s' % (database, )) cursor.execute('DROP DATABASE IF EXISTS %s' % (database, ))
cursor.execute('CREATE DATABASE %s' % (database, )) cursor.execute('CREATE DATABASE %s' % (database, ))
cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' % cursor.execute('GRANT ALL ON %s.* TO "%s"@"localhost" IDENTIFIED BY ""' %
(database, user)) (database, user))
cursor.close() cursor.close()
sql_connection.close() sql_connection.close()
def getMasterConfiguration(self, cluster='main', master_number=2, def getMasterConfiguration(self, cluster='main', master_number=2,
replicas=2, partitions=1009, uuid=None): replicas=2, partitions=1009, uuid=None):
assert master_number >= 1 and master_number <= 10 assert master_number >= 1 and master_number <= 10
masters = [('127.0.0.1', 10010 + i) for i in xrange(master_number)] masters = [('127.0.0.1', 10010 + i) for i in xrange(master_number)]
...@@ -71,7 +71,7 @@ class NeoTestBase(unittest.TestCase): ...@@ -71,7 +71,7 @@ class NeoTestBase(unittest.TestCase):
'getUUID': uuid, 'getUUID': uuid,
}) })
def getStorageConfiguration(self, cluster='main', master_number=2, def getStorageConfiguration(self, cluster='main', master_number=2,
index=0, prefix=DB_PREFIX, uuid=None): index=0, prefix=DB_PREFIX, uuid=None):
assert master_number >= 1 and master_number <= 10 assert master_number >= 1 and master_number <= 10
assert index >= 0 and index <= 9 assert index >= 0 and index <= 9
...@@ -87,9 +87,9 @@ class NeoTestBase(unittest.TestCase): ...@@ -87,9 +87,9 @@ class NeoTestBase(unittest.TestCase):
'getReset': False, 'getReset': False,
'getAdapter': 'MySQL', 'getAdapter': 'MySQL',
}) })
# XXX: according to changes with namespaced UUIDs, it would be better to # XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods # implement get<NodeType>UUID() methods
def getNewUUID(self): def getNewUUID(self):
self.uuid = getNewUUID() self.uuid = getNewUUID()
return self.uuid return self.uuid
...@@ -343,11 +343,11 @@ class TestElectionConnector(DoNothingConnector): ...@@ -343,11 +343,11 @@ class TestElectionConnector(DoNothingConnector):
# second : answer primary master nodes # second : answer primary master nodes
logging.info("in patched analyse / ANSWER PM") logging.info("in patched analyse / ANSWER PM")
p = protocol.Packet() p = protocol.Packet()
p.answerPrimary(2, protocol.INVALID_UUID, []) p.answerPrimary(2, protocol.INVALID_UUID, [])
self.packet_cpt += 1 self.packet_cpt += 1
return p.encode() return p.encode()
else: else:
# then do nothing # then do nothing
from neo.connector import ConnectorTryAgainException from neo.connector import ConnectorTryAgainException
raise ConnectorTryAgainException raise ConnectorTryAgainException
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -135,10 +135,10 @@ class ClientApplicationTests(NeoTestBase): ...@@ -135,10 +135,10 @@ class ClientApplicationTests(NeoTestBase):
txn = app.local_var.txn txn = app.local_var.txn
tid = app.local_var.tid tid = app.local_var.tid
packet = Packets.NotifyTransactionFinished(tid) packet = Packets.NotifyTransactionFinished(tid)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getAddress': ('127.0.0.1', 10010), 'getAddress': ('127.0.0.1', 10010),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.tpc_finish(txn) app.tpc_finish(txn)
...@@ -154,7 +154,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -154,7 +154,7 @@ class ClientApplicationTests(NeoTestBase):
app = self.getApp() app = self.getApp()
# Test sanity check # Test sanity check
self.assertTrue(getattr(app, 'local_var', None) is not None) self.assertTrue(getattr(app, 'local_var', None) is not None)
# Test that queue is created # Test that queue is created
self.assertTrue(getattr(app.local_var, 'queue', None) is not None) self.assertTrue(getattr(app.local_var, 'queue', None) is not None)
def test_registerDB(self): def test_registerDB(self):
...@@ -197,7 +197,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -197,7 +197,7 @@ class ClientApplicationTests(NeoTestBase):
app.getSerial(oid) app.getSerial(oid)
self.assertEquals(app.getSerial(oid), tid) self.assertEquals(app.getSerial(oid), tid)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellListForOID')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('getCellListForOID')), 0)
def test_load(self): def test_load(self):
app = self.getApp() app = self.getApp()
mq = app.mq_cache mq = app.mq_cache
...@@ -211,7 +211,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -211,7 +211,7 @@ class ClientApplicationTests(NeoTestBase):
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({'getUUID': '\x10' * 16, conn = Mock({'getUUID': '\x10' * 16,
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.local_var.queue = Mock({'get_nowait' : (conn, None)}) app.local_var.queue = Mock({'get_nowait' : (conn, None)})
app.pt = Mock({ 'getCellListForOID': (cell, ), }) app.pt = Mock({ 'getCellListForOID': (cell, ), })
...@@ -225,9 +225,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -225,9 +225,9 @@ class ClientApplicationTests(NeoTestBase):
self.assertTrue(oid not in mq) self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('') packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.pt = Mock({ 'getCellListForOID': (cell, ), }) app.pt = Mock({ 'getCellListForOID': (cell, ), })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
...@@ -236,9 +236,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -236,9 +236,9 @@ class ClientApplicationTests(NeoTestBase):
self.checkAskObject(conn) self.checkAskObject(conn)
# object found on storage nodes and put in cache # object found on storage nodes and put in cache
packet = Packets.AnswerObject(*an_object[1:]) packet = Packets.AnswerObject(*an_object[1:])
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = an_object app.local_var.asked_object = an_object
...@@ -246,15 +246,15 @@ class ClientApplicationTests(NeoTestBase): ...@@ -246,15 +246,15 @@ class ClientApplicationTests(NeoTestBase):
self.assertEquals(result, ('OBJ', tid1)) self.assertEquals(result, ('OBJ', tid1))
self.checkAskObject(conn) self.checkAskObject(conn)
self.assertTrue(oid in mq) self.assertTrue(oid in mq)
# object is now cached, try to reload it # object is now cached, try to reload it
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
}) })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
result = app.load(oid) result = app.load(oid)
self.assertEquals(result, ('OBJ', tid1)) self.assertEquals(result, ('OBJ', tid1))
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
def test_loadSerial(self): def test_loadSerial(self):
app = self.getApp() app = self.getApp()
mq = app.mq_cache mq = app.mq_cache
...@@ -265,9 +265,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -265,9 +265,9 @@ class ClientApplicationTests(NeoTestBase):
self.assertTrue(oid not in mq) self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('') packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.pt = Mock({ 'getCellListForOID': (cell, ), }) app.pt = Mock({ 'getCellListForOID': (cell, ), })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
...@@ -276,14 +276,14 @@ class ClientApplicationTests(NeoTestBase): ...@@ -276,14 +276,14 @@ class ClientApplicationTests(NeoTestBase):
self.checkAskObject(conn) self.checkAskObject(conn)
# object should not have been cached # object should not have been cached
self.assertFalse(oid in mq) self.assertFalse(oid in mq)
# now a cached version ewxists but should not be hit # now a cached version ewxists but should not be hit
mq.store(oid, (tid1, 'WRONG')) mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq) self.assertTrue(oid in mq)
another_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum('RIGHT'), 'RIGHT') another_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum('RIGHT'), 'RIGHT')
packet = Packets.AnswerObject(*another_object[1:]) packet = Packets.AnswerObject(*another_object[1:])
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = another_object app.local_var.asked_object = another_object
...@@ -302,9 +302,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -302,9 +302,9 @@ class ClientApplicationTests(NeoTestBase):
self.assertTrue(oid not in mq) self.assertTrue(oid not in mq)
packet = protocol.oidNotFound('') packet = protocol.oidNotFound('')
cell = Mock({ 'getUUID': '\x00' * 16}) cell = Mock({ 'getUUID': '\x00' * 16})
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.pt = Mock({ 'getCellListForOID': (cell, ), }) app.pt = Mock({ 'getCellListForOID': (cell, ), })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
...@@ -314,9 +314,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -314,9 +314,9 @@ class ClientApplicationTests(NeoTestBase):
# no previous versions -> return None # no previous versions -> return None
an_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum(''), '') an_object = (1, oid, tid2, INVALID_SERIAL, 0, makeChecksum(''), '')
packet = Packets.AnswerObject(*an_object[1:]) packet = Packets.AnswerObject(*an_object[1:])
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = an_object app.local_var.asked_object = an_object
...@@ -324,14 +324,14 @@ class ClientApplicationTests(NeoTestBase): ...@@ -324,14 +324,14 @@ class ClientApplicationTests(NeoTestBase):
self.assertEquals(result, None) self.assertEquals(result, None)
# object should not have been cached # object should not have been cached
self.assertFalse(oid in mq) self.assertFalse(oid in mq)
# as for loadSerial, the object is cached but should be loaded from db # as for loadSerial, the object is cached but should be loaded from db
mq.store(oid, (tid1, 'WRONG')) mq.store(oid, (tid1, 'WRONG'))
self.assertTrue(oid in mq) self.assertTrue(oid in mq)
another_object = (1, oid, tid1, tid2, 0, makeChecksum('RIGHT'), 'RIGHT') another_object = (1, oid, tid1, tid2, 0, makeChecksum('RIGHT'), 'RIGHT')
packet = Packets.AnswerObject(*another_object[1:]) packet = Packets.AnswerObject(*another_object[1:])
conn = Mock({ conn = Mock({
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.cp = Mock({ 'getConnForCell' : conn}) app.cp = Mock({ 'getConnForCell' : conn})
app.local_var.asked_object = another_object app.local_var.asked_object = another_object
...@@ -344,7 +344,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -344,7 +344,7 @@ class ClientApplicationTests(NeoTestBase):
app = self.getApp() app = self.getApp()
tid = self.makeTID() tid = self.makeTID()
txn = Mock() txn = Mock()
# first, tid is supplied # first, tid is supplied
self.assertNotEquals(getattr(app, 'tid', None), tid) self.assertNotEquals(getattr(app, 'tid', None), tid)
self.assertNotEquals(getattr(app, 'txn', None), txn) self.assertNotEquals(getattr(app, 'txn', None), txn)
packet = Packets.AnswerBeginTransaction(tid=tid) packet = Packets.AnswerBeginTransaction(tid=tid)
...@@ -392,11 +392,11 @@ class ClientApplicationTests(NeoTestBase): ...@@ -392,11 +392,11 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
app.pt = Mock({ 'getCellListForOID': (), }) app.pt = Mock({ 'getCellListForOID': (), })
app.num_partitions = 2 app.num_partitions = 2
self.assertRaises(NEOStorageError, app.store, oid, tid, '', None, txn) self.assertRaises(NEOStorageError, app.store, oid, tid, '', None, txn)
calls = app.pt.mockGetNamedCalls('getCellListForOID') calls = app.pt.mockGetNamedCalls('getCellListForOID')
self.assertEquals(len(calls), 1) self.assertEquals(len(calls), 1)
self.assertEquals(calls[0].getParam(0), oid) # oid=11 self.assertEquals(calls[0].getParam(0), oid) # oid=11
def test_store2(self): def test_store2(self):
app = self.getApp() app = self.getApp()
...@@ -407,9 +407,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -407,9 +407,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
packet = Packets.AnswerStoreObject(conflicting=1, oid=oid, serial=tid) packet = Packets.AnswerStoreObject(conflicting=1, oid=oid, serial=tid)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
}) })
cell = Mock({ cell = Mock({
'getAddress': 'FakeServer', 'getAddress': 'FakeServer',
...@@ -436,9 +436,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -436,9 +436,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn = txn app.local_var.txn = txn
app.local_var.tid = tid app.local_var.tid = tid
packet = Packets.AnswerStoreObject(conflicting=0, oid=oid, serial=tid) packet = Packets.AnswerStoreObject(conflicting=0, oid=oid, serial=tid)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.cp = Mock({ 'getConnForCell': ReturnValues(None, conn, ) }) app.cp = Mock({ 'getConnForCell': ReturnValues(None, conn, ) })
cell = Mock({ cell = Mock({
...@@ -475,9 +475,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -475,9 +475,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.tid = tid app.local_var.tid = tid
# wrong answer -> failure # wrong answer -> failure
packet = Packets.AnswerTIDs(()) packet = Packets.AnswerTIDs(())
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
'getAddress': ('127.0.0.1', 0), 'getAddress': ('127.0.0.1', 0),
}) })
cell = Mock({ cell = Mock({
...@@ -502,9 +502,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -502,9 +502,9 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.tid = tid app.local_var.tid = tid
# response -> OK # response -> OK
packet = Packets.AnswerStoreTransaction(tid=tid) packet = Packets.AnswerStoreTransaction(tid=tid)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': packet, 'fakeReceived': packet,
}) })
cell = Mock({ cell = Mock({
'getAddress': 'FakeServer', 'getAddress': 'FakeServer',
...@@ -552,9 +552,9 @@ class ClientApplicationTests(NeoTestBase): ...@@ -552,9 +552,9 @@ class ClientApplicationTests(NeoTestBase):
cell1 = Mock({ 'getNode': 'NODE1', '__hash__': 1 }) cell1 = Mock({ 'getNode': 'NODE1', '__hash__': 1 })
cell2 = Mock({ 'getNode': 'NODE2', '__hash__': 2 }) cell2 = Mock({ 'getNode': 'NODE2', '__hash__': 2 })
conn1, conn2 = Mock({ 'getNextId': 1, }), Mock({ 'getNextId': 2, }) conn1, conn2 = Mock({ 'getNextId': 1, }), Mock({ 'getNextId': 2, })
app.pt = Mock({ app.pt = Mock({
'getCellListForOID': ReturnValues((cell1, ), (cell1, )), 'getCellListForOID': ReturnValues((cell1, ), (cell1, )),
'getCellListForTID': (cell1, cell2), 'getCellListForTID': (cell1, cell2),
}) })
app.cp = Mock({ 'getConnForCell': ReturnValues(conn1, conn2), }) app.cp = Mock({ 'getConnForCell': ReturnValues(conn1, conn2), })
# fake data # fake data
...@@ -597,14 +597,14 @@ class ClientApplicationTests(NeoTestBase): ...@@ -597,14 +597,14 @@ class ClientApplicationTests(NeoTestBase):
# test callable passed to tpc_finish # test callable passed to tpc_finish
self.f_called = False self.f_called = False
self.f_called_with_tid = None self.f_called_with_tid = None
def hook(tid): def hook(tid):
self.f_called = True self.f_called = True
self.f_called_with_tid = tid self.f_called_with_tid = tid
packet = Packets.AnswerBeginTransaction(INVALID_TID) packet = Packets.AnswerBeginTransaction(INVALID_TID)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getAddress': ('127.0.0.1', 10000), 'getAddress': ('127.0.0.1', 10000),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.dispatcher = Mock({}) app.dispatcher = Mock({})
app.local_var.txn_finished = False app.local_var.txn_finished = False
...@@ -622,14 +622,14 @@ class ClientApplicationTests(NeoTestBase): ...@@ -622,14 +622,14 @@ class ClientApplicationTests(NeoTestBase):
app.local_var.txn, app.local_var.tid = txn, tid app.local_var.txn, app.local_var.tid = txn, tid
self.f_called = False self.f_called = False
self.f_called_with_tid = None self.f_called_with_tid = None
def hook(tid): def hook(tid):
self.f_called = True self.f_called = True
self.f_called_with_tid = tid self.f_called_with_tid = tid
packet = Packets.NotifyTransactionFinished(tid) packet = Packets.NotifyTransactionFinished(tid)
app.master_conn = Mock({ app.master_conn = Mock({
'getNextId': 1, 'getNextId': 1,
'getAddress': ('127.0.0.1', 10010), 'getAddress': ('127.0.0.1', 10010),
'fakeReceived': packet, 'fakeReceived': packet,
}) })
app.dispatcher = Mock({}) app.dispatcher = Mock({})
app.local_var.txn_finished = True app.local_var.txn_finished = True
...@@ -706,13 +706,13 @@ class ClientApplicationTests(NeoTestBase): ...@@ -706,13 +706,13 @@ class ClientApplicationTests(NeoTestBase):
u4p3 = Packets.AnswerStoreObject(conflicting=0, oid=oid2, serial=tid2) u4p3 = Packets.AnswerStoreObject(conflicting=0, oid=oid2, serial=tid2)
# test logic # test logic
packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3) packets = (u1p1, u1p2, u2p1, u2p2, u3p1, u3p2, u3p3, u3p1, u4p2, u4p3)
conn = Mock({ conn = Mock({
'getNextId': 1, 'getNextId': 1,
'fakeReceived': ReturnValues(*packets), 'fakeReceived': ReturnValues(*packets),
'getAddress': ('127.0.0.1', 10010), 'getAddress': ('127.0.0.1', 10010),
}) })
cell = Mock({ 'getAddress': 'FakeServer', 'getState': 'FakeState', }) cell = Mock({ 'getAddress': 'FakeServer', 'getState': 'FakeState', })
app.pt = Mock({ app.pt = Mock({
'getCellListForTID': (cell, ), 'getCellListForTID': (cell, ),
'getCellListForOID': (cell, ), 'getCellListForOID': (cell, ),
}) })
...@@ -800,7 +800,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -800,7 +800,7 @@ class ClientApplicationTests(NeoTestBase):
# the connection to the first will fail # the connection to the first will fail
# the second will have changed # the second will have changed
# the third will not be ready # the third will not be ready
# after the third, the partition table will be operational # after the third, the partition table will be operational
# (as if it was connected to the primary master node) # (as if it was connected to the primary master node)
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
# will raise IndexError at the third iteration # will raise IndexError at the third iteration
...@@ -828,7 +828,7 @@ class ClientApplicationTests(NeoTestBase): ...@@ -828,7 +828,7 @@ class ClientApplicationTests(NeoTestBase):
Application._waitMessage = _waitMessage6 Application._waitMessage = _waitMessage6
# third iteration : node not ready # third iteration : node not ready
def _waitMessage4(app, conn=None, msg_id=None, handler=None): def _waitMessage4(app, conn=None, msg_id=None, handler=None):
app.setNodeNotReady() app.setNodeNotReady()
app.trying_master_node = None app.trying_master_node = None
Application._waitMessage = _waitMessage5 Application._waitMessage = _waitMessage5
# second iteration : master node changed # second iteration : master node changed
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -92,8 +92,8 @@ class ClientHandlerTests(NeoTestBase): ...@@ -92,8 +92,8 @@ class ClientHandlerTests(NeoTestBase):
storage_port = 10011 storage_port = 10011
fake_storage_node_uuid = self.getNewUUID() fake_storage_node_uuid = self.getNewUUID()
fake_storage_node = Mock({ fake_storage_node = Mock({
'getUUID': fake_storage_node_uuid, 'getUUID': fake_storage_node_uuid,
'getAddress': (storage_ip, storage_port), 'getAddress': (storage_ip, storage_port),
'getType': NodeTypes.STORAGE 'getType': NodeTypes.STORAGE
}) })
master_node_next_packet_id = 1 master_node_next_packet_id = 1
...@@ -121,7 +121,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -121,7 +121,7 @@ class ClientHandlerTests(NeoTestBase):
key_2: queue_2} key_2: queue_2}
dispatcher = Dispatcher() dispatcher = Dispatcher()
method(dispatcher, app, handler_class, conn=conn) method(dispatcher, app, handler_class, conn=conn)
# The master should be notified, but this is done in app.py # The master should be notified, but this is done in app.py
# Check that failed connection got removed from connection pool # Check that failed connection got removed from connection pool
removeConnection_call_list = app.cp.mockGetNamedCalls('removeConnection') removeConnection_call_list = app.cp.mockGetNamedCalls('removeConnection')
# Test sanity check # Test sanity check
...@@ -143,7 +143,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -143,7 +143,7 @@ class ClientHandlerTests(NeoTestBase):
self._testInitialMasterWithMethod(self._testConnectionFailed) self._testInitialMasterWithMethod(self._testConnectionFailed)
def test_storageConnectionFailed(self): def test_storageConnectionFailed(self):
self._testStorageWithMethod(self._testConnectionFailed, self._testStorageWithMethod(self._testConnectionFailed,
StorageBootstrapHandler) StorageBootstrapHandler)
def _testConnectionClosed(self, dispatcher, app, handler_class, uuid=None, conn=None): def _testConnectionClosed(self, dispatcher, app, handler_class, uuid=None, conn=None):
...@@ -160,7 +160,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -160,7 +160,7 @@ class ClientHandlerTests(NeoTestBase):
PrimaryNotificationsHandler) PrimaryNotificationsHandler)
def test_storageConnectionClosed(self): def test_storageConnectionClosed(self):
self._testStorageWithMethod(self._testConnectionClosed, self._testStorageWithMethod(self._testConnectionClosed,
StorageBootstrapHandler) StorageBootstrapHandler)
def _testTimeoutExpired(self, dispatcher, app, handler_class, uuid=None, conn=None): def _testTimeoutExpired(self, dispatcher, app, handler_class, uuid=None, conn=None):
...@@ -176,7 +176,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -176,7 +176,7 @@ class ClientHandlerTests(NeoTestBase):
self._testMasterWithMethod(self._testTimeoutExpired, PrimaryNotificationsHandler) self._testMasterWithMethod(self._testTimeoutExpired, PrimaryNotificationsHandler)
def test_storageTimeoutExpired(self): def test_storageTimeoutExpired(self):
self._testStorageWithMethod(self._testTimeoutExpired, self._testStorageWithMethod(self._testTimeoutExpired,
StorageBootstrapHandler) StorageBootstrapHandler)
def _testPeerBroken(self, dispatcher, app, handler_class, uuid=None, conn=None): def _testPeerBroken(self, dispatcher, app, handler_class, uuid=None, conn=None):
...@@ -215,9 +215,9 @@ class ClientHandlerTests(NeoTestBase): ...@@ -215,9 +215,9 @@ class ClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
app.uuid = 'C' * 16 app.uuid = 'C' * 16
client_handler.acceptIdentification( client_handler.acceptIdentification(
conn, None, conn, None,
NodeTypes.CLIENT, NodeTypes.CLIENT,
uuid, ('127.0.0.1', 10010), uuid, ('127.0.0.1', 10010),
0, 0, INVALID_UUID 0, 0, INVALID_UUID
) )
self.checkClosed(conn) self.checkClosed(conn)
...@@ -242,7 +242,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -242,7 +242,7 @@ class ClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
your_uuid = 'C' * 16 your_uuid = 'C' * 16
app.uuid = INVALID_UUID app.uuid = INVALID_UUID
client_handler.AcceptIdentification(conn, None, client_handler.AcceptIdentification(conn, None,
NodeTypes.MASTER, uuid, ('127.0.0.1', 10010), 10, 2, your_uuid) NodeTypes.MASTER, uuid, ('127.0.0.1', 10010), 10, 2, your_uuid)
self.checkNotClosed(conn) self.checkNotClosed(conn)
self.checkUUIDSet(conn, uuid) self.checkUUIDSet(conn, uuid)
...@@ -262,7 +262,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -262,7 +262,7 @@ class ClientHandlerTests(NeoTestBase):
conn = self.getConnection() conn = self.getConnection()
uuid = self.getNewUUID() uuid = self.getNewUUID()
app.uuid = 'C' * 16 app.uuid = 'C' * 16
client_handler.acceptIdentification(conn, None, client_handler.acceptIdentification(conn, None,
NodeTypes.STORAGE, uuid, ('127.0.0.1', 10010), 0, 0, INVALID_UUID) NodeTypes.STORAGE, uuid, ('127.0.0.1', 10010), 0, 0, INVALID_UUID)
self.checkNotClosed(conn) self.checkNotClosed(conn)
self.checkUUIDSet(conn, uuid) self.checkUUIDSet(conn, uuid)
...@@ -538,7 +538,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -538,7 +538,7 @@ class ClientHandlerTests(NeoTestBase):
conn, None, None) conn, None, None)
def _testNotifyNodeInformation(self, test_node, getByAddress=None, getByUUID=MARKER): def _testNotifyNodeInformation(self, test_node, getByAddress=None, getByUUID=MARKER):
invalid_uid_test_node = (test_node[0], (test_node[1][0], invalid_uid_test_node = (test_node[0], (test_node[1][0],
test_node[1][1] + 1), INVALID_UUID, test_node[3]) test_node[1][1] + 1), INVALID_UUID, test_node[3])
test_node_list = [test_node, invalid_uid_test_node] test_node_list = [test_node, invalid_uid_test_node]
test_master_uuid = self.getNewUUID() test_master_uuid = self.getNewUUID()
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -128,7 +128,7 @@ class NEOCluster(object): ...@@ -128,7 +128,7 @@ class NEOCluster(object):
partitions=1, replicas=0, port_base=10000, partitions=1, replicas=0, port_base=10000,
db_user='neo', db_password='neo', db_user='neo', db_password='neo',
db_super_user='root', db_super_password=None, db_super_user='root', db_super_password=None,
cleanup_on_delete=False, temp_dir=None, cleanup_on_delete=False, temp_dir=None,
clear_databases=True, adapter='MySQL'): clear_databases=True, adapter='MySQL'):
self.cleanup_on_delete = cleanup_on_delete self.cleanup_on_delete = cleanup_on_delete
self.uuid_set = set() self.uuid_set = set()
...@@ -187,7 +187,7 @@ class NEOCluster(object): ...@@ -187,7 +187,7 @@ class NEOCluster(object):
arguments['--verbose'] = None arguments['--verbose'] = None
logfile = arguments['--name'] logfile = arguments['--name']
arguments['--logfile'] = os.path.join(self.temp_dir, '%s.log' % (logfile, )) arguments['--logfile'] = os.path.join(self.temp_dir, '%s.log' % (logfile, ))
self.process_dict.setdefault(command, []).append( self.process_dict.setdefault(command, []).append(
NEOProcess(command, uuid, arguments)) NEOProcess(command, uuid, arguments))
def __allocatePort(self): def __allocatePort(self):
...@@ -387,13 +387,13 @@ class NEOCluster(object): ...@@ -387,13 +387,13 @@ class NEOCluster(object):
current_try = self.__getNodeState(node_type, uuid) current_try = self.__getNodeState(node_type, uuid)
return current_try in state, current_try return current_try in state, current_try
self.expectCondition(callback, timeout, delay) self.expectCondition(callback, timeout, delay)
def expectMasterState(self, uuid, state, timeout=0, delay=1): def expectMasterState(self, uuid, state, timeout=0, delay=1):
self.__expectNodeState(NodeTypes.MASTER, uuid, state, timeout, self.__expectNodeState(NodeTypes.MASTER, uuid, state, timeout,
delay) delay)
def expectStorageState(self, uuid, state, timeout=0, delay=1): def expectStorageState(self, uuid, state, timeout=0, delay=1):
self.__expectNodeState(NodeTypes.STORAGE, uuid, state, self.__expectNodeState(NodeTypes.STORAGE, uuid, state,
timeout,delay) timeout,delay)
def expectPrimary(self, uuid=None, timeout=0, delay=1): def expectPrimary(self, uuid=None, timeout=0, delay=1):
...@@ -464,5 +464,5 @@ class NEOFunctionalTest(unittest.TestCase): ...@@ -464,5 +464,5 @@ class NEOFunctionalTest(unittest.TestCase):
if not os.path.exists(temp_dir): if not os.path.exists(temp_dir):
os.makedirs(temp_dir) os.makedirs(temp_dir)
return temp_dir return temp_dir
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -29,7 +29,7 @@ class ClusterTests(NEOFunctionalTest): ...@@ -29,7 +29,7 @@ class ClusterTests(NEOFunctionalTest):
self.neo.stop() self.neo.stop()
def testClusterBreaks(self): def testClusterBreaks(self):
self.neo = NEOCluster(['test_neo1'], port_base=20000, self.neo = NEOCluster(['test_neo1'], port_base=20000,
master_node_count=1, temp_dir=self.getTempDirectory()) master_node_count=1, temp_dir=self.getTempDirectory())
neoctl = self.neo.getNEOCTL() neoctl = self.neo.getNEOCTL()
self.neo.setupDB() self.neo.setupDB()
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -69,7 +69,7 @@ class ImportExportTests(NEOFunctionalTest): ...@@ -69,7 +69,7 @@ class ImportExportTests(NEOFunctionalTest):
storage = FileStorage(file_name=name) storage = FileStorage(file_name=name)
db = ZODB.DB(storage=storage) db = ZODB.DB(storage=storage)
return (db, storage) return (db, storage)
def __populate(self, db, tree_size=TREE_SIZE): def __populate(self, db, tree_size=TREE_SIZE):
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
...@@ -111,7 +111,7 @@ class ImportExportTests(NEOFunctionalTest): ...@@ -111,7 +111,7 @@ class ImportExportTests(NEOFunctionalTest):
root = conn.root() root = conn.root()
self.__checkTree(root['trees']) self.__checkTree(root['trees'])
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -26,7 +26,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -26,7 +26,7 @@ class MasterTests(NEOFunctionalTest):
def setUp(self): def setUp(self):
NEOFunctionalTest.setUp(self) NEOFunctionalTest.setUp(self)
self.neo = NEOCluster([], port_base=20000, self.neo = NEOCluster([], port_base=20000,
master_node_count=MASTER_NODE_COUNT, master_node_count=MASTER_NODE_COUNT,
temp_dir=self.getTempDirectory()) temp_dir=self.getTempDirectory())
self.neo.stop() self.neo.stop()
...@@ -68,7 +68,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -68,7 +68,7 @@ class MasterTests(NEOFunctionalTest):
self.assertNotEqual(new_uuid, uuid) self.assertNotEqual(new_uuid, uuid)
def testStoppingPrimaryWithOneSecondary(self): def testStoppingPrimaryWithOneSecondary(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT, self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=NodeStates.RUNNING) state=NodeStates.RUNNING)
# Kill one secondary master. # Kill one secondary master.
...@@ -92,7 +92,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -92,7 +92,7 @@ class MasterTests(NEOFunctionalTest):
self.assertNotEqual(new_uuid, uuid) self.assertNotEqual(new_uuid, uuid)
def testMasterSequentialStart(self): def testMasterSequentialStart(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT, self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=NodeStates.RUNNING) state=NodeStates.RUNNING)
master_list = self.neo.getMasterProcessList() master_list = self.neo.getMasterProcessList()
...@@ -112,11 +112,11 @@ class MasterTests(NEOFunctionalTest): ...@@ -112,11 +112,11 @@ class MasterTests(NEOFunctionalTest):
# Start a second master. # Start a second master.
second_master = master_list[1] second_master = master_list[1]
# Check that the second master is known as being down. # Check that the second master is known as being down.
self.assertEqual(self.neo.getMasterNodeState(second_master.getUUID()), self.assertEqual(self.neo.getMasterNodeState(second_master.getUUID()),
None) None)
second_master.start() second_master.start()
# Check that the second master is running under his known UUID. # Check that the second master is running under his known UUID.
self.neo.expectMasterState(second_master.getUUID(), self.neo.expectMasterState(second_master.getUUID(),
NodeStates.RUNNING) NodeStates.RUNNING)
# Check that the primary master didn't change. # Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimary(), first_master_uuid) self.assertEqual(self.neo.getPrimary(), first_master_uuid)
...@@ -124,11 +124,11 @@ class MasterTests(NEOFunctionalTest): ...@@ -124,11 +124,11 @@ class MasterTests(NEOFunctionalTest):
# Start a third master. # Start a third master.
third_master = master_list[2] third_master = master_list[2]
# Check that the third master is known as being down. # Check that the third master is known as being down.
self.assertEqual(self.neo.getMasterNodeState(third_master.getUUID()), self.assertEqual(self.neo.getMasterNodeState(third_master.getUUID()),
None) None)
third_master.start() third_master.start()
# Check that the third master is running under his known UUID. # Check that the third master is running under his known UUID.
self.neo.expectMasterState(third_master.getUUID(), self.neo.expectMasterState(third_master.getUUID(),
NodeStates.RUNNING) NodeStates.RUNNING)
# Check that the primary master didn't change. # Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimary(), first_master_uuid) self.assertEqual(self.neo.getPrimary(), first_master_uuid)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -23,7 +23,7 @@ from neo.tests.functional import NEOCluster, NEOFunctionalTest ...@@ -23,7 +23,7 @@ from neo.tests.functional import NEOCluster, NEOFunctionalTest
from neo.protocol import ClusterStates, NodeStates from neo.protocol import ClusterStates, NodeStates
class PObject(Persistent): class PObject(Persistent):
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
...@@ -45,7 +45,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -45,7 +45,7 @@ class StorageTests(NEOFunctionalTest):
result = db.store_result().fetch_row()[0][0] result = db.store_result().fetch_row()[0][0]
return result return result
def __setup(self, storage_number=2, pending_number=0, replicas=1, def __setup(self, storage_number=2, pending_number=0, replicas=1,
partitions=10, master_node_count=2): partitions=10, master_node_count=2):
# create a neo cluster # create a neo cluster
self.neo = NEOCluster(['test_neo%d' % i for i in xrange(storage_number)], self.neo = NEOCluster(['test_neo%d' % i for i in xrange(storage_number)],
...@@ -68,7 +68,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -68,7 +68,7 @@ class StorageTests(NEOFunctionalTest):
db, conn = self.neo.getZODBConnection() db, conn = self.neo.getZODBConnection()
root = conn.root() root = conn.root()
for i in xrange(OBJECT_NUMBER): for i in xrange(OBJECT_NUMBER):
root[i] = PObject(i) root[i] = PObject(i)
transaction.commit() transaction.commit()
conn.close() conn.close()
db.close() db.close()
...@@ -86,7 +86,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -86,7 +86,7 @@ class StorageTests(NEOFunctionalTest):
# One revision per object and two for the root, before and after # One revision per object and two for the root, before and after
revisions = self.queryCount(db, 'select count(*) from obj') revisions = self.queryCount(db, 'select count(*) from obj')
self.assertEqual(revisions, OBJECT_NUMBER + 2) self.assertEqual(revisions, OBJECT_NUMBER + 2)
# One object more for the root # One object more for the root
query = 'select count(*) from (select * from obj group by oid) as t' query = 'select count(*) from (select * from obj group by oid) as t'
objects = self.queryCount(db, query) objects = self.queryCount(db, query)
self.assertEqual(objects, OBJECT_NUMBER + 1) self.assertEqual(objects, OBJECT_NUMBER + 1)
...@@ -111,7 +111,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -111,7 +111,7 @@ class StorageTests(NEOFunctionalTest):
def __expectPending(self, process): def __expectPending(self, process):
self.neo.expectStorageState(process.getUUID(), NodeStates.PENDING) self.neo.expectStorageState(process.getUUID(), NodeStates.PENDING)
def __expectUnavailable(self, process): def __expectUnavailable(self, process):
self.neo.expectStorageState(process.getUUID(), self.neo.expectStorageState(process.getUUID(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
...@@ -124,7 +124,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -124,7 +124,7 @@ class StorageTests(NEOFunctionalTest):
return False, storage return False, storage
return True, None return True, None
self.neo.expectCondition(expected_storage_not_known) self.neo.expectCondition(expected_storage_not_known)
def testReplicationWithoutBreak(self): def testReplicationWithoutBreak(self):
""" Start a cluster with two storage, one replicas, the two databasqes """ Start a cluster with two storage, one replicas, the two databasqes
must have the same content """ must have the same content """
...@@ -178,7 +178,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -178,7 +178,7 @@ class StorageTests(NEOFunctionalTest):
self.neo.expectAssignedCells(stopped[0].getUUID(), number=10) self.neo.expectAssignedCells(stopped[0].getUUID(), number=10)
self.neo.expectClusterRunning() self.neo.expectClusterRunning()
# wait for replication to finish then check # wait for replication to finish then check
self.__checkReplicationDone() self.__checkReplicationDone()
self.neo.expectClusterRunning() self.neo.expectClusterRunning()
...@@ -284,7 +284,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -284,7 +284,7 @@ class StorageTests(NEOFunctionalTest):
with one storage and no replicas """ with one storage and no replicas """
# start with one storage and no replicas # start with one storage and no replicas
(started, stopped) = self.__setup(storage_number=2, pending_number=1, (started, stopped) = self.__setup(storage_number=2, pending_number=1,
partitions=10, replicas=0) partitions=10, replicas=0)
self.__expectRunning(started[0]) self.__expectRunning(started[0])
self.neo.expectClusterRunning() self.neo.expectClusterRunning()
...@@ -299,10 +299,10 @@ class StorageTests(NEOFunctionalTest): ...@@ -299,10 +299,10 @@ class StorageTests(NEOFunctionalTest):
self.neo.expectClusterRunning() self.neo.expectClusterRunning()
self.neo.expectOudatedCells(number=0) self.neo.expectOudatedCells(number=0)
# the partition table must change, each node should be assigned to # the partition table must change, each node should be assigned to
# five partitions # five partitions
self.neo.expectAssignedCells(started[0].getUUID(), 5) self.neo.expectAssignedCells(started[0].getUUID(), 5)
self.neo.expectAssignedCells(stopped[0].getUUID(), 5) self.neo.expectAssignedCells(stopped[0].getUUID(), 5)
def testPartitionTableReorganizedAfterDrop(self): def testPartitionTableReorganizedAfterDrop(self):
""" Check that the partition change when dropping a replicas from a """ Check that the partition change when dropping a replicas from a
...@@ -324,7 +324,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -324,7 +324,7 @@ class StorageTests(NEOFunctionalTest):
# and the partition table must not change # and the partition table must not change
self.neo.expectAssignedCells(started[0].getUUID(), 10) self.neo.expectAssignedCells(started[0].getUUID(), 10)
self.neo.expectAssignedCells(started[1].getUUID(), 10) self.neo.expectAssignedCells(started[1].getUUID(), 10)
# ask neoctl to drop it # ask neoctl to drop it
self.neo.neoctl.dropNode(started[0].getUUID()) self.neo.neoctl.dropNode(started[0].getUUID())
self.__expectNotKnown(started[0]) self.__expectNotKnown(started[0])
...@@ -335,7 +335,7 @@ class StorageTests(NEOFunctionalTest): ...@@ -335,7 +335,7 @@ class StorageTests(NEOFunctionalTest):
""" Add a replicas to a cluster, wait for the replication to finish, """ Add a replicas to a cluster, wait for the replication to finish,
shutdown the first storage then check the new storage content """ shutdown the first storage then check the new storage content """
# start with one storage # start with one storage
(started, stopped) = self.__setup(storage_number=2, replicas=1, (started, stopped) = self.__setup(storage_number=2, replicas=1,
pending_number=1, partitions=10) pending_number=1, partitions=10)
self.__expectRunning(started[0]) self.__expectRunning(started[0])
...@@ -416,6 +416,6 @@ class StorageTests(NEOFunctionalTest): ...@@ -416,6 +416,6 @@ class StorageTests(NEOFunctionalTest):
self.__expectPending(started[0]) self.__expectPending(started[0])
self.__expectRunning(started[1]) self.__expectRunning(started[1])
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -50,7 +50,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -50,7 +50,7 @@ class MasterClientHandlerTests(NeoTestBase):
# register the storage # register the storage
kw = {'uuid':self.getNewUUID(), 'address': self.master_address} kw = {'uuid':self.getNewUUID(), 'address': self.master_address}
self.app.nm.createStorage(**kw) self.app.nm.createStorage(**kw)
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -64,7 +64,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -64,7 +64,7 @@ class MasterClientHandlerTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
self.app.nm.createFromNodeType( self.app.nm.createFromNodeType(
node_type, node_type,
address=(ip, port), address=(ip, port),
uuid=uuid, uuid=uuid,
state=NodeStates.RUNNING, state=NodeStates.RUNNING,
) )
...@@ -104,7 +104,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -104,7 +104,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care # notify about a known node but with bad address, don't care
self.app.nm.createStorage( self.app.nm.createStorage(
address=("127.0.0.1", 11011), address=("127.0.0.1", 11011),
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
...@@ -141,7 +141,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -141,7 +141,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(sn.getState(), NodeStates.BROKEN) self.assertEquals(sn.getState(), NodeStates.BROKEN)
self.failUnless(ptid < self.app.pt.getID()) self.failUnless(ptid < self.app.pt.getID())
def test_06_answerLastIDs(self): def test_06_answerLastIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
...@@ -167,9 +167,9 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -167,9 +167,9 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(loid, self.app.loid) self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid) self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
def test_07_askBeginTransaction(self):
def test_07_askBeginTransaction(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packets.AskBeginTransaction() packet = Packets.AskBeginTransaction()
...@@ -184,7 +184,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -184,7 +184,7 @@ class MasterClientHandlerTests(NeoTestBase):
tid = self.app.finishing_transaction_dict.keys()[0] tid = self.app.finishing_transaction_dict.keys()[0]
self.assertEquals(tid, self.app.ltid) self.assertEquals(tid, self.app.ltid)
def test_08_askNewOIDs(self): def test_08_askNewOIDs(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packets.AskNewOIDs() packet = Packets.AskNewOIDs()
...@@ -243,7 +243,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -243,7 +243,7 @@ class MasterClientHandlerTests(NeoTestBase):
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
service.abortTransaction(conn, packet, None) service.abortTransaction(conn, packet, None)
self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEqual(len(self.app.finishing_transaction_dict.keys()), 0)
# give a known tid # give a known tid
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
tid = self.app.ltid tid = self.app.ltid
...@@ -268,7 +268,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -268,7 +268,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEqual(loid, self.app.loid) self.assertEqual(loid, self.app.loid)
self.assertEqual(ltid, self.app.ltid) self.assertEqual(ltid, self.app.ltid)
self.assertEqual(lptid, ptid) self.assertEqual(lptid, ptid)
def test_13_askUnfinishedTransactions(self): def test_13_askUnfinishedTransactions(self):
service = self.service service = self.service
...@@ -292,7 +292,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -292,7 +292,7 @@ class MasterClientHandlerTests(NeoTestBase):
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet) packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3) self.assertEqual(len(tid_list), 3)
def test_15_peerBroken(self): def test_15_peerBroken(self):
service = self.service service = self.service
...@@ -310,14 +310,14 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -310,14 +310,14 @@ class MasterClientHandlerTests(NeoTestBase):
NodeStates.RUNNING) NodeStates.RUNNING)
service.peerBroken(conn) service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN) NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn) self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -333,10 +333,10 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -333,10 +333,10 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn) service.peerBroken(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_16_timeoutExpired(self): def test_16_timeoutExpired(self):
service = self.service service = self.service
...@@ -354,14 +354,14 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -354,14 +354,14 @@ class MasterClientHandlerTests(NeoTestBase):
NodeStates.RUNNING) NodeStates.RUNNING)
service.timeoutExpired(conn) service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn) self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -377,7 +377,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -377,7 +377,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn) service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
...@@ -398,14 +398,14 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -398,14 +398,14 @@ class MasterClientHandlerTests(NeoTestBase):
NodeStates.RUNNING) NodeStates.RUNNING)
service.connectionClosed(conn) service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn) self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -421,7 +421,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -421,7 +421,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn) service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -21,7 +21,7 @@ from neo.tests import NeoTestBase ...@@ -21,7 +21,7 @@ from neo.tests import NeoTestBase
from neo.protocol import Packet, Packets, NodeTypes, NodeStates, INVALID_UUID from neo.protocol import Packet, Packets, NodeTypes, NodeStates, INVALID_UUID
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
from neo.master.app import Application from neo.master.app import Application
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
...@@ -61,7 +61,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -61,7 +61,7 @@ class MasterClientElectionTests(NeoTestBase):
self.expectMessage = ClientConnection.expectMessage self.expectMessage = ClientConnection.expectMessage
ClientConnection._addPacket = _addPacket ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage ClientConnection.expectMessage = expectMessage
def tearDown(self): def tearDown(self):
# restore patched methods # restore patched methods
ClientConnection._addPacket = self._addPacket ClientConnection._addPacket = self._addPacket
...@@ -84,7 +84,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -84,7 +84,7 @@ class MasterClientElectionTests(NeoTestBase):
self.election.connectionStarted(conn) self.election.connectionStarted(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
def test_02_connectionCompleted(self): def test_02_connectionCompleted(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
...@@ -92,7 +92,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -92,7 +92,7 @@ class MasterClientElectionTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.election.connectionCompleted(conn) self.election.connectionCompleted(conn)
self.checkAskPrimary(conn) self.checkAskPrimary(conn)
def test_03_connectionFailed(self): def test_03_connectionFailed(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
...@@ -122,7 +122,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -122,7 +122,7 @@ class MasterClientElectionTests(NeoTestBase):
"getConnector": Mock(), "getConnector": Mock(),
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(len(self.app.nm.getMasterList()), 2) self.assertEqual(len(self.app.nm.getMasterList()), 2)
election.askPrimary(conn, packet) election.askPrimary(conn, packet)
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1) self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0) self.assertEquals(len(conn.mockGetNamedCalls("abort")), 0)
self.checkAnswerPrimary(conn) self.checkAnswerPrimary(conn)
...@@ -234,10 +234,10 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -234,10 +234,10 @@ class MasterClientElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
self.assertNotEqual(self.app.primary_master_node, None) self.assertNotEqual(self.app.primary_master_node, None)
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
# Now tell it's another node which is primary, it must raise # Now tell it's another node which is primary, it must raise
self.assertRaises(ElectionFailure, self.election.answerPrimary, conn, p, uuid, []) self.assertRaises(ElectionFailure, self.election.answerPrimary, conn, p, uuid, [])
class MasterServerElectionTests(NeoTestBase): class MasterServerElectionTests(NeoTestBase):
...@@ -265,7 +265,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -265,7 +265,7 @@ class MasterServerElectionTests(NeoTestBase):
self.expectMessage = ClientConnection.expectMessage self.expectMessage = ClientConnection.expectMessage
ClientConnection._addPacket = _addPacket ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage ClientConnection.expectMessage = expectMessage
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
# restore environnement # restore environnement
...@@ -279,7 +279,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -279,7 +279,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
return uuid return uuid
def checkCalledAskPrimary(self, conn, packet_number=0): def checkCalledAskPrimary(self, conn, packet_number=0):
""" Check ask primary master has been send""" """ Check ask primary master has been send"""
call = conn.mockGetNamedCalls("_addPacket")[packet_number] call = conn.mockGetNamedCalls("_addPacket")[packet_number]
...@@ -384,14 +384,14 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -384,14 +384,14 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.AcceptIdentification(conn, p, NodeTypes.STORAGE, self.election.AcceptIdentification(conn, p, NodeTypes.STORAGE,
uuid, "127.0.0.1", self.master_port, uuid, "127.0.0.1", self.master_port,
self.app.pt.getPartitions(), self.app.pt.getPartitions(),
self.app.pt.getReplicas(), self.app.pt.getReplicas(),
self.app.uuid self.app.uuid
) )
self.assertEqual(conn.getConnector(), None) self.assertEqual(conn.getConnector(), None)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
def test_08_AcceptIdentification2(self): def test_08_AcceptIdentification2(self):
# test with bad address, must be rejected # test with bad address, must be rejected
uuid = self.getNewUUID() uuid = self.getNewUUID()
...@@ -407,7 +407,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -407,7 +407,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.AcceptIdentification(conn, p, NodeTypes.STORAGE, self.election.AcceptIdentification(conn, p, NodeTypes.STORAGE,
uuid, ("127.0.0.2", self.master_port), uuid, ("127.0.0.2", self.master_port),
self.app.pt.getPartitions(), self.app.pt.getPartitions(),
self.app.pt.getReplicas(), self.app.pt.getReplicas(),
self.app.uuid) self.app.uuid)
self.assertEqual(conn.getConnector(), None) self.assertEqual(conn.getConnector(), None)
...@@ -428,19 +428,19 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -428,19 +428,19 @@ class MasterServerElectionTests(NeoTestBase):
self.election.AcceptIdentification(conn, p, NodeTypes.MASTER, self.election.AcceptIdentification(conn, p, NodeTypes.MASTER,
uuid, ("127.0.0.1", self.master_port), uuid, ("127.0.0.1", self.master_port),
self.app.pt.getPartitions(), self.app.pt.getPartitions(),
self.app.pt.getReplicas(), self.app.pt.getReplicas(),
self.app.uuid) self.app.uuid)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), uuid) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), uuid)
self.assertEqual(conn.getUUID(), uuid) self.assertEqual(conn.getUUID(), uuid)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),2) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),2)
self.checkCalledAskPrimary(conn.getConnector(), 1) self.checkCalledAskPrimary(conn.getConnector(), 1)
def test_10_RequestIdentification(self): def test_10_RequestIdentification(self):
election = self.election election = self.election
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port), args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port),
'INVALID_NAME') 'INVALID_NAME')
packet = Packets.RequestIdentification(*args) packet = Packets.RequestIdentification(*args)
# test alien cluster # test alien cluster
...@@ -517,7 +517,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -517,7 +517,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid=new_uuid, uuid=new_uuid,
ip_address='127.0.0.1', ip_address='127.0.0.1',
port=self.master_port+1, port=self.master_port+1,
name=self.app.name,) name=self.app.name,)
def test_12_announcePrimary(self): def test_12_announcePrimary(self):
...@@ -538,7 +538,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -538,7 +538,7 @@ class MasterServerElectionTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.assertEqual(self.app.primary, None) self.assertEqual(self.app.primary, None)
self.assertEqual(self.app.primary_master_node, None) self.assertEqual(self.app.primary_master_node, None)
election.announcePrimary(conn, packet) election.announcePrimary(conn, packet)
self.assertEqual(self.app.primary, False) self.assertEqual(self.app.primary, False)
self.assertNotEqual(self.app.primary_master_node, None) self.assertNotEqual(self.app.primary_master_node, None)
# set current as primary, and announce another, must raise # set current as primary, and announce another, must raise
...@@ -548,8 +548,8 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -548,8 +548,8 @@ class MasterServerElectionTests(NeoTestBase):
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
self.app.primary = True self.app.primary = True
self.assertEqual(self.app.primary, True) self.assertEqual(self.app.primary, True)
self.assertRaises(ElectionFailure, election.announcePrimary, conn, packet) self.assertRaises(ElectionFailure, election.announcePrimary, conn, packet)
def test_13_reelectPrimary(self): def test_13_reelectPrimary(self):
election = self.election election = self.election
...@@ -573,7 +573,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -573,7 +573,7 @@ class MasterServerElectionTests(NeoTestBase):
self.checkIdenficationRequired(election.notifyNodeInformation, conn, packet, node_list) self.checkIdenficationRequired(election.notifyNodeInformation, conn, packet, node_list)
# tell the master node about itself, must do nothing # tell the master node about itself, must do nothing
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port - 1), node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port - 1),
self.app.uuid, NodeStates.DOWN),] self.app.uuid, NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
...@@ -583,7 +583,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -583,7 +583,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(node, None) self.assertEqual(node, None)
# tell about a storage node, do nothing # tell about a storage node, do nothing
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.master_port - 1), node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.master_port - 1),
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
...@@ -591,7 +591,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -591,7 +591,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
# tell about a client node, do nothing # tell about a client node, do nothing
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.master_port - 1), node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.master_port - 1),
self.getNewUUID(), NodeStates.DOWN),] self.getNewUUID(), NodeStates.DOWN),]
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
...@@ -599,7 +599,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -599,7 +599,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getNodeList()), 0) self.assertEqual(len(self.app.nm.getNodeList()), 0)
# tell about another master node # tell about another master node
conn = Mock({"getUUID" : uuid, conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.master_port)}) "getAddress" : ("127.0.0.1", self.master_port)})
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port + 1), node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port + 1),
self.getNewUUID(), NodeStates.RUNNING),] self.getNewUUID(), NodeStates.RUNNING),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1))
...@@ -618,7 +618,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -618,7 +618,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1)) self.assertEqual(node.getAddress(), ("127.0.0.1", self.master_port+1))
self.assertEqual(node.getState(), NodeStates.DOWN) self.assertEqual(node.getState(), NodeStates.DOWN)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -49,11 +49,11 @@ class MasterAppTests(NeoTestBase): ...@@ -49,11 +49,11 @@ class MasterAppTests(NeoTestBase):
def test_06_broadcastNodeInformation(self): def test_06_broadcastNodeInformation(self):
# defined some nodes to which data will be send # defined some nodes to which data will be send
master_uuid = self.getNewUUID() master_uuid = self.getNewUUID()
self.app.nm.createMaster(uuid=master_uuid) self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID() storage_uuid = self.getNewUUID()
storage = self.app.nm.createStorage(uuid=storage_uuid) storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID() client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid) client = self.app.nm.createClient(uuid=client_uuid)
self.app.nm.add(storage) self.app.nm.add(storage)
self.app.nm.add(client) self.app.nm.add(client)
...@@ -77,7 +77,7 @@ class MasterAppTests(NeoTestBase): ...@@ -77,7 +77,7 @@ class MasterAppTests(NeoTestBase):
client_conn = Mock({"getUUID" : client_uuid}) client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)}) self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = self.app.nm.createClient( s_node = self.app.nm.createClient(
uuid = self.getNewUUID(), uuid = self.getNewUUID(),
address=("127.1.0.1", 3361) address=("127.1.0.1", 3361)
) )
self.app.broadcastNodeInformation(c_node) self.app.broadcastNodeInformation(c_node)
...@@ -85,14 +85,14 @@ class MasterAppTests(NeoTestBase): ...@@ -85,14 +85,14 @@ class MasterAppTests(NeoTestBase):
self.checkNoPacketSent(client_conn) self.checkNoPacketSent(client_conn)
self.checkNotifyNodeInformation(master_conn) self.checkNotifyNodeInformation(master_conn)
self.checkNotifyNodeInformation(storage_conn) self.checkNotifyNodeInformation(storage_conn)
# address defined and storage type # address defined and storage type
master_conn = Mock({"getUUID" : master_uuid}) master_conn = Mock({"getUUID" : master_uuid})
storage_conn = Mock({"getUUID" : storage_uuid}) storage_conn = Mock({"getUUID" : storage_uuid})
client_conn = Mock({"getUUID" : client_uuid}) client_conn = Mock({"getUUID" : client_uuid})
self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)}) self.app.em = Mock({"getConnectionList" : (master_conn, storage_conn, client_conn)})
s_node = self.app.nm.createStorage( s_node = self.app.nm.createStorage(
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
address=("127.0.0.1", 1351) address=("127.0.0.1", 1351)
) )
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -154,7 +154,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -154,7 +154,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(cells), 1) self.assertEqual(len(cells), 1)
cell = cells[0] cell = cells[0]
self.assertEqual(cell.getState(), CellStates.UP_TO_DATE) self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
def test_14_addNode(self): def test_14_addNode(self):
num_partitions = 5 num_partitions = 5
num_replicas = 2 num_replicas = 2
...@@ -233,9 +233,9 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -233,9 +233,9 @@ class MasterPartitionTableTests(NeoTestBase):
else: else:
self.failUnless(uuid in (uuid1, uuid6)) self.failUnless(uuid in (uuid1, uuid6))
else: else:
self.failUnless(offset in (0, 1)) self.failUnless(offset in (0, 1))
for x in xrange(num_replicas): for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 2) self.assertEqual(len(pt.getCellList(x)), 2)
# there is a feeding cell, just dropped # there is a feeding cell, just dropped
pt.clear() pt.clear()
pt.setCell(0, sn1, CellStates.UP_TO_DATE) pt.setCell(0, sn1, CellStates.UP_TO_DATE)
...@@ -262,9 +262,9 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -262,9 +262,9 @@ class MasterPartitionTableTests(NeoTestBase):
else: else:
self.failUnless(uuid in (uuid1, uuid6)) self.failUnless(uuid in (uuid1, uuid6))
else: else:
self.failUnless(offset in (0, 1)) self.failUnless(offset in (0, 1))
for x in xrange(num_replicas): for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 3) self.assertEqual(len(pt.getCellList(x)), 3)
# there is no feeding cell, marked as feeding # there is no feeding cell, marked as feeding
pt.clear() pt.clear()
pt.setCell(0, sn1, CellStates.UP_TO_DATE) pt.setCell(0, sn1, CellStates.UP_TO_DATE)
...@@ -287,10 +287,10 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -287,10 +287,10 @@ class MasterPartitionTableTests(NeoTestBase):
else: else:
self.failUnless(uuid in (uuid1, uuid6)) self.failUnless(uuid in (uuid1, uuid6))
else: else:
self.failUnless(offset in (0, 1)) self.failUnless(offset in (0, 1))
for x in xrange(num_replicas): for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 3) self.assertEqual(len(pt.getCellList(x)), 3)
def test_15_dropNode(self): def test_15_dropNode(self):
num_partitions = 4 num_partitions = 4
num_replicas = 2 num_replicas = 2
...@@ -333,7 +333,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -333,7 +333,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(state, CellStates.OUT_OF_DATE) self.assertEqual(state, CellStates.OUT_OF_DATE)
else: else:
self.failUnless(uuid in (uuid2, uuid4)) self.failUnless(uuid in (uuid2, uuid4))
for x in xrange(num_replicas): for x in xrange(num_replicas):
self.assertEqual(len(pt.getCellList(x)), 2) self.assertEqual(len(pt.getCellList(x)), 2)
# same test but with feeding state, no other will be added # same test but with feeding state, no other will be added
...@@ -357,7 +357,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -357,7 +357,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getCellList(x)), 1) self.assertEqual(len(pt.getCellList(x)), 1)
else: else:
self.assertEqual(len(pt.getCellList(x)), 2) self.assertEqual(len(pt.getCellList(x)), 2)
def test_16_make(self): def test_16_make(self):
num_partitions = 5 num_partitions = 5
num_replicas = 1 num_replicas = 1
...@@ -408,7 +408,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -408,7 +408,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(node, sn1) self.assertEqual(node, sn1)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
self.assertTrue(pt.operational()) self.assertTrue(pt.operational())
def test_17_tweak(self): def test_17_tweak(self):
# remove broken node # remove broken node
# remove if too many feeding nodes # remove if too many feeding nodes
...@@ -472,7 +472,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -472,7 +472,7 @@ class MasterPartitionTableTests(NeoTestBase):
else: else:
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE) self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn2 in [x.getNode() for x in cells]) self.failUnless(sn2 in [x.getNode() for x in cells])
# check part 2 # check part 2
cells = pt.getCellList(1) cells = pt.getCellList(1)
self.assertEqual(len(cells), 4) self.assertEqual(len(cells), 4)
...@@ -483,7 +483,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -483,7 +483,7 @@ class MasterPartitionTableTests(NeoTestBase):
self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE) self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
self.failUnless(sn3 in [x.getNode() for x in cells]) self.failUnless(sn3 in [x.getNode() for x in cells])
self.failUnless(sn1 in [x.getNode() for x in cells]) self.failUnless(sn1 in [x.getNode() for x in cells])
# check part 3 # check part 3
cells = pt.getCellList(2) cells = pt.getCellList(2)
self.assertEqual(len(cells), 3) self.assertEqual(len(cells), 3)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -46,7 +46,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -46,7 +46,7 @@ class MasterRecoveryTests(NeoTestBase):
self.master_port = 10011 self.master_port = 10011
self.master_address = ('127.0.0.1', self.master_port) self.master_address = ('127.0.0.1', self.master_port)
self.storage_address = ('127.0.0.1', self.storage_port) self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -66,29 +66,29 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -66,29 +66,29 @@ class MasterRecoveryTests(NeoTestBase):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.recovery.connectionClosed(conn) self.recovery.connectionClosed(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.recovery.timeoutExpired(conn) self.recovery.timeoutExpired(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.recovery.peerBroken(conn) self.recovery.peerBroken(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.BROKEN) NodeStates.BROKEN)
def test_08_notifyNodeInformation(self): def test_08_notifyNodeInformation(self):
recovery = self.recovery recovery = self.recovery
...@@ -146,7 +146,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -146,7 +146,7 @@ class MasterRecoveryTests(NeoTestBase):
recovery.notifyNodeInformation(conn, packet, node_list) recovery.notifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), NodeStates.DOWN) self.assertEqual(node.getState(), NodeStates.DOWN)
def test_09_answerLastIDs(self): def test_09_answerLastIDs(self):
recovery = self.recovery recovery = self.recovery
...@@ -213,8 +213,8 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -213,8 +213,8 @@ class MasterRecoveryTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(offset)) self.assertFalse(self.app.pt.hasOffset(offset))
cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)] cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)]
self.checkUnexpectedPacketRaised(recovery.answerPartitionTable, conn, packet, None, cell_list) self.checkUnexpectedPacketRaised(recovery.answerPartitionTable, conn, packet, None, cell_list)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -47,8 +47,8 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -47,8 +47,8 @@ class MasterStorageHandlerTests(NeoTestBase):
self.master_address = ('127.0.0.1', self.master_port) self.master_address = ('127.0.0.1', self.master_port)
self.client_address = ('127.0.0.1', self.client_port) self.client_address = ('127.0.0.1', self.client_port)
self.storage_address = ('127.0.0.1', self.storage_port) self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -96,7 +96,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -96,7 +96,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a known node but with bad address, don't care # notify about a known node but with bad address, don't care
self.app.nm.createStorage( self.app.nm.createStorage(
address=("127.0.0.1", 11011), address=("127.0.0.1", 11011),
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
...@@ -150,7 +150,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -150,7 +150,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(loid, self.app.loid) self.assertEquals(loid, self.app.loid)
self.assertEquals(ltid, self.app.ltid) self.assertEquals(ltid, self.app.ltid)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
def test_10_notifyInformationLocked(self): def test_10_notifyInformationLocked(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode(port=10020) uuid = self.identifyToMasterNode(port=10020)
...@@ -192,7 +192,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -192,7 +192,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.checkNotifyTransactionFinished(conn) self.checkNotifyTransactionFinished(conn)
self.checkLockInformation(storage_conn_1) self.checkLockInformation(storage_conn_1)
self.checkLockInformation(storage_conn_2) self.checkLockInformation(storage_conn_2)
def test_12_askLastIDs(self): def test_12_askLastIDs(self):
service = self.service service = self.service
...@@ -210,7 +210,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -210,7 +210,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEqual(loid, oid) self.assertEqual(loid, oid)
self.assertEqual(ltid, tid) self.assertEqual(ltid, tid)
self.assertEqual(lptid, ptid) self.assertEqual(lptid, ptid)
def test_13_askUnfinishedTransactions(self): def test_13_askUnfinishedTransactions(self):
service = self.service service = self.service
...@@ -235,7 +235,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -235,7 +235,7 @@ class MasterStorageHandlerTests(NeoTestBase):
packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet) packet = self.checkAnswerUnfinishedTransactions(conn, answered_packet=packet)
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 3) self.assertEqual(len(tid_list), 3)
def test_14_notifyPartitionChanges(self): def test_14_notifyPartitionChanges(self):
service = self.service service = self.service
...@@ -245,7 +245,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -245,7 +245,7 @@ class MasterStorageHandlerTests(NeoTestBase):
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port) port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
self.checkUnexpectedPacketRaised(service.notifyPartitionChanges, self.checkUnexpectedPacketRaised(service.notifyPartitionChanges,
conn, packet, None, None) conn, packet, None, None)
# send a bad state, must not be take into account # send a bad state, must not be take into account
...@@ -290,7 +290,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -290,7 +290,7 @@ class MasterStorageHandlerTests(NeoTestBase):
if cell == storage_uuid: if cell == storage_uuid:
self.assertEquals(state, CellStates.FEEDING) self.assertEquals(state, CellStates.FEEDING)
else: else:
self.assertEquals(state, CellStates.OUT_OF_DATE) self.assertEquals(state, CellStates.OUT_OF_DATE)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
service.notifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list) service.notifyPartitionChanges(conn, packet, self.app.pt.getID(), cell_list)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
...@@ -300,7 +300,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -300,7 +300,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(state, CellStates.UP_TO_DATE) self.assertEquals(state, CellStates.UP_TO_DATE)
else: else:
self.assertEquals(state, CellStates.DISCARDED) self.assertEquals(state, CellStates.DISCARDED)
def test_15_peerBroken(self): def test_15_peerBroken(self):
service = self.service service = self.service
...@@ -323,14 +323,14 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -323,14 +323,14 @@ class MasterStorageHandlerTests(NeoTestBase):
NodeStates.RUNNING) NodeStates.RUNNING)
service.peerBroken(conn) service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN) NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn) self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -346,10 +346,10 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -346,10 +346,10 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn) service.peerBroken(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_16_timeoutExpired(self): def test_16_timeoutExpired(self):
service = self.service service = self.service
...@@ -372,14 +372,14 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -372,14 +372,14 @@ class MasterStorageHandlerTests(NeoTestBase):
NodeStates.RUNNING) NodeStates.RUNNING)
service.timeoutExpired(conn) service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn) self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -395,7 +395,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -395,7 +395,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn) service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
...@@ -421,14 +421,14 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -421,14 +421,14 @@ class MasterStorageHandlerTests(NeoTestBase):
NodeStates.RUNNING) NodeStates.RUNNING)
service.connectionClosed(conn) service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN) NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn) self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -444,7 +444,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -444,7 +444,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn) service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -23,7 +23,7 @@ from neo.protocol import Packet, Packets ...@@ -23,7 +23,7 @@ from neo.protocol import Packet, Packets
from neo.protocol import NodeTypes, NodeStates, ErrorCodes from neo.protocol import NodeTypes, NodeStates, ErrorCodes
from neo.master.handlers.verification import VerificationHandler from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application from neo.master.app import Application
from neo.exception import VerificationFailure from neo.exception import VerificationFailure
class MasterVerificationTests(NeoTestBase): class MasterVerificationTests(NeoTestBase):
...@@ -53,7 +53,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -53,7 +53,7 @@ class MasterVerificationTests(NeoTestBase):
self.master_port = 10011 self.master_port = 10011
self.master_address = ('127.0.0.1', self.master_port) self.master_address = ('127.0.0.1', self.master_port)
self.storage_address = ('127.0.0.1', self.storage_port) self.storage_address = ('127.0.0.1', self.storage_port)
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -67,7 +67,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -67,7 +67,7 @@ class MasterVerificationTests(NeoTestBase):
""" """
uuid = self.getNewUUID() uuid = self.getNewUUID()
self.app.nm.createFromNodeType( self.app.nm.createFromNodeType(
node_type, node_type,
address=(ip, port), address=(ip, port),
uuid=uuid, uuid=uuid,
) )
...@@ -141,7 +141,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -141,7 +141,7 @@ class MasterVerificationTests(NeoTestBase):
upper, lower = unpack('!LL', self.app.ltid) upper, lower = unpack('!LL', self.app.ltid)
new_tid = pack('!LL', upper, lower + 10) new_tid = pack('!LL', upper, lower + 10)
verification.answerUnfinishedTransactions(conn, packet, [new_tid]) verification.answerUnfinishedTransactions(conn, packet, [new_tid])
self.assertEquals(len(self.app.unfinished_tid_set), 0) self.assertEquals(len(self.app.unfinished_tid_set), 0)
# update dict # update dict
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.app.asking_uuid_dict[uuid] = False self.app.asking_uuid_dict[uuid] = False
...@@ -171,7 +171,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -171,7 +171,7 @@ class MasterVerificationTests(NeoTestBase):
new_oid = pack('!Q', oid + 1) new_oid = pack('!Q', oid + 1)
verification.answerTransactionInformation(conn, packet, new_tid, verification.answerTransactionInformation(conn, packet, new_tid,
"user", "desc", "ext", [new_oid,]) "user", "desc", "ext", [new_oid,])
self.assertEquals(self.app.unfinished_oid_set, None) self.assertEquals(self.app.unfinished_oid_set, None)
# do nothing as asking_uuid_dict is True # do nothing as asking_uuid_dict is True
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEquals(len(self.app.asking_uuid_dict), 1) self.assertEquals(len(self.app.asking_uuid_dict), 1)
...@@ -226,7 +226,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -226,7 +226,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertTrue(self.app.asking_uuid_dict.has_key(uuid)) self.assertTrue(self.app.asking_uuid_dict.has_key(uuid))
verification.tidNotFound(conn, packet, "msg") verification.tidNotFound(conn, packet, "msg")
self.assertEqual(self.app.unfinished_oid_set, None) self.assertEqual(self.app.unfinished_oid_set, None)
def test_14_answerObjectPresent(self): def test_14_answerObjectPresent(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
...@@ -248,7 +248,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -248,7 +248,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertFalse(self.app.asking_uuid_dict[uuid]) self.assertFalse(self.app.asking_uuid_dict[uuid])
verification.answerObjectPresent(conn, packet, new_oid, new_tid) verification.answerObjectPresent(conn, packet, new_oid, new_tid)
self.assertTrue(self.app.asking_uuid_dict[uuid]) self.assertTrue(self.app.asking_uuid_dict[uuid])
def test_15_oidNotFound(self): def test_15_oidNotFound(self):
verification = self.verification verification = self.verification
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
...@@ -270,7 +270,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -270,7 +270,7 @@ class MasterVerificationTests(NeoTestBase):
verification.oidNotFound(conn, packet, "msg") verification.oidNotFound(conn, packet, "msg")
self.assertFalse(self.app.object_present) self.assertFalse(self.app.object_present)
self.assertTrue(self.app.asking_uuid_dict[uuid ]) self.assertTrue(self.app.asking_uuid_dict[uuid ])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -33,9 +33,9 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL ...@@ -33,9 +33,9 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageClientHandlerTests(NeoTestBase): class StorageClientHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening, "isServer": _listening,
}) })
packet = Packet(msg_type=_msg_type) packet = Packet(msg_type=_msg_type)
# hook # hook
...@@ -130,9 +130,9 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -130,9 +130,9 @@ class StorageClientHandlerTests(NeoTestBase):
packet.setId(0) packet.setId(0)
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1) self.assertEquals(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
...@@ -145,9 +145,9 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -145,9 +145,9 @@ class StorageClientHandlerTests(NeoTestBase):
packet = Packets.AskObject() packet = Packets.AskObject()
packet.setId(0) packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('getObject') calls = self.app.dm.mockGetNamedCalls('getObject')
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
...@@ -162,9 +162,9 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -162,9 +162,9 @@ class StorageClientHandlerTests(NeoTestBase):
packet = Packets.AskObject() packet = Packets.AskObject()
packet.setId(0) packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn) self.checkAnswerObject(conn)
...@@ -256,7 +256,7 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -256,7 +256,7 @@ class StorageClientHandlerTests(NeoTestBase):
self.app.store_lock_dict[oid] = tid1 self.app.store_lock_dict[oid] = tid1
self.assertTrue(oid in self.app.store_lock_dict) self.assertTrue(oid in self.app.store_lock_dict)
t_before = self.app.transaction_dict.items()[:] t_before = self.app.transaction_dict.items()[:]
self.operation.askStoreObject(conn, packet, oid, self.operation.askStoreObject(conn, packet, oid,
INVALID_SERIAL, 0, 0, '', tid2) INVALID_SERIAL, 0, 0, '', tid2)
self.assertEquals(len(self.app.event_queue), 1) self.assertEquals(len(self.app.event_queue), 1)
t_after = self.app.transaction_dict.items()[:] t_after = self.app.transaction_dict.items()[:]
...@@ -271,14 +271,14 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -271,14 +271,14 @@ class StorageClientHandlerTests(NeoTestBase):
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
tid1, tid2 = self.getTwoIDs() tid1, tid2 = self.getTwoIDs()
self.app.store_lock_dict[INVALID_OID] = tid2 self.app.store_lock_dict[INVALID_OID] = tid2
self.operation.askStoreObject(conn, packet, INVALID_OID, self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', tid1) INVALID_SERIAL, 0, 0, '', tid1)
self.checkAnswerStoreObject(conn) self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2) self.assertEquals(self.app.store_lock_dict[INVALID_OID], tid2)
# conflicting # conflicting
packet = conn.mockGetNamedCalls('answer')[0].getParam(0) packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0]) self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_askStoreObject4(self): def test_28_askStoreObject4(self):
# resolvable conflict => answer # resolvable conflict => answer
packet = Packets.AskStoreObject() packet = Packets.AskStoreObject()
...@@ -286,20 +286,20 @@ class StorageClientHandlerTests(NeoTestBase): ...@@ -286,20 +286,20 @@ class StorageClientHandlerTests(NeoTestBase):
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )}) self.app.dm = Mock({'getObjectHistory':((self.getNewUUID(), ), )})
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None) self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
self.operation.askStoreObject(conn, packet, INVALID_OID, self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID) INVALID_SERIAL, 0, 0, '', INVALID_TID)
self.checkAnswerStoreObject(conn) self.checkAnswerStoreObject(conn)
self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None) self.assertEquals(self.app.store_lock_dict.get(INVALID_OID, None), None)
# conflicting # conflicting
packet = conn.mockGetNamedCalls('answer')[0].getParam(0) packet = conn.mockGetNamedCalls('answer')[0].getParam(0)
self.assertTrue(unpack('!B8s8s', packet._body)[0]) self.assertTrue(unpack('!B8s8s', packet._body)[0])
def test_28_askStoreObject5(self): def test_28_askStoreObject5(self):
# no conflict => answer # no conflict => answer
packet = Packets.AskStoreObject() packet = Packets.AskStoreObject()
packet.setId(0) packet.setId(0)
conn = Mock({'getUUID': self.app.uuid}) conn = Mock({'getUUID': self.app.uuid})
self.operation.askStoreObject(conn, packet, INVALID_OID, self.operation.askStoreObject(conn, packet, INVALID_OID,
INVALID_SERIAL, 0, 0, '', INVALID_TID) INVALID_SERIAL, 0, 0, '', INVALID_TID)
t = self.app.transaction_dict.get(INVALID_TID, None) t = self.app.transaction_dict.get(INVALID_TID, None)
self.assertNotEquals(t, None) self.assertNotEquals(t, None)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -48,7 +48,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -48,7 +48,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
# Common methods # Common methods
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
# client connection # client connection
uuid = self.getNewUUID() uuid = self.getNewUUID()
...@@ -91,7 +91,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -91,7 +91,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
node_1 = self.getNewUUID() node_1 = self.getNewUUID()
node_2 = self.getNewUUID() node_2 = self.getNewUUID()
node_3 = self.getNewUUID() node_3 = self.getNewUUID()
# SN already know all nodes # SN already know all nodes
self.app.nm.createStorage(uuid=node_1) self.app.nm.createStorage(uuid=node_1)
self.app.nm.createStorage(uuid=node_2) self.app.nm.createStorage(uuid=node_2)
self.app.nm.createStorage(uuid=node_3) self.app.nm.createStorage(uuid=node_3)
...@@ -118,7 +118,7 @@ class StorageInitializationHandlerTests(NeoTestBase): ...@@ -118,7 +118,7 @@ class StorageInitializationHandlerTests(NeoTestBase):
self.assertEqual(self.app.pt.getID(), 2) self.assertEqual(self.app.pt.getID(), 2)
self.assertNotEqual(self.app.dm.getPartitionTable(), []) self.assertNotEqual(self.app.dm.getPartitionTable(), [])
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -32,9 +32,9 @@ from neo.protocol import INVALID_TID, INVALID_OID ...@@ -32,9 +32,9 @@ from neo.protocol import INVALID_TID, INVALID_OID
class StorageMasterHandlerTests(NeoTestBase): class StorageMasterHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening, "isServer": _listening,
}) })
packet = Packet(msg_type=_msg_type) packet = Packet(msg_type=_msg_type)
# hook # hook
...@@ -97,7 +97,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -97,7 +97,7 @@ class StorageMasterHandlerTests(NeoTestBase):
app = self.app app = self.app
conn = Mock({ conn = Mock({
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
app.replicator = Mock({}) app.replicator = Mock({})
packet = Packets.NotifyPartitionChanges() packet = Packets.NotifyPartitionChanges()
...@@ -122,7 +122,7 @@ class StorageMasterHandlerTests(NeoTestBase): ...@@ -122,7 +122,7 @@ class StorageMasterHandlerTests(NeoTestBase):
# context # context
conn = Mock({ conn = Mock({
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packets.NotifyPartitionChanges() packet = Packets.NotifyPartitionChanges()
app = self.app app = self.app
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -32,7 +32,7 @@ class StorageAppTests(NeoTestBase): ...@@ -32,7 +32,7 @@ class StorageAppTests(NeoTestBase):
config = self.getStorageConfiguration(master_number=1) config = self.getStorageConfiguration(master_number=1)
self.app = Application(config) self.app = Application(config)
self.app.event_queue = deque() self.app.event_queue = deque()
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -55,11 +55,11 @@ class StorageAppTests(NeoTestBase): ...@@ -55,11 +55,11 @@ class StorageAppTests(NeoTestBase):
self.assertFalse(self.app.pt.hasOffset(x)) self.assertFalse(self.app.pt.hasOffset(x))
# add some node, will be remove when loading table # add some node, will be remove when loading table
master_uuid = self.getNewUUID() master_uuid = self.getNewUUID()
master = self.app.nm.createMaster(uuid=master_uuid) master = self.app.nm.createMaster(uuid=master_uuid)
storage_uuid = self.getNewUUID() storage_uuid = self.getNewUUID()
storage = self.app.nm.createStorage(uuid=storage_uuid) storage = self.app.nm.createStorage(uuid=storage_uuid)
client_uuid = self.getNewUUID() client_uuid = self.getNewUUID()
client = self.app.nm.createClient(uuid=client_uuid) client = self.app.nm.createClient(uuid=client_uuid)
self.app.pt.setCell(0, master, CellStates.UP_TO_DATE) self.app.pt.setCell(0, master, CellStates.UP_TO_DATE)
...@@ -92,21 +92,21 @@ class StorageAppTests(NeoTestBase): ...@@ -92,21 +92,21 @@ class StorageAppTests(NeoTestBase):
# fill partition table # fill partition table
self.app.dm.setPTID(1) self.app.dm.setPTID(1)
self.app.dm.query('delete from pt;') self.app.dm.query('delete from pt;')
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(0, dump(client_uuid), CellStates.UP_TO_DATE)) (0, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(client_uuid), CellStates.UP_TO_DATE)) (1, dump(client_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(1, dump(storage_uuid), CellStates.UP_TO_DATE)) (1, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(storage_uuid), CellStates.UP_TO_DATE)) (2, dump(storage_uuid), CellStates.UP_TO_DATE))
self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.app.dm.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(2, dump(master_uuid), CellStates.UP_TO_DATE)) (2, dump(master_uuid), CellStates.UP_TO_DATE))
self.assertEqual(len(self.app.dm.getPartitionTable()), 5) self.assertEqual(len(self.app.dm.getPartitionTable()), 5)
self.app.pt.clear() self.app.pt.clear()
self.app.loadPartitionTable() self.app.loadPartitionTable()
self.assertTrue(self.app.pt.filled()) self.assertTrue(self.app.pt.filled())
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertTrue(self.app.pt.hasOffset(x)) self.assertTrue(self.app.pt.hasOffset(x))
# check each row # check each row
cell_list = self.app.pt.getCellList(0) cell_list = self.app.pt.getCellList(0)
...@@ -120,7 +120,7 @@ class StorageAppTests(NeoTestBase): ...@@ -120,7 +120,7 @@ class StorageAppTests(NeoTestBase):
self.assertEqual(len(cell_list), 2) self.assertEqual(len(cell_list), 2)
self.failUnless(cell_list[0].getUUID() in (master_uuid, storage_uuid)) self.failUnless(cell_list[0].getUUID() in (master_uuid, storage_uuid))
self.failUnless(cell_list[1].getUUID() in (master_uuid, storage_uuid)) self.failUnless(cell_list[1].getUUID() in (master_uuid, storage_uuid))
def test_02_queueEvent(self): def test_02_queueEvent(self):
self.assertEqual(len(self.app.event_queue), 0) self.assertEqual(len(self.app.event_queue), 0)
event = Mock({"getId": 1325136}) event = Mock({"getId": 1325136})
...@@ -131,7 +131,7 @@ class StorageAppTests(NeoTestBase): ...@@ -131,7 +131,7 @@ class StorageAppTests(NeoTestBase):
self.assertEqual(len(args), 1) self.assertEqual(len(args), 1)
self.assertEqual(args[0], "test") self.assertEqual(args[0], "test")
self.assertEqual(kw, {"key" : "value"}) self.assertEqual(kw, {"key" : "value"})
def test_03_executeQueuedEvents(self): def test_03_executeQueuedEvents(self):
self.assertEqual(len(self.app.event_queue), 0) self.assertEqual(len(self.app.event_queue), 0)
event = Mock({"getId": 1325136}) event = Mock({"getId": 1325136})
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -30,9 +30,9 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL ...@@ -30,9 +30,9 @@ from neo.protocol import INVALID_TID, INVALID_OID, INVALID_SERIAL
class StorageStorageHandlerTests(NeoTestBase): class StorageStorageHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs): def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({ conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening, "isServer": _listening,
}) })
packet = Packet(msg_type=_msg_type) packet = Packet(msg_type=_msg_type)
# hook # hook
...@@ -87,9 +87,9 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -87,9 +87,9 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject() packet = Packets.AskObject()
self.app.load_lock_dict[INVALID_OID] = object() self.app.load_lock_dict[INVALID_OID] = object()
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1) self.assertEquals(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
...@@ -102,9 +102,9 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -102,9 +102,9 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject() packet = Packets.AskObject()
packet.setId(0) packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
calls = self.app.dm.mockGetNamedCalls('getObject') calls = self.app.dm.mockGetNamedCalls('getObject')
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
...@@ -119,9 +119,9 @@ class StorageStorageHandlerTests(NeoTestBase): ...@@ -119,9 +119,9 @@ class StorageStorageHandlerTests(NeoTestBase):
packet = Packets.AskObject() packet = Packets.AskObject()
packet.setId(0) packet.setId(0)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.operation.askObject(conn, packet, self.operation.askObject(conn, packet,
oid=INVALID_OID, oid=INVALID_OID,
serial=INVALID_SERIAL, serial=INVALID_SERIAL,
tid=INVALID_TID) tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 0) self.assertEquals(len(self.app.event_queue), 0)
self.checkAnswerObject(conn) self.checkAnswerObject(conn)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -85,13 +85,13 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -85,13 +85,13 @@ class StorageMySQSLdbTests(NeoTestBase):
self.db.rollback() self.db.rollback()
self.assertEquals(len(self.db.conn.mockGetNamedCalls('rollback')), 1) self.assertEquals(len(self.db.conn.mockGetNamedCalls('rollback')), 1)
self.assertEquals(self.db.isUnderTransaction(), False) self.assertEquals(self.db.isUnderTransaction(), False)
def test_07_query1(self): def test_07_query1(self):
# fake result object # fake result object
from array import array from array import array
result_object = Mock({ result_object = Mock({
"num_rows": 1, "num_rows": 1,
"fetch_row": ((1, 2, array('b', (1, 2, ))), ), "fetch_row": ((1, 2, array('b', (1, 2, ))), ),
}) })
# expected formatted result # expected formatted result
expected_result = ( expected_result = (
...@@ -180,7 +180,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -180,7 +180,7 @@ class StorageMySQSLdbTests(NeoTestBase):
def test_12_UUID(self): def test_12_UUID(self):
self.checkConfigEntry( self.checkConfigEntry(
get_call=self.db.getUUID, get_call=self.db.getUUID,
set_call=self.db.setUUID, set_call=self.db.setUUID,
value='TEST_VALUE') value='TEST_VALUE')
...@@ -209,7 +209,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -209,7 +209,7 @@ class StorageMySQSLdbTests(NeoTestBase):
# insert an entry and check it # insert an entry and check it
self.db.setup() self.db.setup()
rid, uuid, state = '\x00' * 8, '\x00' * 16, 0 rid, uuid, state = '\x00' * 8, '\x00' * 16, 0
self.db.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" % self.db.query("insert into pt (rid, uuid, state) values ('%s', '%s', %d)" %
(dump(rid), dump(uuid), state)) (dump(rid), dump(uuid), state))
pt = self.db.getPartitionTable() pt = self.db.getPartitionTable()
self.assertEquals(pt, [(0L, uuid, state)]) self.assertEquals(pt, [(0L, uuid, state)])
...@@ -276,7 +276,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -276,7 +276,7 @@ class StorageMySQSLdbTests(NeoTestBase):
self.assertTrue(self.db.objectPresent(oid1, tid1, all=True)) self.assertTrue(self.db.objectPresent(oid1, tid1, all=True))
self.assertTrue(self.db.objectPresent(oid2, tid2, all=False)) self.assertTrue(self.db.objectPresent(oid2, tid2, all=False))
self.assertTrue(self.db.objectPresent(oid2, tid2, all=True)) self.assertTrue(self.db.objectPresent(oid2, tid2, all=True))
def test_21_getObject(self): def test_21_getObject(self):
self.db.setup() self.db.setup()
oid1, tid1 = '\x00' * 7 + '\x01', '\x00' * 7 + '\x01' oid1, tid1 = '\x00' * 7 + '\x01', '\x00' * 7 + '\x01'
...@@ -473,7 +473,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -473,7 +473,7 @@ class StorageMySQSLdbTests(NeoTestBase):
result = self.db.query('select * from ttrans') result = self.db.query('select * from ttrans')
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(result[0], (2L, oid1 + oid2, 'u', 'd', 'e',)) self.assertEquals(result[0], (2L, oid1 + oid2, 'u', 'd', 'e',))
def test_26_deleteTransaction(self): def test_26_deleteTransaction(self):
# data set # data set
tid1, tid2 = '\x00' * 7 + '\x01', '\x00' * 7 + '\x02' tid1, tid2 = '\x00' * 7 + '\x01', '\x00' * 7 + '\x02'
...@@ -561,7 +561,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -561,7 +561,7 @@ class StorageMySQSLdbTests(NeoTestBase):
self.db.query("""replace into trans (tid, oids, user, description, ext) self.db.query("""replace into trans (tid, oids, user, description, ext)
values ('%s', '%s', 'u', 'd', 'e')""" % (u64(tid1), 'OIDs_')) values ('%s', '%s', 'u', 'd', 'e')""" % (u64(tid1), 'OIDs_'))
self.assertRaises(DatabaseFailure, self.db.getTransaction, tid1) self.assertRaises(DatabaseFailure, self.db.getTransaction, tid1)
def test_28_getOIDList(self): def test_28_getOIDList(self):
# there are two partitions and two objects in each of them # there are two partitions and two objects in each of them
# o1 & o3 in p1, o2 & o4 in p2 # o1 & o3 in p1, o2 & o4 in p2
...@@ -569,9 +569,9 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -569,9 +569,9 @@ class StorageMySQSLdbTests(NeoTestBase):
tid = '\x00' * 7 + '\x01' tid = '\x00' * 7 + '\x01'
oid1, oid2, oid3, oid4 = ['\x00' * 7 + chr(i) for i in xrange(4)] oid1, oid2, oid3, oid4 = ['\x00' * 7 + chr(i) for i in xrange(4)]
for oid in (oid1, oid2, oid3, oid4): for oid in (oid1, oid2, oid3, oid4):
self.db.query("replace into obj values (%d, %d, 0, 0, '')" % self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
(u64(oid), u64(tid))) (u64(oid), u64(tid)))
# get all oids for all partitions # get all oids for all partitions
result = self.db.getOIDList(0, 4, 2, (0, 1)) result = self.db.getOIDList(0, 4, 2, (0, 1))
self.assertEquals(result, [oid4, oid3, oid2, oid1]) self.assertEquals(result, [oid4, oid3, oid2, oid1])
# get all oids but from the second with a limit a two # get all oids but from the second with a limit a two
...@@ -596,7 +596,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -596,7 +596,7 @@ class StorageMySQSLdbTests(NeoTestBase):
tids = ['\x00' * 7 + chr(i) for i in xrange(4)] tids = ['\x00' * 7 + chr(i) for i in xrange(4)]
oid = '\x00' * 8 oid = '\x00' * 8
for tid in tids: for tid in tids:
self.db.query("replace into obj values (%d, %d, 0, 0, '')" % self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
(u64(oid), u64(tid))) (u64(oid), u64(tid)))
# unkwown object # unkwown object
result = self.db.getObjectHistory(oid='\x01' * 8) result = self.db.getObjectHistory(oid='\x01' * 8)
...@@ -619,9 +619,9 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -619,9 +619,9 @@ class StorageMySQSLdbTests(NeoTestBase):
tids = ['\x00' * 7 + chr(i) for i in xrange(4)] tids = ['\x00' * 7 + chr(i) for i in xrange(4)]
tid1, tid2, tid3, tid4 = tids tid1, tid2, tid3, tid4 = tids
for tid in tids: for tid in tids:
self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" % self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" %
(u64(tid))) (u64(tid)))
# get all tids for all partitions # get all tids for all partitions
result = self.db.getTIDList(0, 4, 2, (0, 1)) result = self.db.getTIDList(0, 4, 2, (0, 1))
self.assertEquals(result, [tid4, tid3, tid2, tid1]) self.assertEquals(result, [tid4, tid3, tid2, tid1])
# get all tids but from the second with a limit a two # get all tids but from the second with a limit a two
...@@ -646,7 +646,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -646,7 +646,7 @@ class StorageMySQSLdbTests(NeoTestBase):
tid = '\x00' * 7 + '\x01' tid = '\x00' * 7 + '\x01'
tid1, tid2, tid3, tid4 = ['\x00' * 7 + chr(i) for i in xrange(4)] tid1, tid2, tid3, tid4 = ['\x00' * 7 + chr(i) for i in xrange(4)]
for tid in (tid1, tid2, tid3, tid4): for tid in (tid1, tid2, tid3, tid4):
self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" % self.db.query("replace into trans values (%d, '', 'u', 'd', 'e')" %
(u64(tid))) (u64(tid)))
# all match # all match
result = self.db.getTIDListPresent((tid1, tid2, tid3, tid4)) result = self.db.getTIDListPresent((tid1, tid2, tid3, tid4))
...@@ -666,7 +666,7 @@ class StorageMySQSLdbTests(NeoTestBase): ...@@ -666,7 +666,7 @@ class StorageMySQSLdbTests(NeoTestBase):
tid1, tid2, tid3, tid4 = tids tid1, tid2, tid3, tid4 = tids
oid = '\x00' * 8 oid = '\x00' * 8
for tid in tids: for tid in tids:
self.db.query("replace into obj values (%d, %d, 0, 0, '')" % self.db.query("replace into obj values (%d, %d, 0, 0, '')" %
(u64(oid), u64(tid))) (u64(oid), u64(tid)))
# all match # all match
result = self.db.getSerialListPresent(oid, tids) result = self.db.getSerialListPresent(oid, tids)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -44,7 +44,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -44,7 +44,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.load_lock_dict = {} self.app.load_lock_dict = {}
self.app.pt = PartitionTable(self.num_partitions, self.num_replicas) self.app.pt = PartitionTable(self.num_partitions, self.num_replicas)
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -131,7 +131,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -131,7 +131,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.assertEqual(oid, last_oid) self.assertEqual(oid, last_oid)
self.assertEqual(u64(tid), 4) self.assertEqual(u64(tid), 4)
self.assertEqual(ptid, self.app.pt.getID()) self.assertEqual(ptid, self.app.pt.getID())
def test_08_askPartitionTable(self): def test_08_askPartitionTable(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
packet = Mock() packet = Mock()
...@@ -151,7 +151,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -151,7 +151,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# try to get known offset # try to get known offset
node = self.app.nm.createStorage( node = self.app.nm.createStorage(
address=("127.7.9.9", 1), address=("127.7.9.9", 1),
uuid=self.getNewUUID() uuid=self.getNewUUID()
) )
self.app.pt.setCell(1, node, CellStates.UP_TO_DATE) self.app.pt.setCell(1, node, CellStates.UP_TO_DATE)
...@@ -170,7 +170,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -170,7 +170,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# old partition change # old partition change
conn = Mock({ conn = Mock({
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packets.NotifyPartitionChanges() packet = Packets.NotifyPartitionChanges()
self.verification.notifyPartitionChanges(conn, packet, 1, ()) self.verification.notifyPartitionChanges(conn, packet, 1, ())
...@@ -180,7 +180,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -180,7 +180,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
# new node # new node
conn = Mock({ conn = Mock({
"isServer": False, "isServer": False,
"getAddress" : ("127.0.0.1", self.master_port), "getAddress" : ("127.0.0.1", self.master_port),
}) })
packet = Packets.NotifyPartitionChanges() packet = Packets.NotifyPartitionChanges()
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
...@@ -250,7 +250,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -250,7 +250,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
self.app.dm.query("""insert into ttrans (tid, oids, user, self.app.dm.query("""insert into ttrans (tid, oids, user,
description, ext) values (3, '%s', 'u1', 'd1', 'e1')""" %(p64(4),)) description, ext) values (3, '%s', 'u1', 'd1', 'e1')""" %(p64(4),))
self.app.dm.query("""insert into trans (tid, oids, user, self.app.dm.query("""insert into trans (tid, oids, user,
description, ext) values (1,'%s', 'u2', 'd2', 'e2')""" %(p64(2),)) description, ext) values (1,'%s', 'u2', 'd2', 'e2')""" %(p64(2),))
self.app.dm.commit() self.app.dm.commit()
# object from trans # object from trans
conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port), conn = Mock({ "getAddress" : ("127.0.0.1", self.master_port),
...@@ -299,7 +299,7 @@ class StorageVerificationHandlerTests(NeoTestBase): ...@@ -299,7 +299,7 @@ class StorageVerificationHandlerTests(NeoTestBase):
packet = Packets.AskTransactionInformation() packet = Packets.AskTransactionInformation()
packet.setId(0) packet.setId(0)
self.verification.askTransactionInformation(conn, packet, p64(2)) self.verification.askTransactionInformation(conn, packet, p64(2))
code, message = self.checkErrorPacket(conn, decode=True) code, message = self.checkErrorPacket(conn, decode=True)
self.assertEqual(code, ErrorCodes.TID_NOT_FOUND) self.assertEqual(code, ErrorCodes.TID_NOT_FOUND)
def test_15_askObjectPresent(self): def test_15_askObjectPresent(self):
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -37,7 +37,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -37,7 +37,7 @@ class BootstrapManagerTests(NeoTestBase):
self.storage_port = 10020 self.storage_port = 10020
self.num_partitions = 1009 self.num_partitions = 1009
self.num_replicas = 2 self.num_replicas = 2
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
...@@ -54,14 +54,14 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -54,14 +54,14 @@ class BootstrapManagerTests(NeoTestBase):
self.checkAskPrimary(conn) self.checkAskPrimary(conn)
def testHandleNotReady(self): def testHandleNotReady(self):
# the primary is not ready # the primary is not ready
conn = Mock({}) conn = Mock({})
packet = Mock({}) packet = Mock({})
self.bootstrap.notReady(conn, packet, '') self.bootstrap.notReady(conn, packet, '')
self.checkClosed(conn) self.checkClosed(conn)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -56,7 +56,7 @@ class ConnectionTests(NeoTestBase): ...@@ -56,7 +56,7 @@ class ConnectionTests(NeoTestBase):
# init with connector but no handler # init with connector but no handler
registerConnectorHandler(DoNothingConnector) registerConnectorHandler(DoNothingConnector)
connector = getConnectorHandler("DoNothingConnector")() connector = getConnectorHandler("DoNothingConnector")()
self.assertNotEqual(connector, None) self.assertNotEqual(connector, None)
em = Mock() em = Mock()
bc = BaseConnection(em, handler, connector=connector) bc = BaseConnection(em, handler, connector=connector)
...@@ -99,7 +99,7 @@ class ConnectionTests(NeoTestBase): ...@@ -99,7 +99,7 @@ class ConnectionTests(NeoTestBase):
call = em.mockGetNamedCalls("register")[0] call = em.mockGetNamedCalls("register")[0]
conn = call.getParam(0) conn = call.getParam(0)
self.assertEquals(conn, bc) self.assertEquals(conn, bc)
def test_02_ListeningConnection(self): def test_02_ListeningConnection(self):
# test init part # test init part
em = Mock() em = Mock()
...@@ -117,8 +117,8 @@ class ConnectionTests(NeoTestBase): ...@@ -117,8 +117,8 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(connector.mockGetNamedCalls("makeListeningConnection")), 1) self.assertEqual(len(connector.mockGetNamedCalls("makeListeningConnection")), 1)
# test readable # test readable
bc.readable() bc.readable()
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1) self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 1) self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 1)
# test with exception raise when getting new connection # test with exception raise when getting new connection
em = Mock() em = Mock()
...@@ -136,8 +136,8 @@ class ConnectionTests(NeoTestBase): ...@@ -136,8 +136,8 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(len(connector.mockGetNamedCalls("makeListeningConnection")), 1) self.assertEqual(len(connector.mockGetNamedCalls("makeListeningConnection")), 1)
# test readable # test readable
bc.readable() bc.readable()
self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1) self.assertEqual(len(connector.mockGetNamedCalls("getNewConnection")), 1)
self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 0) self.assertEqual(len(handler.mockGetNamedCalls("connectionAccepted")), 0)
def test_03_Connection(self): def test_03_Connection(self):
...@@ -194,7 +194,7 @@ class ConnectionTests(NeoTestBase): ...@@ -194,7 +194,7 @@ class ConnectionTests(NeoTestBase):
connector=conn, addr=("127.0.0.7", 93413)) connector=conn, addr=("127.0.0.7", 93413))
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
self.assertNotEqual(bc.connector, None) self.assertNotEqual(bc.connector, None)
self.assertFalse(bc.pending()) self.assertFalse(bc.pending())
# connector and buffer # connector and buffer
bc.write_buf += '1' bc.write_buf += '1'
self.assertTrue(bc.pending()) self.assertTrue(bc.pending())
...@@ -257,7 +257,7 @@ class ConnectionTests(NeoTestBase): ...@@ -257,7 +257,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 1)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 2) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 2)
def test_06_Connection_send(self): def test_06_Connection_send(self):
# no data, nothing done # no data, nothing done
...@@ -273,7 +273,7 @@ class ConnectionTests(NeoTestBase): ...@@ -273,7 +273,7 @@ class ConnectionTests(NeoTestBase):
self.assertEquals(len(connector.mockGetNamedCalls("send")), 0) self.assertEquals(len(connector.mockGetNamedCalls("send")), 0)
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
# send all data # send all data
def send(self, data): def send(self, data):
return len(data) return len(data)
...@@ -330,7 +330,7 @@ class ConnectionTests(NeoTestBase): ...@@ -330,7 +330,7 @@ class ConnectionTests(NeoTestBase):
self.assertEqual(bc.write_buf, '') self.assertEqual(bc.write_buf, '')
self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0) self.assertEquals(len(handler.mockGetNamedCalls("connectionClosed")), 0)
self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0) self.assertEquals(len(em.mockGetNamedCalls("unregister")), 0)
# send part of multiple packet # send part of multiple packet
def send(self, data): def send(self, data):
return len(data)/2 return len(data)/2
...@@ -458,10 +458,10 @@ class ConnectionTests(NeoTestBase): ...@@ -458,10 +458,10 @@ class ConnectionTests(NeoTestBase):
# give some data to analyse # give some data to analyse
master_list = ( master_list = (
(("127.0.0.1", 2135), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()), (("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()), (("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()), (("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()), (("127.0.0.1", 2133), self.getNewUUID()),
(("127.0.0.1", 2435), self.getNewUUID()), (("127.0.0.1", 2435), self.getNewUUID()),
...@@ -479,7 +479,7 @@ class ConnectionTests(NeoTestBase): ...@@ -479,7 +479,7 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0) data = call.getParam(0)
self.assertEqual(data.getType(), p.getType()) self.assertEqual(data.getType(), p.getType())
self.assertEqual(data.getId(), p.getId()) self.assertEqual(data.getId(), p.getId())
self.assertEqual(data.decode(), p.decode()) self.assertEqual(data.decode(), p.decode())
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
...@@ -491,9 +491,9 @@ class ConnectionTests(NeoTestBase): ...@@ -491,9 +491,9 @@ class ConnectionTests(NeoTestBase):
bc._queue = Mock() bc._queue = Mock()
# packet 1 # packet 1
master_list = ( master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()), (("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()), (("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()), (("127.0.0.1", 2133), self.getNewUUID()),
...@@ -505,9 +505,9 @@ class ConnectionTests(NeoTestBase): ...@@ -505,9 +505,9 @@ class ConnectionTests(NeoTestBase):
bc.read_buf += data bc.read_buf += data
# packet 2 # packet 2
master_list = ( master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()), (("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()), (("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()), (("127.0.0.1", 2133), self.getNewUUID()),
...@@ -528,13 +528,13 @@ class ConnectionTests(NeoTestBase): ...@@ -528,13 +528,13 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0) data = call.getParam(0)
self.assertEqual(data.getType(), p1.getType()) self.assertEqual(data.getType(), p1.getType())
self.assertEqual(data.getId(), p1.getId()) self.assertEqual(data.getId(), p1.getId())
self.assertEqual(data.decode(), p1.decode()) self.assertEqual(data.decode(), p1.decode())
# packet 2 # packet 2
call = bc._queue.mockGetNamedCalls("append")[1] call = bc._queue.mockGetNamedCalls("append")[1]
data = call.getParam(0) data = call.getParam(0)
self.assertEqual(data.getType(), p2.getType()) self.assertEqual(data.getType(), p2.getType())
self.assertEqual(data.getId(), p2.getId()) self.assertEqual(data.getId(), p2.getId())
self.assertEqual(data.decode(), p2.decode()) self.assertEqual(data.decode(), p2.decode())
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(len(bc.read_buf), 0) self.assertEqual(len(bc.read_buf), 0)
...@@ -558,11 +558,11 @@ class ConnectionTests(NeoTestBase): ...@@ -558,11 +558,11 @@ class ConnectionTests(NeoTestBase):
bc = Connection(em, handler, connector_handler=DoNothingConnector, bc = Connection(em, handler, connector_handler=DoNothingConnector,
connector=connector, addr=("127.0.0.7", 93413)) connector=connector, addr=("127.0.0.7", 93413))
bc._queue = Mock() bc._queue = Mock()
master_list = ( master_list = (
(("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2135), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()), (("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()), (("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()), (("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()), (("127.0.0.1", 2133), self.getNewUUID()),
...@@ -583,7 +583,7 @@ class ConnectionTests(NeoTestBase): ...@@ -583,7 +583,7 @@ class ConnectionTests(NeoTestBase):
data = call.getParam(0) data = call.getParam(0)
self.assertEqual(data.getType(), p.getType()) self.assertEqual(data.getType(), p.getType())
self.assertEqual(data.getId(), p.getId()) self.assertEqual(data.getId(), p.getId())
self.assertEqual(data.decode(), p.decode()) self.assertEqual(data.decode(), p.decode())
self.assertEqual(len(bc.event_dict), 0) self.assertEqual(len(bc.event_dict), 0)
self.assertEqual(bc.read_buf, '') self.assertEqual(bc.read_buf, '')
...@@ -690,9 +690,9 @@ class ConnectionTests(NeoTestBase): ...@@ -690,9 +690,9 @@ class ConnectionTests(NeoTestBase):
handler = Mock() handler = Mock()
# patch receive method to return data # patch receive method to return data
def receive(self): def receive(self):
master_list = ((("127.0.0.1", 2135), self.getNewUUID()), master_list = ((("127.0.0.1", 2135), self.getNewUUID()),
(("127.0.0.1", 2136), self.getNewUUID()), (("127.0.0.1", 2136), self.getNewUUID()),
(("127.0.0.1", 2235), self.getNewUUID()), (("127.0.0.1", 2235), self.getNewUUID()),
(("127.0.0.1", 2134), self.getNewUUID()), (("127.0.0.1", 2134), self.getNewUUID()),
(("127.0.0.1", 2335), self.getNewUUID()), (("127.0.0.1", 2335), self.getNewUUID()),
(("127.0.0.1", 2133), self.getNewUUID()), (("127.0.0.1", 2133), self.getNewUUID()),
...@@ -796,7 +796,7 @@ class ConnectionTests(NeoTestBase): ...@@ -796,7 +796,7 @@ class ConnectionTests(NeoTestBase):
connector = DoNothingConnector() connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection DoNothingConnector.makeClientConnection = makeClientConnection
try: try:
self.assertRaises(ConnectorException, ClientConnection, em, handler, self.assertRaises(ConnectorException, ClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413)) connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413))
finally: finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
...@@ -970,7 +970,7 @@ class ConnectionTests(NeoTestBase): ...@@ -970,7 +970,7 @@ class ConnectionTests(NeoTestBase):
bc.abort() bc.abort()
self.assertEqual(bc.aborted, True) self.assertEqual(bc.aborted, True)
self.assertTrue(bc.isServer()) self.assertTrue(bc.isServer())
def test_15_MTClientConnection(self): def test_15_MTClientConnection(self):
makeClientConnection_org = DoNothingConnector.makeClientConnection makeClientConnection_org = DoNothingConnector.makeClientConnection
...@@ -1039,8 +1039,8 @@ class ConnectionTests(NeoTestBase): ...@@ -1039,8 +1039,8 @@ class ConnectionTests(NeoTestBase):
connector = DoNothingConnector() connector = DoNothingConnector()
DoNothingConnector.makeClientConnection = makeClientConnection DoNothingConnector.makeClientConnection = makeClientConnection
try: try:
self.assertRaises(ConnectorException, MTClientConnection, em, handler, self.assertRaises(ConnectorException, MTClientConnection, em, handler,
connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413), connector_handler=DoNothingConnector, addr=("127.0.0.7", 93413),
dispatcher=dispatcher) dispatcher=dispatcher)
finally: finally:
DoNothingConnector.makeClientConnection = makeClientConnection_org DoNothingConnector.makeClientConnection = makeClientConnection_org
...@@ -1098,6 +1098,6 @@ class ConnectionTests(NeoTestBase): ...@@ -1098,6 +1098,6 @@ class ConnectionTests(NeoTestBase):
# XXX check locking ??? # XXX check locking ???
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -67,7 +67,7 @@ class EventTests(NeoTestBase): ...@@ -67,7 +67,7 @@ class EventTests(NeoTestBase):
event = Mock() event = Mock()
self.assertEqual(len(em.event_list), 0) self.assertEqual(len(em.event_list), 0)
em.addIdleEvent(event) em.addIdleEvent(event)
self.assertEqual(len(em.event_list), 1) self.assertEqual(len(em.event_list), 1)
em.removeIdleEvent(event) em.removeIdleEvent(event)
self.assertEqual(len(em.event_list), 0) self.assertEqual(len(em.event_list), 0)
em.removeIdleEvent(event) # must not fail em.removeIdleEvent(event) # must not fail
...@@ -146,7 +146,7 @@ class EventTests(NeoTestBase): ...@@ -146,7 +146,7 @@ class EventTests(NeoTestBase):
critical_time = event.getCriticalTime() critical_time = event.getCriticalTime()
self.assertEqual(critical_time, time+20) self.assertEqual(critical_time, time+20)
# call with t < time < critical_time # call with t < time < critical_time
t = time - 10 t = time - 10
r = event(t) r = event(t)
self.assertFalse(r) self.assertFalse(r)
...@@ -157,7 +157,7 @@ class EventTests(NeoTestBase): ...@@ -157,7 +157,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < t < critical_time # call with time < t < critical_time
t = time + 5 t = time + 5
self.failUnless(t < critical_time) self.failUnless(t < critical_time)
...@@ -170,7 +170,7 @@ class EventTests(NeoTestBase): ...@@ -170,7 +170,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("ping")), 1) self.assertEquals(len(conn.mockGetNamedCalls("ping")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < critical_time < t # call with time < critical_time < t
t = critical_time + 5 t = critical_time + 5
self.failUnless(t > critical_time) self.failUnless(t > critical_time)
...@@ -197,7 +197,7 @@ class EventTests(NeoTestBase): ...@@ -197,7 +197,7 @@ class EventTests(NeoTestBase):
critical_time = event.getCriticalTime() critical_time = event.getCriticalTime()
self.assertEqual(critical_time, time+3) self.assertEqual(critical_time, time+3)
# call with t < time < critical_time # call with t < time < critical_time
t = time - 10 t = time - 10
r = event(t) r = event(t)
self.assertFalse(r) self.assertFalse(r)
...@@ -208,7 +208,7 @@ class EventTests(NeoTestBase): ...@@ -208,7 +208,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < t < critical_time # call with time < t < critical_time
t = time + 1 t = time + 1
self.failUnless(t < critical_time) self.failUnless(t < critical_time)
...@@ -221,7 +221,7 @@ class EventTests(NeoTestBase): ...@@ -221,7 +221,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < critical_time < t # call with time < critical_time < t
t = critical_time + 5 t = critical_time + 5
self.failUnless(t > critical_time) self.failUnless(t > critical_time)
...@@ -234,7 +234,7 @@ class EventTests(NeoTestBase): ...@@ -234,7 +234,7 @@ class EventTests(NeoTestBase):
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1) self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.checkNoPacketSent(conn) self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1) self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -47,36 +47,36 @@ class HandlerTests(NeoTestBase): ...@@ -47,36 +47,36 @@ class HandlerTests(NeoTestBase):
# all is ok # all is ok
self.setFakeMethod(lambda c, p: None) self.setFakeMethod(lambda c, p: None)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
# raise UnexpectedPacketError # raise UnexpectedPacketError
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
def fake(c, p): raise UnexpectedPacketError('fake packet') def fake(c, p): raise UnexpectedPacketError('fake packet')
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
self.checkAborted(conn) self.checkAborted(conn)
# raise PacketMalformedError # raise PacketMalformedError
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
def fake(c, p): raise PacketMalformedError('message') def fake(c, p): raise PacketMalformedError('message')
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
self.checkAborted(conn) self.checkAborted(conn)
# raise BrokenNodeDisallowedError # raise BrokenNodeDisallowedError
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
def fake(c, p): raise BrokenNodeDisallowedError def fake(c, p): raise BrokenNodeDisallowedError
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
self.checkAborted(conn) self.checkAborted(conn)
# raise NotReadyError # raise NotReadyError
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
def fake(c, p): raise NotReadyError def fake(c, p): raise NotReadyError
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn) self.checkErrorPacket(conn)
self.checkAborted(conn) self.checkAborted(conn)
# raise ProtocolError # raise ProtocolError
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
def fake(c, p): raise ProtocolError def fake(c, p): raise ProtocolError
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -47,7 +47,7 @@ class NodesTests(NeoTestBase): ...@@ -47,7 +47,7 @@ class NodesTests(NeoTestBase):
self.assertEqual(node.getState(), NodeStates.UNKNOWN) self.assertEqual(node.getState(), NodeStates.UNKNOWN)
self.assertEqual(node.getAddress(), address) self.assertEqual(node.getAddress(), address)
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
def testState(self): def testState(self):
""" Check if the last changed time is updated when state is changed """ """ Check if the last changed time is updated when state is changed """
...@@ -150,7 +150,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -150,7 +150,7 @@ class NodeManagerTests(NeoTestBase):
def checkByServer(self, node): def checkByServer(self, node):
node_found = self.manager.getByAddress(node.getAddress()) node_found = self.manager.getByAddress(node.getAddress())
self.assertEqual(node_found, node) self.assertEqual(node_found, node)
def checkByUUID(self, node): def checkByUUID(self, node):
node_found = self.manager.getByUUID(node.getUUID()) node_found = self.manager.getByUUID(node.getUUID())
self.assertEqual(node_found, node) self.assertEqual(node_found, node)
...@@ -273,7 +273,7 @@ class NodeManagerTests(NeoTestBase): ...@@ -273,7 +273,7 @@ class NodeManagerTests(NeoTestBase):
self.checkNodes([self.master, self.admin, new_storage]) self.checkNodes([self.master, self.admin, new_storage])
self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN) self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -122,8 +122,8 @@ class PartitionTableTests(NeoTestBase): ...@@ -122,8 +122,8 @@ class PartitionTableTests(NeoTestBase):
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0) self.assertEqual(pt.count_dict[sn1], 0)
def test_04_removeCell(self): def test_04_removeCell(self):
num_partitions = 5 num_partitions = 5
num_replicas = 2 num_replicas = 2
...@@ -162,7 +162,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -162,7 +162,7 @@ class PartitionTableTests(NeoTestBase):
self.assertEqual(pt.count_dict[sn1], 0) self.assertEqual(pt.count_dict[sn1], 0)
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
def test_05_getCellList(self): def test_05_getCellList(self):
num_partitions = 5 num_partitions = 5
num_replicas = 2 num_replicas = 2
...@@ -281,7 +281,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -281,7 +281,7 @@ class PartitionTableTests(NeoTestBase):
self.assertEqual(len(pt.getNodeList()), 2) self.assertEqual(len(pt.getNodeList()), 2)
nodes = pt.getNodeList() nodes = pt.getNodeList()
self.failUnless(sn1 in nodes) self.failUnless(sn1 in nodes)
self.failUnless(sn2 in nodes) self.failUnless(sn2 in nodes)
self.failUnless(sn3 not in nodes) self.failUnless(sn3 not in nodes)
self.failUnless(sn4 not in nodes) self.failUnless(sn4 not in nodes)
...@@ -297,8 +297,8 @@ class PartitionTableTests(NeoTestBase): ...@@ -297,8 +297,8 @@ class PartitionTableTests(NeoTestBase):
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, CellStates.UP_TO_DATE) pt.setCell(x, sn1, CellStates.UP_TO_DATE)
self.assertEqual(pt.num_filled_rows, num_partitions) self.assertEqual(pt.num_filled_rows, num_partitions)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
def test_09_hasOffset(self): def test_09_hasOffset(self):
......
...@@ -429,7 +429,7 @@ class ProtocolTests(NeoTestBase): ...@@ -429,7 +429,7 @@ class ProtocolTests(NeoTestBase):
oid3 = self.getNextTID() oid3 = self.getNextTID()
oid4 = self.getNextTID() oid4 = self.getNextTID()
oid_list = [oid1, oid2, oid3, oid4] oid_list = [oid1, oid2, oid3, oid4]
p = Packets.AnswerTransactionInformation(tid, "moi", p = Packets.AnswerTransactionInformation(tid, "moi",
"transaction", "exti", oid_list) "transaction", "exti", oid_list)
ptid, user, desc, ext, p_oid_list = p.decode() ptid, user, desc, ext, p_oid_list = p.decode()
self.assertEqual(ptid, tid) self.assertEqual(ptid, tid)
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import util from neo import util
class UtilTests(NeoTestBase): class UtilTests(NeoTestBase):
def test_getNextTID(self): def test_getNextTID(self):
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -49,7 +49,7 @@ def bin(s): ...@@ -49,7 +49,7 @@ def bin(s):
ret.append(chr(int(s[:2], 16))) ret.append(chr(int(s[:2], 16)))
s = s[2:] s = s[2:]
return ''.join(ret) return ''.join(ret)
def makeChecksum(s): def makeChecksum(s):
"""Return a 4-byte integer checksum against a string.""" """Return a 4-byte integer checksum against a string."""
...@@ -68,7 +68,7 @@ def getNextTID(ltid): ...@@ -68,7 +68,7 @@ def getNextTID(ltid):
if lower == 0xffffffff: if lower == 0xffffffff:
# This should not happen usually. # This should not happen usually.
from datetime import timedelta, datetime from datetime import timedelta, datetime
d = datetime(gmt.tm_year, gmt.tm_mon, gmt.tm_mday, d = datetime(gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
gmt.tm_hour, gmt.tm_min) \ gmt.tm_hour, gmt.tm_min) \
+ timedelta(0, 60) + timedelta(0, 60)
upper = ((((d.year - 1900) * 12 + d.month - 1) * 31 \ upper = ((((d.year - 1900) * 12 + d.month - 1) * 31 \
...@@ -98,7 +98,7 @@ class Enum(dict): ...@@ -98,7 +98,7 @@ class Enum(dict):
class MyEnum(Enum): class MyEnum(Enum):
ITEM1 = Enum.Item(0) ITEM1 = Enum.Item(0)
ITEM2 = Enum.Item(1) ITEM2 = Enum.Item(1)
Enum items must be written in full upper case Enum items must be written in full upper case
""" """
class Item(int): class Item(int):
...@@ -134,7 +134,7 @@ class Enum(dict): ...@@ -134,7 +134,7 @@ class Enum(dict):
item._name = name item._name = name
item._enum = self item._enum = self
self[int(item)] = item self[int(item)] = item
def getByName(self, name): def getByName(self, name):
return getattr(self, name) return getattr(self, name)
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