Commit ef7eedd3 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use new Enum class for packet types. Drop the old Enum, this job is done.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1343 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent cf37fdd3
......@@ -19,7 +19,7 @@ from neo import logging
from neo.locking import RLock
from neo import protocol
from neo.protocol import PacketMalformedError
from neo.protocol import PacketMalformedError, PacketTypes
from neo.event import IdleEvent
from neo.connector import ConnectorException, ConnectorTryAgainException, \
ConnectorInProgressException, ConnectorConnectionRefusedException, \
......@@ -256,10 +256,10 @@ class Connection(BaseConnection):
try:
packet_type = packet.getType()
if packet_type == protocol.PING:
if packet_type == PacketTypes.PING:
# Send a pong notification
self.answer(protocol.pong(), packet.getId())
elif packet_type != protocol.PONG:
elif packet_type != PacketTypes.PONG:
# Skip PONG packets, its only purpose is to drop IdleEvent
# generated upong ping.
self._queue.append(packet)
......
This diff is collapsed.
......@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from neo import logging
from neo import protocol
from neo.protocol import PacketTypes
from neo.util import dump
class PacketLogger(object):
......@@ -243,68 +243,68 @@ class PacketLogger(object):
# Fetch tables initialization
def initFetchTable(self):
d = {}
d[protocol.ERROR] = self.error
d[protocol.REQUEST_NODE_IDENTIFICATION] = self.requestNodeIdentification
d[protocol.ACCEPT_NODE_IDENTIFICATION] = self.acceptNodeIdentification
d[protocol.ASK_PRIMARY_MASTER] = self.askPrimaryMaster
d[protocol.ANSWER_PRIMARY_MASTER] = self.answerPrimaryMaster
d[protocol.ANNOUNCE_PRIMARY_MASTER] = self.announcePrimaryMaster
d[protocol.REELECT_PRIMARY_MASTER] = self.reelectPrimaryMaster
d[protocol.NOTIFY_NODE_INFORMATION] = self.notifyNodeInformation
d[protocol.ASK_LAST_IDS] = self.askLastIDs
d[protocol.ANSWER_LAST_IDS] = self.answerLastIDs
d[protocol.ASK_PARTITION_TABLE] = self.askPartitionTable
d[protocol.ANSWER_PARTITION_TABLE] = self.answerPartitionTable
d[protocol.SEND_PARTITION_TABLE] = self.sendPartitionTable
d[protocol.NOTIFY_PARTITION_CHANGES] = self.notifyPartitionChanges
d[protocol.START_OPERATION] = self.startOperation
d[protocol.STOP_OPERATION] = self.stopOperation
d[protocol.ASK_UNFINISHED_TRANSACTIONS] = self.askUnfinishedTransactions
d[protocol.ANSWER_UNFINISHED_TRANSACTIONS] = self.answerUnfinishedTransactions
d[protocol.ASK_OBJECT_PRESENT] = self.askObjectPresent
d[protocol.ANSWER_OBJECT_PRESENT] = self.answerObjectPresent
d[protocol.DELETE_TRANSACTION] = self.deleteTransaction
d[protocol.COMMIT_TRANSACTION] = self.commitTransaction
d[protocol.ASK_BEGIN_TRANSACTION] = self.askBeginTransaction
d[protocol.ANSWER_BEGIN_TRANSACTION] = self.answerBeginTransaction
d[protocol.FINISH_TRANSACTION] = self.finishTransaction
d[protocol.NOTIFY_TRANSACTION_FINISHED] = self.notifyTransactionFinished
d[protocol.LOCK_INFORMATION] = self.lockInformation
d[protocol.NOTIFY_INFORMATION_LOCKED] = self.notifyInformationLocked
d[protocol.INVALIDATE_OBJECTS] = self.invalidateObjects
d[protocol.UNLOCK_INFORMATION] = self.unlockInformation
d[protocol.ASK_NEW_OIDS] = self.askNewOIDs
d[protocol.ANSWER_NEW_OIDS] = self.answerNewOIDs
d[protocol.ASK_STORE_OBJECT] = self.askStoreObject
d[protocol.ANSWER_STORE_OBJECT] = self.answerStoreObject
d[protocol.ABORT_TRANSACTION] = self.abortTransaction
d[protocol.ASK_STORE_TRANSACTION] = self.askStoreTransaction
d[protocol.ANSWER_STORE_TRANSACTION] = self.answerStoreTransaction
d[protocol.ASK_OBJECT] = self.askObject
d[protocol.ANSWER_OBJECT] = self.answerObject
d[protocol.ASK_TIDS] = self.askTIDs
d[protocol.ANSWER_TIDS] = self.answerTIDs
d[protocol.ASK_TRANSACTION_INFORMATION] = self.askTransactionInformation
d[protocol.ANSWER_TRANSACTION_INFORMATION] = self.answerTransactionInformation
d[protocol.ASK_OBJECT_HISTORY] = self.askObjectHistory
d[protocol.ANSWER_OBJECT_HISTORY] = self.answerObjectHistory
d[protocol.ASK_OIDS] = self.askOIDs
d[protocol.ANSWER_OIDS] = self.answerOIDs
d[protocol.ASK_PARTITION_LIST] = self.askPartitionList
d[protocol.ANSWER_PARTITION_LIST] = self.answerPartitionList
d[protocol.ASK_NODE_LIST] = self.askNodeList
d[protocol.ANSWER_NODE_LIST] = self.answerNodeList
d[protocol.SET_NODE_STATE] = self.setNodeState
d[protocol.ANSWER_NODE_STATE] = self.answerNodeState
d[protocol.SET_CLUSTER_STATE] = self.setClusterState
d[protocol.ADD_PENDING_NODES] = self.addPendingNodes
d[protocol.ANSWER_NEW_NODES] = self.answerNewNodes
d[protocol.ASK_NODE_INFORMATION] = self.askNodeInformation
d[protocol.ANSWER_NODE_INFORMATION] = self.answerNodeInformation
d[protocol.ASK_CLUSTER_STATE] = self.askClusterState
d[protocol.ANSWER_CLUSTER_STATE] = self.answerClusterState
d[protocol.NOTIFY_CLUSTER_INFORMATION] = self.notifyClusterInformation
d[protocol.NOTIFY_LAST_OID] = self.notifyLastOID
d[PacketTypes.ERROR] = self.error
d[PacketTypes.REQUEST_NODE_IDENTIFICATION] = self.requestNodeIdentification
d[PacketTypes.ACCEPT_NODE_IDENTIFICATION] = self.acceptNodeIdentification
d[PacketTypes.ASK_PRIMARY_MASTER] = self.askPrimaryMaster
d[PacketTypes.ANSWER_PRIMARY_MASTER] = self.answerPrimaryMaster
d[PacketTypes.ANNOUNCE_PRIMARY_MASTER] = self.announcePrimaryMaster
d[PacketTypes.REELECT_PRIMARY_MASTER] = self.reelectPrimaryMaster
d[PacketTypes.NOTIFY_NODE_INFORMATION] = self.notifyNodeInformation
d[PacketTypes.ASK_LAST_IDS] = self.askLastIDs
d[PacketTypes.ANSWER_LAST_IDS] = self.answerLastIDs
d[PacketTypes.ASK_PARTITION_TABLE] = self.askPartitionTable
d[PacketTypes.ANSWER_PARTITION_TABLE] = self.answerPartitionTable
d[PacketTypes.SEND_PARTITION_TABLE] = self.sendPartitionTable
d[PacketTypes.NOTIFY_PARTITION_CHANGES] = self.notifyPartitionChanges
d[PacketTypes.START_OPERATION] = self.startOperation
d[PacketTypes.STOP_OPERATION] = self.stopOperation
d[PacketTypes.ASK_UNFINISHED_TRANSACTIONS] = self.askUnfinishedTransactions
d[PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS] = self.answerUnfinishedTransactions
d[PacketTypes.ASK_OBJECT_PRESENT] = self.askObjectPresent
d[PacketTypes.ANSWER_OBJECT_PRESENT] = self.answerObjectPresent
d[PacketTypes.DELETE_TRANSACTION] = self.deleteTransaction
d[PacketTypes.COMMIT_TRANSACTION] = self.commitTransaction
d[PacketTypes.ASK_BEGIN_TRANSACTION] = self.askBeginTransaction
d[PacketTypes.ANSWER_BEGIN_TRANSACTION] = self.answerBeginTransaction
d[PacketTypes.FINISH_TRANSACTION] = self.finishTransaction
d[PacketTypes.NOTIFY_TRANSACTION_FINISHED] = self.notifyTransactionFinished
d[PacketTypes.LOCK_INFORMATION] = self.lockInformation
d[PacketTypes.NOTIFY_INFORMATION_LOCKED] = self.notifyInformationLocked
d[PacketTypes.INVALIDATE_OBJECTS] = self.invalidateObjects
d[PacketTypes.UNLOCK_INFORMATION] = self.unlockInformation
d[PacketTypes.ASK_NEW_OIDS] = self.askNewOIDs
d[PacketTypes.ANSWER_NEW_OIDS] = self.answerNewOIDs
d[PacketTypes.ASK_STORE_OBJECT] = self.askStoreObject
d[PacketTypes.ANSWER_STORE_OBJECT] = self.answerStoreObject
d[PacketTypes.ABORT_TRANSACTION] = self.abortTransaction
d[PacketTypes.ASK_STORE_TRANSACTION] = self.askStoreTransaction
d[PacketTypes.ANSWER_STORE_TRANSACTION] = self.answerStoreTransaction
d[PacketTypes.ASK_OBJECT] = self.askObject
d[PacketTypes.ANSWER_OBJECT] = self.answerObject
d[PacketTypes.ASK_TIDS] = self.askTIDs
d[PacketTypes.ANSWER_TIDS] = self.answerTIDs
d[PacketTypes.ASK_TRANSACTION_INFORMATION] = self.askTransactionInformation
d[PacketTypes.ANSWER_TRANSACTION_INFORMATION] = self.answerTransactionInformation
d[PacketTypes.ASK_OBJECT_HISTORY] = self.askObjectHistory
d[PacketTypes.ANSWER_OBJECT_HISTORY] = self.answerObjectHistory
d[PacketTypes.ASK_OIDS] = self.askOIDs
d[PacketTypes.ANSWER_OIDS] = self.answerOIDs
d[PacketTypes.ASK_PARTITION_LIST] = self.askPartitionList
d[PacketTypes.ANSWER_PARTITION_LIST] = self.answerPartitionList
d[PacketTypes.ASK_NODE_LIST] = self.askNodeList
d[PacketTypes.ANSWER_NODE_LIST] = self.answerNodeList
d[PacketTypes.SET_NODE_STATE] = self.setNodeState
d[PacketTypes.ANSWER_NODE_STATE] = self.answerNodeState
d[PacketTypes.SET_CLUSTER_STATE] = self.setClusterState
d[PacketTypes.ADD_PENDING_NODES] = self.addPendingNodes
d[PacketTypes.ANSWER_NEW_NODES] = self.answerNewNodes
d[PacketTypes.ASK_NODE_INFORMATION] = self.askNodeInformation
d[PacketTypes.ANSWER_NODE_INFORMATION] = self.answerNodeInformation
d[PacketTypes.ASK_CLUSTER_STATE] = self.askClusterState
d[PacketTypes.ANSWER_CLUSTER_STATE] = self.answerClusterState
d[PacketTypes.NOTIFY_CLUSTER_INFORMATION] = self.notifyClusterInformation
d[PacketTypes.NOTIFY_LAST_OID] = self.notifyLastOID
return d
......
......@@ -17,7 +17,6 @@
from neo.handler import EventHandler
from neo.protocol import ErrorCodes
from neo import protocol
class CommandEventHandler(EventHandler):
""" Base handler for command """
......
......@@ -20,7 +20,7 @@ from neo.connection import ClientConnection
from neo.event import EventManager
from neo.neoctl.handler import CommandEventHandler
from neo import protocol
from neo.protocol import ClusterStates, NodeStates, ErrorCodes
from neo.protocol import ClusterStates, NodeStates, ErrorCodes, PacketTypes
class NotReadyException(Exception):
pass
......@@ -59,7 +59,7 @@ class NeoCTL(object):
if not self.connected:
raise NotReadyException, 'Connection closed'
response = response_queue.pop()
if response[0] == protocol.ERROR and \
if response[0] == PacketTypes.ERROR and \
response[1] == ErrorCodes.NOT_READY:
raise NotReadyException(response[2])
return response
......@@ -70,7 +70,7 @@ class NeoCTL(object):
"""
packet = protocol.addPendingNodes(uuid_list)
response = self.__ask(packet)
assert response[0] == protocol.ERROR
assert response[0] == PacketTypes.ERROR
assert response[1] == ErrorCodes.NO_ERROR
def setClusterState(self, state):
......@@ -79,7 +79,7 @@ class NeoCTL(object):
"""
packet = protocol.setClusterState(state)
response = self.__ask(packet)
assert response[0] == protocol.ERROR
assert response[0] == PacketTypes.ERROR
assert response[1] == ErrorCodes.NO_ERROR
def setNodeState(self, node, state, update_partition_table=False):
......@@ -92,7 +92,7 @@ class NeoCTL(object):
update_partition_table = 0
packet = protocol.setNodeState(node, state, update_partition_table)
response = self.__ask(packet)
assert response[0] == protocol.ERROR
assert response[0] == PacketTypes.ERROR
assert response[1] == ErrorCodes.NO_ERROR
def getClusterState(self):
......@@ -101,7 +101,7 @@ class NeoCTL(object):
"""
packet = protocol.askClusterState()
response = self.__ask(packet)
assert response[0] == protocol.ANSWER_CLUSTER_STATE
assert response[0] == PacketTypes.ANSWER_CLUSTER_STATE
return response[1]
def getNodeList(self, node_type=None):
......@@ -110,7 +110,7 @@ class NeoCTL(object):
"""
packet = protocol.askNodeList(node_type)
response = self.__ask(packet)
assert response[0] == protocol.ANSWER_NODE_LIST
assert response[0] == PacketTypes.ANSWER_NODE_LIST
return response[1]
def getPartitionRowList(self, min_offset=0, max_offset=0, node=None):
......@@ -120,7 +120,7 @@ class NeoCTL(object):
"""
packet = protocol.askPartitionList(min_offset, max_offset, node)
response = self.__ask(packet)
assert response[0] == protocol.ANSWER_PARTITION_LIST
assert response[0] == PacketTypes.ANSWER_PARTITION_LIST
return (response[1], response[2])
def startCluster(self):
......@@ -141,6 +141,6 @@ class NeoCTL(object):
"""
packet = protocol.askPrimaryMaster()
response = self.__ask(packet)
assert response[0] == protocol.ANSWER_PRIMARY_MASTER
assert response[0] == PacketTypes.ANSWER_PRIMARY_MASTER
return response[1]
This diff is collapsed.
......@@ -22,6 +22,7 @@ import MySQLdb
from neo import logging
from mock import Mock
from neo import protocol
from neo.protocol import PacketTypes
DB_PREFIX = 'test_neo_'
DB_ADMIN = 'root'
......@@ -168,7 +169,7 @@ class NeoTestBase(unittest.TestCase):
self.assertEquals(len(calls), 1)
packet = calls[0].getParam(0)
self.assertTrue(isinstance(packet, protocol.Packet))
self.assertEquals(packet.getType(), protocol.ERROR)
self.assertEquals(packet.getType(), PacketTypes.ERROR)
if decode:
return protocol.decode_table[packet.getType()](packet._body)
return packet
......@@ -210,97 +211,97 @@ class NeoTestBase(unittest.TestCase):
return packet
def checkNotifyNodeInformation(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.NOTIFY_NODE_INFORMATION, **kw)
return self.checkNotifyPacket(conn, PacketTypes.NOTIFY_NODE_INFORMATION, **kw)
def checkSendPartitionTable(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.SEND_PARTITION_TABLE, **kw)
return self.checkNotifyPacket(conn, PacketTypes.SEND_PARTITION_TABLE, **kw)
def checkStartOperation(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.START_OPERATION, **kw)
return self.checkNotifyPacket(conn, PacketTypes.START_OPERATION, **kw)
def checkNotifyTransactionFinished(self, conn, **kw):
return self.checkNotifyPacket(conn, protocol.NOTIFY_TRANSACTION_FINISHED, **kw)
return self.checkNotifyPacket(conn, PacketTypes.NOTIFY_TRANSACTION_FINISHED, **kw)
def checkNotifyInformationLocked(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.NOTIFY_INFORMATION_LOCKED, **kw)
return self.checkAnswerPacket(conn, PacketTypes.NOTIFY_INFORMATION_LOCKED, **kw)
def checkLockInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.LOCK_INFORMATION, **kw)
return self.checkAskPacket(conn, PacketTypes.LOCK_INFORMATION, **kw)
def checkUnlockInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.UNLOCK_INFORMATION, **kw)
return self.checkAskPacket(conn, PacketTypes.UNLOCK_INFORMATION, **kw)
def checkRequestNodeIdentification(self, conn, **kw):
return self.checkAskPacket(conn, protocol.REQUEST_NODE_IDENTIFICATION, **kw)
return self.checkAskPacket(conn, PacketTypes.REQUEST_NODE_IDENTIFICATION, **kw)
def checkAskPrimaryMaster(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_PRIMARY_MASTER)
return self.checkAskPacket(conn, PacketTypes.ASK_PRIMARY_MASTER)
def checkAskUnfinishedTransactions(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_UNFINISHED_TRANSACTIONS)
return self.checkAskPacket(conn, PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
def checkAskTransactionInformation(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_TRANSACTION_INFORMATION, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_TRANSACTION_INFORMATION, **kw)
def checkAskObjectPresent(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_OBJECT_PRESENT, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_OBJECT_PRESENT, **kw)
def checkAskObject(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_OBJECT, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_OBJECT, **kw)
def checkAskStoreObject(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_STORE_OBJECT, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_STORE_OBJECT, **kw)
def checkAskStoreTransaction(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_STORE_TRANSACTION, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_STORE_TRANSACTION, **kw)
def checkFinishTransaction(self, conn, **kw):
return self.checkAskPacket(conn, protocol.FINISH_TRANSACTION, **kw)
return self.checkAskPacket(conn, PacketTypes.FINISH_TRANSACTION, **kw)
def checkAskNewTid(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_BEGIN_TRANSACTION, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_BEGIN_TRANSACTION, **kw)
def checkAskLastIDs(self, conn, **kw):
return self.checkAskPacket(conn, protocol.ASK_LAST_IDS, **kw)
return self.checkAskPacket(conn, PacketTypes.ASK_LAST_IDS, **kw)
def checkAcceptNodeIdentification(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ACCEPT_NODE_IDENTIFICATION, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ACCEPT_NODE_IDENTIFICATION, **kw)
def checkAnswerPrimaryMaster(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_PRIMARY_MASTER, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_PRIMARY_MASTER, **kw)
def checkAnswerLastIDs(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_LAST_IDS, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_LAST_IDS, **kw)
def checkAnswerUnfinishedTransactions(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_UNFINISHED_TRANSACTIONS, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_UNFINISHED_TRANSACTIONS, **kw)
def checkAnswerObject(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT, **kw)
def checkAnswerTransactionInformation(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_TRANSACTION_INFORMATION, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_TRANSACTION_INFORMATION, **kw)
def checkAnswerTids(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_TIDS, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_TIDS, **kw)
def checkAnswerObjectHistory(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_HISTORY, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT_HISTORY, **kw)
def checkAnswerStoreTransaction(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_STORE_TRANSACTION, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_STORE_TRANSACTION, **kw)
def checkAnswerStoreObject(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_STORE_OBJECT, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_STORE_OBJECT, **kw)
def checkAnswerOids(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OIDS, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OIDS, **kw)
def checkAnswerPartitionTable(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_PARTITION_TABLE, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_PARTITION_TABLE, **kw)
def checkAnswerObjectPresent(self, conn, **kw):
return self.checkAnswerPacket(conn, protocol.ANSWER_OBJECT_PRESENT, **kw)
return self.checkAnswerPacket(conn, PacketTypes.ANSWER_OBJECT_PRESENT, **kw)
# XXX: imported from neo.master.test.connector since it's used at many places
......
......@@ -23,14 +23,9 @@ from struct import pack, unpack
from neo.tests import NeoTestBase
import neo.master
from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID
from neo.protocol import Packet, PacketTypes, NodeTypes, NodeStates
from neo.master.handlers.client import ClientServiceHandler
from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION
from neo.exception import OperationFailure, ElectionFailure
class MasterClientHandlerTests(NeoTestBase):
......@@ -82,7 +77,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_05_handleNotifyNodeInformation(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port),
......@@ -153,7 +148,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_06_handleAnswerLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.pt.getID()
......@@ -180,7 +175,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_07_handleAskBeginTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
packet = Packet(msg_type=PacketTypes.ASK_BEGIN_TRANSACTION)
ltid = self.app.ltid
# client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
......@@ -195,7 +190,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_08_handleAskNewOIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_NEW_OIDS)
packet = Packet(msg_type=PacketTypes.ASK_NEW_OIDS)
loid = self.app.loid
# client call it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
......@@ -206,7 +201,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_09_handleFinishTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=FINISH_TRANSACTION)
packet = Packet(msg_type=PacketTypes.FINISH_TRANSACTION)
packet.setId(9)
# give an older tid than the PMN known, must abort
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
......@@ -244,7 +239,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_11_handleAbortTransaction(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ABORT_TRANSACTION)
packet = Packet(msg_type=PacketTypes.ABORT_TRANSACTION)
# give a bad tid, must not failed, just ignored it
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
......@@ -263,7 +258,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_12_handleAskLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_LAST_IDS)
packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.pt.getID()
......@@ -280,7 +275,7 @@ class MasterClientHandlerTests(NeoTestBase):
def test_13_handleAskUnfinishedTransactions(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet)
......
......@@ -22,24 +22,9 @@ from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID
from neo.protocol import Packet, PacketTypes, NodeTypes, NodeStates, INVALID_UUID
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \
STOP_OPERATION, ASK_LAST_IDS, ANSWER_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_PARTITION_TABLE, SEND_PARTITION_TABLE, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ANSWER_UNFINISHED_TRANSACTIONS, \
ASK_OBJECT_PRESENT, ANSWER_OBJECT_PRESENT, \
DELETE_TRANSACTION, COMMIT_TRANSACTION, ASK_BEGIN_TRANSACTION, ANSWER_BEGIN_TRANSACTION, \
FINISH_TRANSACTION, NOTIFY_TRANSACTION_FINISHED, LOCK_INFORMATION, \
NOTIFY_INFORMATION_LOCKED, INVALIDATE_OBJECTS, UNLOCK_INFORMATION, \
ASK_NEW_OIDS, ANSWER_NEW_OIDS, ASK_STORE_OBJECT, ANSWER_STORE_OBJECT, \
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS
from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -541,7 +526,7 @@ class MasterServerElectionTests(NeoTestBase):
def test_12_handleAnnouncePrimaryMaster(self):
election = self.election
uuid = self.identifyToMasterNode(port=self.master_port)
packet = Packet(msg_type=ANNOUNCE_PRIMARY_MASTER)
packet = Packet(msg_type=PacketTypes.ANNOUNCE_PRIMARY_MASTER)
# No uuid
conn = Mock({"_addPacket" : None,
"getUUID" : None,
......@@ -583,7 +568,7 @@ class MasterServerElectionTests(NeoTestBase):
def test_14_handleNotifyNodeInformation(self):
election = self.election
uuid = self.identifyToMasterNode(port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# do not answer if no uuid
conn = Mock({"getUUID" : None,
"getAddress" : ("127.0.0.1", self.master_port)})
......
......@@ -20,7 +20,7 @@ from mock import Mock
from neo.tests import NeoTestBase
from neo.master.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION
INVALID_UUID, Packet
from neo.storage.mysqldb import p64, u64
class MasterAppTests(NeoTestBase):
......
......@@ -21,25 +21,10 @@ from neo import logging
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.protocol import Packet, PacketTypes
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
PING, PONG, ASK_PRIMARY_MASTER, ANSWER_PRIMARY_MASTER, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, START_OPERATION, \
STOP_OPERATION, ASK_LAST_IDS, ANSWER_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_PARTITION_TABLE, SEND_PARTITION_TABLE, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ANSWER_UNFINISHED_TRANSACTIONS, \
ASK_OBJECT_PRESENT, ANSWER_OBJECT_PRESENT, \
DELETE_TRANSACTION, COMMIT_TRANSACTION, ASK_BEGIN_TRANSACTION, ANSWER_BEGIN_TRANSACTION, \
FINISH_TRANSACTION, NOTIFY_TRANSACTION_FINISHED, LOCK_INFORMATION, \
NOTIFY_INFORMATION_LOCKED, INVALIDATE_OBJECTS, UNLOCK_INFORMATION, \
ASK_NEW_OIDS, ANSWER_NEW_OIDS, ASK_STORE_OBJECT, ANSWER_STORE_OBJECT, \
ABORT_TRANSACTION, ASK_STORE_TRANSACTION, ANSWER_STORE_TRANSACTION, \
ASK_OBJECT, ANSWER_OBJECT, ASK_TIDS, ANSWER_TIDS, ASK_TRANSACTION_INFORMATION, \
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS
from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -114,7 +99,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_08_handleNotifyNodeInformation(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# tell about a client node, do nothing
conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port,
......@@ -172,7 +157,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_09_handleAnswerLastIDs(self):
recovery = self.recovery
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.pt.getID()
......@@ -199,7 +184,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_10_handleAnswerPartitionTable(self):
recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE)
packet = Packet(msg_type=PacketTypes.ANSWER_PARTITION_TABLE)
# not from target node, ignore
uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port)
conn = self.getFakeConnection(uuid, self.storage_port)
......
......@@ -23,14 +23,10 @@ from struct import pack, unpack
from neo.tests import NeoTestBase
import neo.master
from neo import protocol
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, INVALID_UUID
from neo.protocol import Packet, PacketTypes
from neo.protocol import NodeTypes, NodeStates, CellStates
from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION
from neo.exception import OperationFailure, ElectionFailure
class MasterStorageHandlerTests(NeoTestBase):
......@@ -72,7 +68,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_05_handleNotifyNodeInformation(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
packet = Packet(msg_type=PacketTypes.NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port,
......@@ -142,7 +138,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_06_handleAnswerLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = self.app.pt.getID()
......@@ -160,7 +156,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_10_handleNotifyInformationLocked(self):
service = self.service
uuid = self.identifyToMasterNode(port=10020)
packet = Packet(msg_type=NOTIFY_INFORMATION_LOCKED)
packet = Packet(msg_type=PacketTypes.NOTIFY_INFORMATION_LOCKED)
# give an older tid than the PMN known, must abort
conn = self.getFakeConnection(uuid, self.storage_address)
oid_list = []
......@@ -203,7 +199,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_12_handleAskLastIDs(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_LAST_IDS)
packet = Packet(msg_type=PacketTypes.ASK_LAST_IDS)
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
ptid = self.app.pt.getID()
......@@ -220,7 +216,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_13_handleAskUnfinishedTransactions(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ASK_UNFINISHED_TRANSACTIONS)
packet = Packet(msg_type=PacketTypes.ASK_UNFINISHED_TRANSACTIONS)
# give a uuid
conn = self.getFakeConnection(uuid, self.storage_address)
service.handleAskUnfinishedTransactions(conn, packet)
......@@ -244,7 +240,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def test_14_handleNotifyPartitionChanges(self):
service = self.service
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
packet = Packet(msg_type=PacketTypes.NOTIFY_PARTITION_CHANGES)
# do not answer if not a storage node
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port=self.client_port)
......
......@@ -22,14 +22,10 @@ from mock import Mock
from struct import pack, unpack
import neo
from neo.tests import NeoTestBase
from neo.protocol import Packet, NodeTypes, NodeStates, CellStates, ErrorCodes
from neo.protocol import Packet, PacketTypes
from neo.protocol import NodeTypes, NodeStates, CellStates, ErrorCodes
from neo.master.handlers.verification import VerificationHandler
from neo.master.app import Application
from neo import protocol
from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, INVALID_UUID, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
from neo.tests import DoNothingConnector
from neo.connection import ClientConnection
......@@ -137,7 +133,7 @@ class MasterVerificationTests(NeoTestBase):
def test_09_handleAnswerLastIDs(self):
verification = self.verification
uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ANSWER_LAST_IDS)
packet = Packet(msg_type=PacketTypes.ANSWER_LAST_IDS)
loid = self.app.loid
ltid = self.app.ltid
lptid = '\0' * 8
......@@ -161,7 +157,7 @@ class MasterVerificationTests(NeoTestBase):