Commit 04d5bcc6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Apply new Enum class to node types. Use each time the 'NodeTypes' symbol import

to avoid full module.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1334 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7358c9bf
...@@ -28,6 +28,7 @@ from neo.bootstrap import BootstrapManager ...@@ -28,6 +28,7 @@ from neo.bootstrap import BootstrapManager
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo import protocol from neo import protocol
from neo.util import parseMasterList from neo.util import parseMasterList
from neo.protocol import NodeTypes
class Dispatcher: class Dispatcher:
"""Dispatcher use to redirect master request to handler""" """Dispatcher use to redirect master request to handler"""
...@@ -123,7 +124,7 @@ class Application(object): ...@@ -123,7 +124,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, protocol.ADMIN_NODE_TYPE, 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
......
...@@ -29,6 +29,7 @@ setupLog('CLIENT', verbose=True) ...@@ -29,6 +29,7 @@ setupLog('CLIENT', verbose=True)
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.event import EventManager from neo.event import EventManager
from neo.util import makeChecksum, dump from neo.util import makeChecksum, dump
from neo.locking import RLock, Lock from neo.locking import RLock, Lock
...@@ -86,7 +87,7 @@ class ConnectionPool(object): ...@@ -86,7 +87,7 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node) logging.error('Connection to storage node %s failed', node)
return None return None
p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(NodeTypes.CLIENT,
app.uuid, None, app.name) app.uuid, None, app.name)
msg_id = conn.ask(app.local_var.queue, p) msg_id = conn.ask(app.local_var.queue, p)
finally: finally:
...@@ -438,7 +439,7 @@ class Application(object): ...@@ -438,7 +439,7 @@ class Application(object):
self.trying_master_node) self.trying_master_node)
self.primary_master_node = None self.primary_master_node = None
break break
p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(NodeTypes.CLIENT,
self.uuid, None, self.name) self.uuid, None, self.name)
msg_id = conn.ask(self.local_var.queue, p) msg_id = conn.ask(self.local_var.queue, p)
finally: finally:
......
...@@ -20,6 +20,7 @@ from neo import logging ...@@ -20,6 +20,7 @@ from neo import logging
from neo.client.handlers import BaseHandler, AnswerBaseHandler from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo.pt import MTPartitionTable as PartitionTable from neo.pt import MTPartitionTable as PartitionTable
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.util import dump from neo.util import dump
class PrimaryBootstrapHandler(AnswerBaseHandler): class PrimaryBootstrapHandler(AnswerBaseHandler):
...@@ -35,7 +36,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -35,7 +36,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
# this must be a master node # this must be a master node
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
conn.close() conn.close()
return return
if conn.getAddress() != address: if conn.getAddress() != address:
...@@ -163,14 +164,14 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -163,14 +164,14 @@ class PrimaryNotificationsHandler(BaseHandler):
app = self.app app = self.app
self.app.nm.update(node_list) self.app.nm.update(node_list)
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != protocol.STORAGE_NODE_TYPE \ if node_type != NodeTypes.STORAGE \
or state != protocol.RUNNING_STATE: or state != protocol.RUNNING_STATE:
continue continue
# close connection to this storage if no longer running # close connection to this storage if no longer running
conn = self.app.em.getConnectionByUUID(uuid) conn = self.app.em.getConnectionByUUID(uuid)
if conn is not None: if conn is not None:
conn.close() conn.close()
if node_type == protocol.STORAGE_NODE_TYPE: if node_type == NodeTypes.STORAGE:
# Remove from pool connection # Remove from pool connection
app.cp.removeConnection(conn) app.cp.removeConnection(conn)
self.dispatcher.unregister(conn) self.dispatcher.unregister(conn)
......
...@@ -20,6 +20,7 @@ from ZODB.TimeStamp import TimeStamp ...@@ -20,6 +20,7 @@ from ZODB.TimeStamp import TimeStamp
from neo.client.handlers import BaseHandler, AnswerBaseHandler from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
class StorageEventHandler(BaseHandler): class StorageEventHandler(BaseHandler):
...@@ -56,8 +57,8 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -56,8 +57,8 @@ class StorageBootstrapHandler(AnswerBaseHandler):
uuid, address, num_partitions, num_replicas, your_uuid): uuid, address, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
# It can be eiter a master node or a storage node # this must be a storage node
if node_type != protocol.STORAGE_NODE_TYPE: if node_type != NodeTypes.STORAGE:
conn.close() conn.close()
return return
if conn.getAddress() != address: if conn.getAddress() != address:
......
...@@ -21,7 +21,7 @@ from time import time ...@@ -21,7 +21,7 @@ from time import time
from struct import pack, unpack from struct import pack, unpack
from neo import protocol from neo import protocol
from neo.protocol import UUID_NAMESPACES, ClusterStates from neo.protocol import UUID_NAMESPACES, ClusterStates, NodeTypes
from neo.node import NodeManager from neo.node import NodeManager
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection, ClientConnection from neo.connection import ListeningConnection, ClientConnection
...@@ -78,7 +78,7 @@ class Application(object): ...@@ -78,7 +78,7 @@ class Application(object):
# Generate an UUID for self # Generate an UUID for self
if uuid is None: if uuid is None:
uuid = self.getNewUUID(protocol.MASTER_NODE_TYPE) uuid = self.getNewUUID(NodeTypes.MASTER)
self.uuid = uuid self.uuid = uuid
# The last OID. # The last OID.
...@@ -770,12 +770,12 @@ class Application(object): ...@@ -770,12 +770,12 @@ class Application(object):
state = protocol.RUNNING_STATE state = protocol.RUNNING_STATE
handler = identification.IdentificationHandler handler = identification.IdentificationHandler
if node_type == protocol.ADMIN_NODE_TYPE: if node_type == NodeTypes.ADMIN:
# always accept admin nodes # always accept admin nodes
node_ctor = self.nm.createAdmin node_ctor = self.nm.createAdmin
handler = administration.AdministrationHandler handler = administration.AdministrationHandler
logging.info('Accept an admin %s' % dump(uuid)) logging.info('Accept an admin %s' % dump(uuid))
elif node_type == protocol.MASTER_NODE_TYPE: elif node_type == NodeTypes.MASTER:
if node is None: if node is None:
# unknown master, rejected # unknown master, rejected
raise protocol.ProtocolError('Reject an unknown master node') raise protocol.ProtocolError('Reject an unknown master node')
...@@ -783,7 +783,7 @@ class Application(object): ...@@ -783,7 +783,7 @@ class Application(object):
node_ctor = self.nm.createMaster node_ctor = self.nm.createMaster
handler = secondary.SecondaryMasterHandler handler = secondary.SecondaryMasterHandler
logging.info('Accept a master %s' % dump(uuid)) logging.info('Accept a master %s' % dump(uuid))
elif node_type == protocol.CLIENT_NODE_TYPE: elif node_type == NodeTypes.CLIENT:
# refuse any client before running # refuse any client before running
if self.cluster_state != ClusterStates.RUNNING: if self.cluster_state != ClusterStates.RUNNING:
logging.info('Reject a connection from a client') logging.info('Reject a connection from a client')
...@@ -791,7 +791,7 @@ class Application(object): ...@@ -791,7 +791,7 @@ class Application(object):
node_ctor = self.nm.createClient node_ctor = self.nm.createClient
handler = client.ClientServiceHandler handler = client.ClientServiceHandler
logging.info('Accept a client %s' % dump(uuid)) logging.info('Accept a client %s' % dump(uuid))
elif node_type == protocol.STORAGE_NODE_TYPE: elif node_type == NodeTypes.STORAGE:
node_ctor = self.nm.createStorage node_ctor = self.nm.createStorage
(uuid, state, handler) = self.identifyStorageNode(uuid, node) (uuid, state, handler) = self.identifyStorageNode(uuid, node)
logging.info('Accept a storage (%s)' % state) logging.info('Accept a storage (%s)' % state)
......
...@@ -19,6 +19,7 @@ from neo import logging ...@@ -19,6 +19,7 @@ from neo import logging
from neo import protocol from neo import protocol
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import NodeTypes
class MasterHandler(EventHandler): class MasterHandler(EventHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
...@@ -71,7 +72,7 @@ class MasterHandler(EventHandler): ...@@ -71,7 +72,7 @@ class MasterHandler(EventHandler):
DISCONNECTED_STATE_DICT = { DISCONNECTED_STATE_DICT = {
protocol.STORAGE_NODE_TYPE: protocol.TEMPORARILY_DOWN_STATE, NodeTypes.STORAGE: protocol.TEMPORARILY_DOWN_STATE,
} }
class BaseServiceHandler(MasterHandler): class BaseServiceHandler(MasterHandler):
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
...@@ -30,7 +31,7 @@ class ElectionHandler(MasterHandler): ...@@ -30,7 +31,7 @@ class ElectionHandler(MasterHandler):
raise protocol.UnexpectedPacketError raise protocol.UnexpectedPacketError
app = self.app app = self.app
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
# No interest. # No interest.
continue continue
...@@ -114,7 +115,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -114,7 +115,7 @@ class ClientElectionHandler(ElectionHandler):
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
# The peer is not a master node! # The peer is not a master node!
logging.error('%s:%d is not a master node', *address) logging.error('%s:%d is not a master node', *address)
app.nm.remove(node) app.nm.remove(node)
...@@ -198,7 +199,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -198,7 +199,7 @@ class ClientElectionHandler(ElectionHandler):
# Request a node idenfitication. # Request a node idenfitication.
conn.ask(protocol.requestNodeIdentification( conn.ask(protocol.requestNodeIdentification(
protocol.MASTER_NODE_TYPE, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server, app.server,
app.name app.name
...@@ -230,7 +231,7 @@ class ServerElectionHandler(ElectionHandler): ...@@ -230,7 +231,7 @@ class ServerElectionHandler(ElectionHandler):
return return
self.checkClusterName(name) self.checkClusterName(name)
app = self.app app = self.app
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
logging.info('reject a connection from a non-master') logging.info('reject a connection from a non-master')
raise protocol.NotReadyError raise protocol.NotReadyError
node = app.nm.getByAddress(address) node = app.nm.getByAddress(address)
...@@ -250,7 +251,7 @@ class ServerElectionHandler(ElectionHandler): ...@@ -250,7 +251,7 @@ class ServerElectionHandler(ElectionHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
p = protocol.acceptNodeIdentification( p = protocol.acceptNodeIdentification(
protocol.MASTER_NODE_TYPE, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server, app.server,
app.pt.getPartitions(), app.pt.getPartitions(),
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
class IdentificationHandler(MasterHandler): class IdentificationHandler(MasterHandler):
...@@ -73,7 +74,7 @@ class IdentificationHandler(MasterHandler): ...@@ -73,7 +74,7 @@ class IdentificationHandler(MasterHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
conn.setHandler(handler) conn.setHandler(handler)
# answer # answer
args = (protocol.MASTER_NODE_TYPE, 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(protocol.acceptNodeIdentification(*args), packet.getId()) conn.answer(protocol.acceptNodeIdentification(*args), packet.getId())
# trigger the event # trigger the event
......
...@@ -20,6 +20,7 @@ from neo import logging ...@@ -20,6 +20,7 @@ from neo import logging
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure, PrimaryFailure from neo.exception import ElectionFailure, PrimaryFailure
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
class SecondaryMasterHandler(MasterHandler): class SecondaryMasterHandler(MasterHandler):
""" Handler used by primary to handle secondary masters""" """ Handler used by primary to handle secondary masters"""
...@@ -66,7 +67,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -66,7 +67,7 @@ class PrimaryMasterHandler(MasterHandler):
def handleNotifyNodeInformation(self, conn, packet, node_list): def handleNotifyNodeInformation(self, conn, packet, node_list):
app = self.app app = self.app
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type != protocol.MASTER_NODE_TYPE: if node_type != NodeTypes.MASTER:
# No interest. # No interest.
continue continue
...@@ -90,7 +91,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -90,7 +91,7 @@ class PrimaryMasterHandler(MasterHandler):
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
assert node_type == protocol.MASTER_NODE_TYPE assert node_type == NodeTypes.MASTER
assert conn.getAddress() == address assert conn.getAddress() == address
if your_uuid != app.uuid: if your_uuid != app.uuid:
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from neo.neoctl.neoctl import NeoCTL, NotReadyException from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo.util import bin, dump from neo.util import bin, dump
from neo import protocol from neo import protocol
from neo.protocol import ClusterStates from neo.protocol import ClusterStates, NodeTypes
action_dict = { action_dict = {
'print': { 'print': {
...@@ -49,9 +49,7 @@ class TerminalNeoCTL(object): ...@@ -49,9 +49,7 @@ class TerminalNeoCTL(object):
return protocol.node_states.getFromStr(value) return protocol.node_states.getFromStr(value)
def asNodeType(self, value): def asNodeType(self, value):
if not value.endswith('_NODE_TYPE'): return NodeTypes.getByName(values.upper())
value += '_NODE_TYPE'
return protocol.node_types.getFromStr(value)
def asClusterState(self, value): def asClusterState(self, value):
return ClusterStates.getByName(value.upper()) return ClusterStates.getByName(value.upper())
...@@ -167,8 +165,7 @@ class TerminalNeoCTL(object): ...@@ -167,8 +165,7 @@ class TerminalNeoCTL(object):
otherwise, the list of storage nodes to enable. otherwise, the list of storage nodes to enable.
""" """
if len(params) == 1 and params[0] == 'all': if len(params) == 1 and params[0] == 'all':
node_list = self.neoctl.getNodeList( node_list = self.neoctl.getNodeList(NodeTypes.STORAGE)
node_type=protocol.STORAGE_NODE_TYPE)
uuid_list = [node[2] for node in node_list] uuid_list = [node[2] for node in node_list]
else: else:
uuid_list = [self.asNode(x) for x in params] uuid_list = [self.asNode(x) for x in params]
......
...@@ -20,6 +20,7 @@ from time import time ...@@ -20,6 +20,7 @@ from time import time
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.util import dump from neo.util import dump
from neo.protocol import NodeTypes
class Node(object): class Node(object):
"""This class represents a node.""" """This class represents a node."""
...@@ -158,16 +159,16 @@ class AdminNode(Node): ...@@ -158,16 +159,16 @@ class AdminNode(Node):
NODE_TYPE_MAPPING = { NODE_TYPE_MAPPING = {
protocol.MASTER_NODE_TYPE: MasterNode, NodeTypes.MASTER: MasterNode,
protocol.STORAGE_NODE_TYPE: StorageNode, NodeTypes.STORAGE: StorageNode,
protocol.CLIENT_NODE_TYPE: ClientNode, NodeTypes.CLIENT: ClientNode,
protocol.ADMIN_NODE_TYPE: AdminNode, NodeTypes.ADMIN: AdminNode,
} }
NODE_CLASS_MAPPING = { NODE_CLASS_MAPPING = {
StorageNode: protocol.STORAGE_NODE_TYPE, StorageNode: NodeTypes.STORAGE,
MasterNode: protocol.MASTER_NODE_TYPE, MasterNode: NodeTypes.MASTER,
ClientNode: protocol.CLIENT_NODE_TYPE, ClientNode: NodeTypes.CLIENT,
AdminNode: protocol.ADMIN_NODE_TYPE, AdminNode: NodeTypes.ADMIN,
} }
class NodeManager(object): class NodeManager(object):
......
...@@ -327,13 +327,14 @@ class ClusterStates(Enum): ...@@ -327,13 +327,14 @@ class ClusterStates(Enum):
ClusterStates = ClusterStates() ClusterStates = ClusterStates()
# Node types. class NodeTypes(Enum):
node_types = OldEnum({
'MASTER_NODE_TYPE' : 1, MASTER = Enum.Item(1)
'STORAGE_NODE_TYPE' : 2, STORAGE = Enum.Item(2)
'CLIENT_NODE_TYPE' : 3, CLIENT = Enum.Item(3)
'ADMIN_NODE_TYPE' : 4, ADMIN = Enum.Item(4)
})
NodeTypes = NodeTypes()
# Node states. # Node states.
node_states = OldEnum({ node_states = OldEnum({
...@@ -387,10 +388,10 @@ CLIENT_NS = 'C' ...@@ -387,10 +388,10 @@ CLIENT_NS = 'C'
ADMIN_NS = 'A' ADMIN_NS = 'A'
UUID_NAMESPACES = { UUID_NAMESPACES = {
STORAGE_NODE_TYPE: STORAGE_NS, NodeTypes.STORAGE: STORAGE_NS,
MASTER_NODE_TYPE: MASTER_NS, NodeTypes.MASTER: MASTER_NS,
CLIENT_NODE_TYPE: CLIENT_NS, NodeTypes.CLIENT: CLIENT_NS,
ADMIN_NODE_TYPE: ADMIN_NS, NodeTypes.ADMIN: ADMIN_NS,
} }
class ProtocolError(Exception): class ProtocolError(Exception):
...@@ -510,7 +511,7 @@ def _decodeNodeState(state): ...@@ -510,7 +511,7 @@ def _decodeNodeState(state):
return node_state return node_state
def _decodeNodeType(original_node_type): def _decodeNodeType(original_node_type):
node_type = node_types.get(original_node_type) node_type = NodeTypes.get(original_node_type)
if node_type is None: if node_type is None:
raise PacketMalformedError('invalid node type %d' % original_node_type) raise PacketMalformedError('invalid node type %d' % original_node_type)
return node_type return node_type
......
...@@ -20,6 +20,7 @@ import sys ...@@ -20,6 +20,7 @@ import sys
from collections import deque from collections import deque
from neo import protocol from neo import protocol
from neo.protocol import NodeTypes
from neo.node import NodeManager from neo.node import NodeManager
from neo.event import EventManager from neo.event import EventManager
from neo.storage.mysqldb import MySQLDatabaseManager from neo.storage.mysqldb import MySQLDatabaseManager
...@@ -196,7 +197,7 @@ class Application(object): ...@@ -196,7 +197,7 @@ class Application(object):
# search, find, connect and identify to the primary master # search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, bootstrap = BootstrapManager(self, self.name,
protocol.STORAGE_NODE_TYPE, self.uuid, self.server) NodeTypes.STORAGE, 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
self.master_node = node self.master_node = node
......
...@@ -19,7 +19,7 @@ from neo import logging ...@@ -19,7 +19,7 @@ from neo import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo import protocol from neo import protocol
from neo.protocol import BROKEN_STATE, CLIENT_NODE_TYPE, \ from neo.protocol import BROKEN_STATE, \
DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE
from neo.util import dump from neo.util import dump
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
......
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
from neo import logging from neo import logging
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import BROKEN_STATE, STORAGE_NODE_TYPE, DOWN_STATE, \ from neo.protocol import BROKEN_STATE, DOWN_STATE, \
TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.protocol import NodeTypes
class HiddenHandler(BaseMasterHandler): class HiddenHandler(BaseMasterHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
...@@ -34,7 +35,7 @@ class HiddenHandler(BaseMasterHandler): ...@@ -34,7 +35,7 @@ class HiddenHandler(BaseMasterHandler):
app = self.app app = self.app
self.app.nm.update(node_list) self.app.nm.update(node_list)
for node_type, addr, uuid, state in node_list: for node_type, addr, uuid, state in node_list:
if node_type == STORAGE_NODE_TYPE: if node_type == NodeTypes.STORAGE:
if uuid == self.app.uuid: if uuid == self.app.uuid:
# This is me, do what the master tell me # This is me, do what the master tell me
if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, BROKEN_STATE): if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, BROKEN_STATE):
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from neo import logging from neo import logging
from neo.storage.handlers import BaseStorageHandler from neo.storage.handlers import BaseStorageHandler
from neo.protocol import NodeTypes
from neo import protocol from neo import protocol
from neo.util import dump from neo.util import dump
...@@ -36,12 +37,12 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -36,12 +37,12 @@ class IdentificationHandler(BaseStorageHandler):
app = self.app app = self.app
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 == protocol.CLIENT_NODE_TYPE: 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()
elif node_type == protocol.STORAGE_NODE_TYPE: elif node_type == NodeTypes.STORAGE:
from neo.storage.handlers.storage import StorageOperationHandler from neo.storage.handlers.storage import StorageOperationHandler
handler = StorageOperationHandler handler = StorageOperationHandler
else: else:
...@@ -57,7 +58,7 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -57,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 = (protocol.STORAGE_NODE_TYPE, 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(protocol.acceptNodeIdentification(*args), packet.getId()) conn.answer(protocol.acceptNodeIdentification(*args), packet.getId())
......
...@@ -20,8 +20,8 @@ from random import choice ...@@ -20,8 +20,8 @@ from random import choice
from neo.storage.handlers import replication from neo.storage.handlers import replication
from neo import protocol from neo import protocol
from neo.protocol import STORAGE_NODE_TYPE, UP_TO_DATE_STATE, \ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, RUNNING_STATE
OUT_OF_DATE_STATE, RUNNING_STATE from neo.protocol import NodeTypes
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.util import dump from neo.util import dump
...@@ -180,8 +180,8 @@ class Replicator(object): ...@@ -180,8 +180,8 @@ class Replicator(object):
self.current_connection = ClientConnection(app.em, handler, self.current_connection = ClientConnection(app.em, handler,
addr = addr, addr = addr,
connector_handler = app.connector_handler) connector_handler = app.connector_handler)
p = protocol.requestNodeIdentification(STORAGE_NODE_TYPE, app.uuid, p = protocol.requestNodeIdentification(NodeTypes.STORAGE,
app.server, app.name) app.uuid, app.server, app.name)
self.current_connection.ask(p) self.current_connection.ask(p)
self.tid_offset = 0 self.tid_offset = 0
......
...@@ -334,7 +334,7 @@ class TestElectionConnector(DoNothingConnector): ...@@ -334,7 +334,7 @@ class TestElectionConnector(DoNothingConnector):
p = protocol.Packet() p = protocol.Packet()
self.uuid = getNewUUID() self.uuid = getNewUUID()
p.acceptNodeIdentification(1, p.acceptNodeIdentification(1,
protocol.MASTER_NODE_TYPE, NodeType.MASTER,
self.uuid, self.uuid,
self.getAddress()[0], self.getAddress()[0],
self.getAddress()[1], self.getAddress()[1],
......
...@@ -23,8 +23,7 @@ from neo.tests import NeoTestBase ...@@ -23,8 +23,7 @@ from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.protocol import UnexpectedPacketError, INVALID_UUID from neo.protocol import UnexpectedPacketError, INVALID_UUID
from neo.protocol import \ from neo.protocol import NodeTypes, INVALID_PTID, \
INVALID_PTID, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, \
UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.client.handlers import BaseHandler from neo.client.handlers import BaseHandler
...@@ -95,7 +94,11 @@ class ClientHandlerTests(NeoTestBase): ...@@ -95,7 +94,11 @@ class ClientHandlerTests(NeoTestBase):
storage_ip = '127.0.0.1' storage_ip = '127.0.0.1'
storage_port = 10011 storage_port = 10011
fake_storage_node_uuid = self.getNewUUID() fake_storage_node_uuid = self.getNewUUID()
fake_storage_node = Mock({'getUUID': fake_storage_node_uuid, 'getAddress': (storage_ip, storage_port), 'getType': STORAGE_NODE_TYPE}) fake_storage_node = Mock({
'getUUID': fake_storage_node_uuid,
'getAddress': (storage_ip, storage_port),
'getType': NodeTypes.STORAGE
})
master_node_next_packet_id = 1 master_node_next_packet_id = 1
class App: class App:
primary_master_node = Mock({'getUUID': self.getNewUUID()}) primary_master_node = Mock({'getUUID': self.getNewUUID()})
...@@ -220,8 +223,12 @@ class ClientHandlerTests(NeoTestBase): ...@@ -220,8 +223,12 @@ 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.handleAcceptNodeIdentification(conn, None, CLIENT_NODE_TYPE, client_handler.handleAcceptNodeIdentification(
uuid, ('127.0.0.1', 10010), 0, 0, INVALID_UUID) conn, None,
NodeTypes.CLIENT,
uuid, ('127.0.0.1', 10010),
0, 0, INVALID_UUID
)
self.checkClosed(conn) self.checkClosed(conn)
self.assertEquals(app.storage_node, None) self.assertEquals(app.storage_node, None)
self.assertEquals(app.pt, None) self.assertEquals(app.pt, None)
...@@ -244,8 +251,8 @@ class ClientHandlerTests(NeoTestBase): ...@@ -244,8 +251,8 @@ 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.handleAcceptNodeIdentification(conn, None, MASTER_NODE_TYPE, client_handler.handleAcceptNodeIdentification(conn, None,
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)
self.assertEquals(app.storage_node, None) self.assertEquals(app.storage_node, None)
...@@ -264,8 +271,8 @@ class ClientHandlerTests(NeoTestBase): ...@@ -264,8 +271,8 @@ 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.handleAcceptNodeIdentification(conn, None, STORAGE_NODE_TYPE, client_handler.handleAcceptNodeIdentification(conn, None,
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)
self.assertEquals(app.pt, None) self.assertEquals(app.pt, None)
...@@ -276,7 +283,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -276,7 +283,7 @@ class ClientHandlerTests(NeoTestBase):
# Master node handler # Master node handler
def test_nonMasterAnswerPrimaryMaster(self): def test_nonMasterAnswerPrimaryMaster(self):
for node_type in (CLIENT_NODE_TYPE, STORAGE_NODE_TYPE): for node_type in (NodeTypes.CLIENT, NodeTypes.STORAGE):
node = Mock({'getType': node_type}) node = Mock({'getType': node_type})
class App: class App:
nm = Mock({'getByUUID': node, 'getByAddress': None, 'add': None}) nm = Mock({'getByUUID': node, 'getByAddress': None, 'add': None})
...@@ -290,7 +297,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -290,7 +297,7 @@ class ClientHandlerTests(NeoTestBase):
self.assertEqual(len(app.nm.mockGetNamedCalls('add')), 0) self.assertEqual(len(app.nm.mockGetNamedCalls('add')), 0)
def test_unknownNodeAnswerPrimaryMaster(self): def test_unknownNodeAnswerPrimaryMaster(self):
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': NodeTypes.MASTER})
class App: class App:
nm = Mock({'getByAddress': None, 'add': None}) nm = Mock({'getByAddress': None, 'add': None})
primary_master_node = None primary_master_node = None
...@@ -315,7 +322,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -315,7 +322,7 @@ class ClientHandlerTests(NeoTestBase):
self.assertEquals(app.primary_master_node, None) self.assertEquals(app.primary_master_node, None)
def test_knownNodeUnknownUUIDNodeAnswerPrimaryMaster(self): def test_knownNodeUnknownUUIDNodeAnswerPrimaryMaster(self):
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': None, 'setUUID': None}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': None, 'setUUID': None})
class App: class App:
nm = Mock({'getByAddress': node, 'add': None}) nm = Mock({'getByAddress': node, 'add': None})
primary_master_node = None primary_master_node = None
...@@ -342,7 +349,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -342,7 +349,7 @@ class ClientHandlerTests(NeoTestBase):
def test_knownNodeKnownUUIDNodeAnswerPrimaryMaster(self): def test_knownNodeKnownUUIDNodeAnswerPrimaryMaster(self):
test_node_uuid = self.getNewUUID() test_node_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_node_uuid, 'setUUID': None})
class App: class App:
nm = Mock({'getByAddress': node, 'add': None}) nm = Mock({'getByAddress': node, 'add': None})
primary_master_node = None primary_master_node = None
...@@ -376,7 +383,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -376,7 +383,7 @@ class ClientHandlerTests(NeoTestBase):
while test_primary_node_uuid == test_node_uuid: while test_primary_node_uuid == test_node_uuid:
test_primary_node_uuid = self.getNewUUID() test_primary_node_uuid = self.getNewUUID()
test_primary_master_node = Mock({'getUUID': test_primary_node_uuid}) test_primary_master_node = Mock({'getUUID': test_primary_node_uuid})
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_node_uuid, 'setUUID': None})
class App: class App:
nm = Mock({'getByUUID': node, 'getByAddress': node, 'add': None}) nm = Mock({'getByUUID': node, 'getByAddress': node, 'add': None})
primary_master_node = test_primary_master_node primary_master_node = test_primary_master_node
...@@ -399,7 +406,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -399,7 +406,7 @@ class ClientHandlerTests(NeoTestBase):
def test_alreadySamePrimaryAnswerPrimaryMaster(self): def test_alreadySamePrimaryAnswerPrimaryMaster(self):
test_node_uuid = self.getNewUUID() test_node_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_node_uuid, 'setUUID': None})
class App: class App:
nm = Mock({'getByUUID': node, 'getByAddress': node, 'add': None}) nm = Mock({'getByUUID': node, 'getByAddress': node, 'add': None})
primary_master_node = node primary_master_node = node
...@@ -416,7 +423,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -416,7 +423,7 @@ class ClientHandlerTests(NeoTestBase):
test_primary_node_uuid = test_node_uuid test_primary_node_uuid = test_node_uuid
while test_primary_node_uuid == test_node_uuid: while test_primary_node_uuid == test_node_uuid:
test_primary_node_uuid = self.getNewUUID() test_primary_node_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_node_uuid, 'setUUID': None})
class App: class App:
nm = Mock({'getByUUID': None, 'getByAddress': node, 'add': None}) nm = Mock({'getByUUID': None, 'getByAddress': node, 'add': None})
primary_master_node = None primary_master_node = None
...@@ -434,7 +441,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -434,7 +441,7 @@ class ClientHandlerTests(NeoTestBase):
def test_AnswerPrimaryMaster(self): def test_AnswerPrimaryMaster(self):
test_node_uuid = self.getNewUUID() test_node_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_node_uuid, 'setUUID': None})
class App: class App:
nm = Mock({'getByUUID': node, 'getByAddress': node, 'add': None}) nm = Mock({'getByUUID': node, 'getByAddress': node, 'add': None})
primary_master_node = None primary_master_node = None
...@@ -455,7 +462,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -455,7 +462,7 @@ class ClientHandlerTests(NeoTestBase):
self.assertTrue(app.primary_master_node is node) self.assertTrue(app.primary_master_node is node)
def test_newSendPartitionTable(self): def test_newSendPartitionTable(self):
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': NodeTypes.MASTER})
test_ptid = 0 test_ptid = 0
class App: class App:
nm = Mock({'getByUUID': node}) nm = Mock({'getByUUID': node})
...@@ -468,7 +475,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -468,7 +475,7 @@ class ClientHandlerTests(NeoTestBase):
self.assertEquals(app.pt.getID(), 1) self.assertEquals(app.pt.getID(), 1)
def test_unknownNodeSendPartitionTable(self): def test_unknownNodeSendPartitionTable(self):
test_node = Mock({'getType': MASTER_NODE_TYPE}) test_node = Mock({'getType': NodeTypes.MASTER})
test_ptid = 0 test_ptid = 0
class App: class App:
nm = Mock({'getByUUID': ReturnValues(test_node, None), 'add': None}) nm = Mock({'getByUUID': ReturnValues(test_node, None), 'add': None})
...@@ -493,7 +500,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -493,7 +500,7 @@ class ClientHandlerTests(NeoTestBase):
test_row_list[0][1][0][1]) test_row_list[0][1][0][1])
def test_knownNodeSendPartitionTable(self): def test_knownNodeSendPartitionTable(self):
test_node = Mock({'getType': MASTER_NODE_TYPE}) test_node = Mock({'getType': NodeTypes.MASTER})
test_ptid = 0 test_ptid = 0
class App: class App:
nm = Mock({'getByUUID': test_node, 'add': None}) nm = Mock({'getByUUID': test_node, 'add': None})
...@@ -515,7 +522,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -515,7 +522,7 @@ class ClientHandlerTests(NeoTestBase):
test_row_list[0][1][0][1]) test_row_list[0][1][0][1])
def test_nonMasterNotifyNodeInformation(self): def test_nonMasterNotifyNodeInformation(self):
for node_type in (CLIENT_NODE_TYPE, STORAGE_NODE_TYPE): for node_type in (NodeTypes.CLIENT, NodeTypes.STORAGE):
test_master_uuid = self.getNewUUID() test_master_uuid = self.getNewUUID()
node = Mock({'getType': node_type}) node = Mock({'getType': node_type})
class App: class App:
...@@ -531,7 +538,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -531,7 +538,7 @@ class ClientHandlerTests(NeoTestBase):
# by making a valid call with a non-iterable parameter given as # by making a valid call with a non-iterable parameter given as
# node_list value. # node_list value.
test_master_uuid = self.getNewUUID() test_master_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': NodeTypes.MASTER})
class App: class App:
nm = Mock({'getByUUID': node}) nm = Mock({'getByUUID': node})
app = App() app = App()
...@@ -545,7 +552,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -545,7 +552,7 @@ class ClientHandlerTests(NeoTestBase):
INVALID_UUID, test_node[4]) INVALID_UUID, test_node[4])
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()
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': NodeTypes.MASTER})
if getByUUID is not MARKER: if getByUUID is not MARKER:
getByUUID = ReturnValues(node, getNodeByUUID) getByUUID = ReturnValues(node, getNodeByUUID)
class App: class App:
...@@ -563,7 +570,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -563,7 +570,7 @@ class ClientHandlerTests(NeoTestBase):
def test_unknownMasterNotifyNodeInformation(self): def test_unknownMasterNotifyNodeInformation(self):
# first notify unknown master nodes # first notify unknown master nodes
uuid = self.getNewUUID() uuid = self.getNewUUID()
test_node = (MASTER_NODE_TYPE, '127.0.0.1', 10010, uuid, test_node = (NodeTypes.MASTER, '127.0.0.1', 10010, uuid,
RUNNING_STATE) RUNNING_STATE)
nm = self._testNotifyNodeInformation(test_node, getByUUID=None) nm = self._testNotifyNodeInformation(test_node, getByUUID=None)
# Check that two nodes got added (second is with INVALID_UUID) # Check that two nodes got added (second is with INVALID_UUID)
...@@ -577,7 +584,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -577,7 +584,7 @@ class ClientHandlerTests(NeoTestBase):
def test_knownMasterNotifyNodeInformation(self): def test_knownMasterNotifyNodeInformation(self):
node = Mock({}) node = Mock({})
uuid = self.getNewUUID() uuid = self.getNewUUID()
test_node = (MASTER_NODE_TYPE, '127.0.0.1', 10010, uuid, test_node = (NodeTypes.MASTER, '127.0.0.1', 10010, uuid,
RUNNING_STATE) RUNNING_STATE)
nm = self._testNotifyNodeInformation(test_node, getByAddress=node, nm = self._testNotifyNodeInformation(test_node, getByAddress=node,
getByUUID=node) getByUUID=node)
...@@ -592,7 +599,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -592,7 +599,7 @@ class ClientHandlerTests(NeoTestBase):
self.assertEqual(setState_call_list[0].getParam(0), test_node[4]) self.assertEqual(setState_call_list[0].getParam(0), test_node[4])
def test_unknownStorageNotifyNodeInformation(self): def test_unknownStorageNotifyNodeInformation(self):
test_node = (STORAGE_NODE_TYPE, '127.0.0.1', 10010, self.getNewUUID(), test_node = (NodeTypes.STORAGE, '127.0.0.1', 10010, self.getNewUUID(),
RUNNING_STATE) RUNNING_STATE)
nm = self._testNotifyNodeInformation(test_node, getByUUID=None) nm = self._testNotifyNodeInformation(test_node, getByUUID=None)
# Check that node got added # Check that node got added
...@@ -607,7 +614,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -607,7 +614,7 @@ class ClientHandlerTests(NeoTestBase):
def test_knownStorageNotifyNodeInformation(self): def test_knownStorageNotifyNodeInformation(self):
node = Mock({'setState': None, 'setAddress': None}) node = Mock({'setState': None, 'setAddress': None})
test_node = (STORAGE_NODE_TYPE, '127.0.0.1', 10010, self.getNewUUID(), test_node = (NodeTypes.STORAGE, '127.0.0.1', 10010, self.getNewUUID(),
RUNNING_STATE) RUNNING_STATE)
nm = self._testNotifyNodeInformation(test_node, getByUUID=node) nm = self._testNotifyNodeInformation(test_node, getByUUID=node)
# Check that node got replaced # Check that node got replaced
...@@ -632,7 +639,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -632,7 +639,7 @@ class ClientHandlerTests(NeoTestBase):
args=(conn, None, None, None)) args=(conn, None, None, None))
def test_nonMasterNotifyPartitionChanges(self): def test_nonMasterNotifyPartitionChanges(self):
for node_type in (CLIENT_NODE_TYPE, STORAGE_NODE_TYPE): for node_type in (NodeTypes.CLIENT, NodeTypes.STORAGE):
test_master_uuid = self.getNewUUID() test_master_uuid = self.getNewUUID()
node = Mock({'getType': node_type, 'getUUID': test_master_uuid}) node = Mock({'getType': node_type, 'getUUID': test_master_uuid})
class App: class App:
...@@ -649,7 +656,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -649,7 +656,7 @@ class ClientHandlerTests(NeoTestBase):
self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0) self.assertEquals(len(app.pt.mockGetNamedCalls('removeCell')), 0)
def test_noPrimaryMasterNotifyPartitionChanges(self): def test_noPrimaryMasterNotifyPartitionChanges(self):
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': NodeTypes.MASTER})
class App: class App:
nm = Mock({'getByUUID': node}) nm = Mock({'getByUUID': node})
pt = Mock() pt = Mock()
...@@ -668,7 +675,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -668,7 +675,7 @@ class ClientHandlerTests(NeoTestBase):
test_sender_uuid = test_master_uuid test_sender_uuid = test_master_uuid
while test_sender_uuid == test_master_uuid: while test_sender_uuid == test_master_uuid:
test_sender_uuid = self.getNewUUID() test_sender_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE}) node = Mock({'getType': NodeTypes.MASTER})
test_master_node = Mock({'getUUID': test_master_uuid}) test_master_node = Mock({'getUUID': test_master_uuid})
class App: class App:
nm = Mock({'getByUUID': node}) nm = Mock({'getByUUID': node})
...@@ -685,7 +692,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -685,7 +692,7 @@ class ClientHandlerTests(NeoTestBase):
def test_ignoreOutdatedPTIDNotifyPartitionChanges(self): def test_ignoreOutdatedPTIDNotifyPartitionChanges(self):
test_master_uuid = self.getNewUUID() test_master_uuid = self.getNewUUID()
node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_master_uuid}) node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_master_uuid})
test_ptid = 1 test_ptid = 1
class App: class App:
nm = Mock({'getByUUID': node}) nm = Mock({'getByUUID': node})
...@@ -703,7 +710,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -703,7 +710,7 @@ class ClientHandlerTests(NeoTestBase):
def test_unknownNodeNotifyPartitionChanges(self): def test_unknownNodeNotifyPartitionChanges(self):
test_master_uuid = self.getNewUUID() test_master_uuid = self.getNewUUID()
test_node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': test_master_uuid}) test_node = Mock({'getType': NodeTypes.MASTER, 'getUUID': test_master_uuid})
test_ptid = 1 test_ptid = 1
class App: class App:
nm = Mock({'getByUUID': ReturnValues(None)}) nm = Mock({'getByUUID': ReturnValues(None)})
...@@ -734,7 +741,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -734,7 +741,7 @@ class ClientHandlerTests(NeoTestBase):
test_ptid = 1 test_ptid = 1
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID() uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
uuid3, uuid4 = self.getNewUUID(), self.getNewUUID() uuid3, uuid4 = self.getNewUUID(), self.getNewUUID()
test_node = Mock({'getType': MASTER_NODE_TYPE, 'getUUID': uuid1}) test_node = Mock({'getType': NodeTypes.MASTER, 'getUUID': uuid1})
class App: class App:
nm = Mock({'getByUUID': ReturnValues(test_node, None, None, None), 'add': None}) nm = Mock({'getByUUID': ReturnValues(test_node, None, None, None), 'add': None})
pt = Mock({'setCell': None}) pt = Mock({'setCell': None})
......
...@@ -28,7 +28,7 @@ import unittest ...@@ -28,7 +28,7 @@ import unittest
import tempfile import tempfile
import traceback import traceback
from neo.protocol import ClusterStates from neo.protocol import ClusterStates, NodeTypes
from neo.client.Storage import Storage from neo.client.Storage import Storage
from neo.tests import getNewUUID from neo.tests import getNewUUID
from neo.util import dump from neo.util import dump
...@@ -245,7 +245,7 @@ class NEOCluster(object): ...@@ -245,7 +245,7 @@ class NEOCluster(object):
if time.time() > end_time: if time.time() > end_time:
raise AssertionError, 'Timeout when starting cluster' raise AssertionError, 'Timeout when starting cluster'
storage_node_list = neoctl.getNodeList( storage_node_list = neoctl.getNodeList(
node_type=protocol.STORAGE_NODE_TYPE) node_type=NodeTypes.STORAGE)
if len(storage_node_list) == target_count: if len(storage_node_list) == target_count:
break break
time.sleep(0.5) time.sleep(0.5)
...@@ -332,10 +332,10 @@ class NEOCluster(object): ...@@ -332,10 +332,10 @@ class NEOCluster(object):
if state is None or x[3] == state] if state is None or x[3] == state]
def getMasterList(self, state=None): def getMasterList(self, state=None):
return self.__getNodeList(protocol.MASTER_NODE_TYPE, state) return self.__getNodeList(NodeTypes.MASTER, state)
def getStorageList(self, state=None): def getStorageList(self, state=None):
return self.__getNodeList(protocol.STORAGE_NODE_TYPE, state) return self.__getNodeList(NodeTypes.STORAGE, state)
def __getNodeState(self, node_type, uuid): def __getNodeState(self, node_type, uuid):
node_list = self.__getNodeList(node_type) node_list = self.__getNodeList(node_type)
...@@ -347,7 +347,7 @@ class NEOCluster(object): ...@@ -347,7 +347,7 @@ class NEOCluster(object):
return state return state
def getMasterNodeState(self, uuid): def getMasterNodeState(self, uuid):
return self.__getNodeState(protocol.MASTER_NODE_TYPE, uuid) return self.__getNodeState(NodeTypes.MASTER, uuid)
def getPrimaryMaster(self): def getPrimaryMaster(self):
try: try:
...@@ -389,11 +389,11 @@ class NEOCluster(object): ...@@ -389,11 +389,11 @@ class NEOCluster(object):
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(protocol.MASTER_NODE_TYPE, 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(protocol.STORAGE_NODE_TYPE, uuid, state, self.__expectNodeState(NodeTypes.STORAGE, uuid, state,
timeout,delay) timeout,delay)
def expectPrimaryMaster(self, uuid=None, timeout=0, delay=1): def expectPrimaryMaster(self, uuid=None, timeout=0, delay=1):
......
...@@ -23,7 +23,7 @@ from struct import pack, unpack ...@@ -23,7 +23,7 @@ from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
from neo.master.handlers.client import ClientServiceHandler from neo.master.handlers.client import ClientServiceHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
...@@ -31,7 +31,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ ...@@ -31,7 +31,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \ ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \ ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \ NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -68,7 +67,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -68,7 +67,7 @@ class MasterClientHandlerTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """ """Do first step of identification to MN """
# register the master itself # register the master itself
...@@ -88,24 +87,24 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -88,24 +87,24 @@ class MasterClientHandlerTests(NeoTestBase):
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises # tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port), self.app.uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port), self.app.uuid, DOWN_STATE),]
self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list)
# tell the master node that it's running, nothing change # tell the master node that it's running, nothing change
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port), self.app.uuid, RUNNING_STATE),] node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port), self.app.uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a client node, don't care # notify about a client node, don't care
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(CLIENT_NODE_TYPE, ('127.0.0.1', self.client_port), new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.client_port), new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about an unknown node, don't care # notify about an unknown node, don't care
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', 11010), new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11010), new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -115,20 +114,20 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -115,20 +114,20 @@ class MasterClientHandlerTests(NeoTestBase):
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', 11012), uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11012), uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is running, as PMN already know it, nothing is done # notify node is running, as PMN already know it, nothing is done
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', self.storage_port), uuid, RUNNING_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is temp down, must be taken into account # notify node is temp down, must be taken into account
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', self.storage_port), uuid, TEMPORARILY_DOWN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, TEMPORARILY_DOWN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -137,7 +136,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -137,7 +136,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(ptid, self.app.pt.getID()) self.assertEquals(ptid, self.app.pt.getID())
# notify node is broken, must be taken into account and partition must changed # notify node is broken, must be taken into account and partition must changed
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, ('127.0.0.1', self.storage_port), uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -154,7 +153,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -154,7 +153,7 @@ class MasterClientHandlerTests(NeoTestBase):
ltid = self.app.ltid ltid = self.app.ltid
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
# do not care if client node call it # do not care if client node call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
node_list = [] node_list = []
self.checkUnexpectedPacketRaised(service.handleAnswerLastIDs, conn, packet, None, None, None) self.checkUnexpectedPacketRaised(service.handleAnswerLastIDs, conn, packet, None, None, None)
...@@ -179,7 +178,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -179,7 +178,7 @@ class MasterClientHandlerTests(NeoTestBase):
packet = Packet(msg_type=ASK_BEGIN_TRANSACTION) packet = Packet(msg_type=ASK_BEGIN_TRANSACTION)
ltid = self.app.ltid ltid = self.app.ltid
# client call it # client call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskBeginTransaction(conn, packet, None) service.handleAskBeginTransaction(conn, packet, None)
self.failUnless(ltid < self.app.ltid) self.failUnless(ltid < self.app.ltid)
...@@ -194,7 +193,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -194,7 +193,7 @@ class MasterClientHandlerTests(NeoTestBase):
packet = Packet(msg_type=ASK_NEW_OIDS) packet = Packet(msg_type=ASK_NEW_OIDS)
loid = self.app.loid loid = self.app.loid
# client call it # client call it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
service.handleAskNewOIDs(conn, packet, 1) service.handleAskNewOIDs(conn, packet, 1)
self.failUnless(loid < self.app.loid) self.failUnless(loid < self.app.loid)
...@@ -205,7 +204,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -205,7 +204,7 @@ class MasterClientHandlerTests(NeoTestBase):
packet = Packet(msg_type=FINISH_TRANSACTION) packet = Packet(msg_type=FINISH_TRANSACTION)
packet.setId(9) packet.setId(9)
# give an older tid than the PMN known, must abort # give an older tid than the PMN known, must abort
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address) conn = self.getFakeConnection(client_uuid, self.client_address)
oid_list = [] oid_list = []
upper, lower = unpack('!LL', self.app.ltid) upper, lower = unpack('!LL', self.app.ltid)
...@@ -216,7 +215,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -216,7 +215,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.app.pt.dropNode(old_node) self.app.pt.dropNode(old_node)
# do the right job # do the right job
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
storage_uuid = self.identifyToMasterNode() storage_uuid = self.identifyToMasterNode()
storage_conn = self.getFakeConnection(storage_uuid, self.storage_address) storage_conn = self.getFakeConnection(storage_uuid, self.storage_address)
self.assertNotEquals(uuid, client_uuid) self.assertNotEquals(uuid, client_uuid)
...@@ -242,7 +241,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -242,7 +241,7 @@ class MasterClientHandlerTests(NeoTestBase):
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=ABORT_TRANSACTION) packet = Packet(msg_type=ABORT_TRANSACTION)
# give a bad tid, must not failed, just ignored it # give a bad tid, must not failed, just ignored it
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
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.handleAbortTransaction(conn, packet, None) service.handleAbortTransaction(conn, packet, None)
...@@ -284,7 +283,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -284,7 +283,7 @@ class MasterClientHandlerTests(NeoTestBase):
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 0) self.assertEqual(len(tid_list), 0)
# create some transaction # create some transaction
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, 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)
service.handleAskBeginTransaction(conn, packet, None) service.handleAskBeginTransaction(conn, packet, None)
...@@ -321,7 +320,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -321,7 +320,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE)
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=CLIENT_NODE_TYPE, 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)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -362,7 +361,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -362,7 +361,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
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=CLIENT_NODE_TYPE, 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)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -403,7 +402,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -403,7 +402,7 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
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=CLIENT_NODE_TYPE, 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)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
......
...@@ -22,7 +22,7 @@ from mock import Mock ...@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, 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.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -43,7 +43,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -43,7 +43,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \ PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \ INTERNAL_ERROR_CODE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -294,7 +293,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -294,7 +293,7 @@ class MasterServerElectionTests(NeoTestBase):
ClientConnection._addPacket = self._addPacket ClientConnection._addPacket = self._addPacket
ClientConnection.expectMessage = self.expectMessage ClientConnection.expectMessage = self.expectMessage
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -366,7 +365,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -366,7 +365,7 @@ class MasterServerElectionTests(NeoTestBase):
def test_07_packetReceived(self): def test_07_packetReceived(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
p = protocol.acceptNodeIdentification(MASTER_NODE_TYPE, uuid, p = protocol.acceptNodeIdentification(NodeTypes.MASTER, uuid,
("127.0.0.1", self.master_port), 1009, 2, self.app.uuid) ("127.0.0.1", self.master_port), 1009, 2, self.app.uuid)
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
...@@ -386,7 +385,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -386,7 +385,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
args = (MASTER_NODE_TYPE, uuid, ('127.0.0.1', self.master_port), args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.master_port),
self.app.pt.getPartitions(), self.app.pt.getReplicas(), self.app.uuid) self.app.pt.getPartitions(), self.app.pt.getReplicas(), self.app.uuid)
p = protocol.acceptNodeIdentification(*args) p = protocol.acceptNodeIdentification(*args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -394,7 +393,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -394,7 +393,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, STORAGE_NODE_TYPE, self.election.handleAcceptNodeIdentification(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(),
...@@ -409,7 +408,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -409,7 +408,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
args = (MASTER_NODE_TYPE, uuid, ('127.0.0.1', self.master_port), args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.master_port),
self.app.pt.getPartitions(), self.app.pt.getReplicas(), self.app.uuid) self.app.pt.getPartitions(), self.app.pt.getReplicas(), self.app.uuid)
p = protocol.acceptNodeIdentification(*args) p = protocol.acceptNodeIdentification(*args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -417,7 +416,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -417,7 +416,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getUUID(), None)
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, STORAGE_NODE_TYPE, self.election.handleAcceptNodeIdentification(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(),
...@@ -429,7 +428,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -429,7 +428,7 @@ class MasterServerElectionTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
args = (MASTER_NODE_TYPE, uuid, ('127.0.0.1', self.master_port), args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.master_port),
self.app.pt.getPartitions(), self.app.pt.getReplicas(), self.app.uuid) self.app.pt.getPartitions(), self.app.pt.getReplicas(), self.app.uuid)
p = protocol.acceptNodeIdentification(*args) p = protocol.acceptNodeIdentification(*args)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
...@@ -438,7 +437,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -438,7 +437,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(conn.getUUID(), None) self.assertEqual(conn.getUUID(), None)
self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1) self.assertEqual(len(conn.getConnector().mockGetNamedCalls("_addPacket")),1)
self.election.handleAcceptNodeIdentification(conn, p, MASTER_NODE_TYPE, self.election.handleAcceptNodeIdentification(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(),
...@@ -452,7 +451,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -452,7 +451,7 @@ class MasterServerElectionTests(NeoTestBase):
def test_10_handleRequestNodeIdentification(self): def test_10_handleRequestNodeIdentification(self):
election = self.election election = self.election
uuid = self.getNewUUID() uuid = self.getNewUUID()
args = (MASTER_NODE_TYPE, uuid, ('127.0.0.1', self.storage_port), args = (NodeTypes.MASTER, uuid, ('127.0.0.1', self.storage_port),
'INVALID_NAME') 'INVALID_NAME')
packet = protocol.requestNodeIdentification(*args) packet = protocol.requestNodeIdentification(*args)
# test alien cluster # test alien cluster
...@@ -462,7 +461,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -462,7 +461,7 @@ class MasterServerElectionTests(NeoTestBase):
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
conn, conn,
packet=packet, packet=packet,
node_type=MASTER_NODE_TYPE, node_type=NodeTypes.MASTER,
uuid=uuid, uuid=uuid,
address=('127.0.0.1', self.storage_port), address=('127.0.0.1', self.storage_port),
name="INVALID_NAME",) name="INVALID_NAME",)
...@@ -473,7 +472,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -473,7 +472,7 @@ class MasterServerElectionTests(NeoTestBase):
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
conn, conn,
packet=packet, packet=packet,
node_type=STORAGE_NODE_TYPE, node_type=NodeTypes.STORAGE,
uuid=uuid, uuid=uuid,
address=('127.0.0.1', self.storage_port), address=('127.0.0.1', self.storage_port),
name=self.app.name,) name=self.app.name,)
...@@ -487,7 +486,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -487,7 +486,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
election.handleRequestNodeIdentification(conn, election.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
node_type=MASTER_NODE_TYPE, node_type=NodeTypes.MASTER,
uuid=uuid, uuid=uuid,
address=('127.0.0.1', self.master_port), address=('127.0.0.1', self.master_port),
name=self.app.name,) name=self.app.name,)
...@@ -504,7 +503,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -504,7 +503,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
election.handleRequestNodeIdentification(conn, election.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
node_type=MASTER_NODE_TYPE, node_type=NodeTypes.MASTER,
uuid=new_uuid, uuid=new_uuid,
address=('127.0.0.1', address=('127.0.0.1',
self.master_port+1), self.master_port+1),
...@@ -525,7 +524,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -525,7 +524,7 @@ class MasterServerElectionTests(NeoTestBase):
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
conn, conn,
packet=packet, packet=packet,
node_type=MASTER_NODE_TYPE, node_type=NodeTypes.MASTER,
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,
...@@ -586,7 +585,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -586,7 +585,7 @@ class MasterServerElectionTests(NeoTestBase):
# 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 = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port - 1), self.app.uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port - 1), self.app.uuid, DOWN_STATE),]
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))
self.assertEqual(node, None) self.assertEqual(node, None)
election.handleNotifyNodeInformation(conn, packet, node_list) election.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -595,21 +594,21 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -595,21 +594,21 @@ class MasterServerElectionTests(NeoTestBase):
# 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 = [(STORAGE_NODE_TYPE, ('127.0.0.1', self.master_port - 1), self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.master_port - 1), self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
election.handleNotifyNodeInformation(conn, packet, node_list) election.handleNotifyNodeInformation(conn, packet, node_list)
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 = [(CLIENT_NODE_TYPE, ('127.0.0.1', self.master_port - 1), self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.master_port - 1), self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getNodeList()), 0) self.assertEqual(len(self.app.nm.getNodeList()), 0)
election.handleNotifyNodeInformation(conn, packet, node_list) election.handleNotifyNodeInformation(conn, packet, node_list)
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 = [(MASTER_NODE_TYPE, ('127.0.0.1', self.master_port + 1), self.getNewUUID(), RUNNING_STATE),] node_list = [(NodeTypes.MASTER, ('127.0.0.1', self.master_port + 1), self.getNewUUID(), RUNNING_STATE),]
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))
self.assertEqual(node, None) self.assertEqual(node, None)
election.handleNotifyNodeInformation(conn, packet, node_list) election.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -618,7 +617,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -618,7 +617,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(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
# tell that node is down # tell that node is down
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port + 1, self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port + 1, self.getNewUUID(), DOWN_STATE),]
election.handleNotifyNodeInformation(conn, packet, node_list) election.handleNotifyNodeInformation(conn, packet, node_list)
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))
self.assertNotEqual(node, None) self.assertNotEqual(node, None)
......
...@@ -22,7 +22,7 @@ from mock import Mock ...@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
from neo.master.handlers.recovery import RecoveryHandler from neo.master.handlers.recovery import RecoveryHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -43,7 +43,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -43,7 +43,6 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ NOT_READY_CODE, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \ PROTOCOL_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, \ INTERNAL_ERROR_CODE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -81,7 +80,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -81,7 +80,7 @@ class MasterRecoveryTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -90,14 +89,14 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -90,14 +89,14 @@ class MasterRecoveryTests(NeoTestBase):
# Tests # Tests
def test_01_connectionClosed(self): def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, 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(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.connectionClosed(conn) self.recovery.connectionClosed(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, 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(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.timeoutExpired(conn) self.recovery.timeoutExpired(conn)
...@@ -105,7 +104,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -105,7 +104,7 @@ class MasterRecoveryTests(NeoTestBase):
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, 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(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.recovery.peerBroken(conn) self.recovery.peerBroken(conn)
...@@ -113,18 +112,18 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -113,18 +112,18 @@ class MasterRecoveryTests(NeoTestBase):
def test_08_handleNotifyNodeInformation(self): def test_08_handleNotifyNodeInformation(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# tell about a client node, do nothing # tell about a client node, do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getList()), 0) self.assertEqual(len(self.app.nm.getList()), 0)
# tell the master node about itself, if running must do nothing # tell the master node about itself, if running must do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, RUNNING_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port-1, self.app.uuid, RUNNING_STATE),]
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))
self.assertEqual(node, None) self.assertEqual(node, None)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -132,21 +131,21 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -132,21 +131,21 @@ class MasterRecoveryTests(NeoTestBase):
# tell the master node about itself, if down must raise # tell the master node about itself, if down must raise
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port-1, self.app.uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port-1, self.app.uuid, DOWN_STATE),]
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))
self.assertEqual(node, None) self.assertEqual(node, None)
self.assertRaises(RuntimeError, recovery.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, recovery.handleNotifyNodeInformation, conn, packet, node_list)
# tell about an unknown storage node, do nothing # tell about an unknown storage node, do nothing
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.master_port - 1, self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.master_port - 1, self.getNewUUID(), DOWN_STATE),]
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
self.assertEqual(len(self.app.nm.getStorageList()), 0) self.assertEqual(len(self.app.nm.getStorageList()), 0)
# tell about a known node but different address # tell about a known node but different address
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.2', self.master_port, uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.2', self.master_port, uuid, DOWN_STATE),]
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(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -155,7 +154,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -155,7 +154,7 @@ class MasterRecoveryTests(NeoTestBase):
# tell about a known node # tell about a known node
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, uuid, DOWN_STATE),]
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(), RUNNING_STATE) self.assertEqual(node.getState(), RUNNING_STATE)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -192,10 +191,10 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -192,10 +191,10 @@ class MasterRecoveryTests(NeoTestBase):
def test_10_handleAnswerPartitionTable(self): def test_10_handleAnswerPartitionTable(self):
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(MASTER_NODE_TYPE, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
packet = Packet(msg_type=ANSWER_PARTITION_TABLE) packet = Packet(msg_type=ANSWER_PARTITION_TABLE)
# not from target node, ignore # not from target node, ignore
uuid = self.identifyToMasterNode(STORAGE_NODE_TYPE, port=self.storage_port) uuid = self.identifyToMasterNode(NodeTypes.STORAGE, port=self.storage_port)
conn = self.getFakeConnection(uuid, self.storage_port) conn = self.getFakeConnection(uuid, self.storage_port)
self.assertNotEquals(self.app.target_uuid, uuid) self.assertNotEquals(self.app.target_uuid, uuid)
offset = 1 offset = 1
......
...@@ -23,7 +23,7 @@ from struct import pack, unpack ...@@ -23,7 +23,7 @@ from struct import pack, unpack
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
import neo.master import neo.master
from neo import protocol from neo import protocol
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
from neo.master.handlers.storage import StorageServiceHandler from neo.master.handlers.storage import StorageServiceHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
...@@ -31,7 +31,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \ ...@@ -31,7 +31,6 @@ from neo.protocol import ERROR, PING, PONG, ANNOUNCE_PRIMARY_MASTER, \
ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \ ASK_LAST_IDS, ANSWER_LAST_IDS, NOTIFY_PARTITION_CHANGES, \
ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \ ASK_UNFINISHED_TRANSACTIONS, ASK_BEGIN_TRANSACTION, FINISH_TRANSACTION, \
NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \ NOTIFY_INFORMATION_LOCKED, ASK_NEW_OIDS, ABORT_TRANSACTION, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure from neo.exception import OperationFailure, ElectionFailure
...@@ -64,7 +63,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -64,7 +63,7 @@ class MasterStorageHandlerTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -78,24 +77,24 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -78,24 +77,24 @@ class MasterStorageHandlerTests(NeoTestBase):
packet = Packet(msg_type=NOTIFY_NODE_INFORMATION) packet = Packet(msg_type=NOTIFY_NODE_INFORMATION)
# tell the master node that is not running any longer, it must raises # tell the master node that is not running any longer, it must raises
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, self.app.uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, self.app.uuid, DOWN_STATE),]
self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list) self.assertRaises(RuntimeError, service.handleNotifyNodeInformation, conn, packet, node_list)
# tell the master node that it's running, nothing change # tell the master node that it's running, nothing change
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(MASTER_NODE_TYPE, '127.0.0.1', self.master_port, self.app.uuid, RUNNING_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, self.app.uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about a client node, don't care # notify about a client node, don't care
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(CLIENT_NODE_TYPE, '127.0.0.1', self.client_port, new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify about an unknown node, don't care # notify about an unknown node, don't care
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11010, new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11010, new_uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -105,20 +104,20 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -105,20 +104,20 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid=self.getNewUUID(), uuid=self.getNewUUID(),
) )
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', 11012, uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11012, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is running, as PMN already know it, nothing is done # notify node is running, as PMN already know it, nothing is done
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, RUNNING_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, RUNNING_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
# notify node is temp down, must be taken into account # notify node is temp down, must be taken into account
ptid = self.app.pt.getID() ptid = self.app.pt.getID()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, TEMPORARILY_DOWN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, TEMPORARILY_DOWN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -127,7 +126,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -127,7 +126,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(ptid, self.app.pt.getID()) self.assertEquals(ptid, self.app.pt.getID())
# notify node is broken, must be taken into account and partition must changed # notify node is broken, must be taken into account and partition must changed
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
node_list = [(STORAGE_NODE_TYPE, '127.0.0.1', self.storage_port, uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, BROKEN_STATE),]
service.handleNotifyNodeInformation(conn, packet, node_list) service.handleNotifyNodeInformation(conn, packet, node_list)
for call in conn.mockGetAllCalls(): for call in conn.mockGetAllCalls():
self.assertEquals(call.getName(), "getUUID") self.assertEquals(call.getName(), "getUUID")
...@@ -169,7 +168,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -169,7 +168,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.app.pt.dropNode(old_node) self.app.pt.dropNode(old_node)
# do the right job # do the right job
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, port=self.client_port) client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, port=self.client_port)
storage_uuid_1 = self.identifyToMasterNode() storage_uuid_1 = self.identifyToMasterNode()
storage_uuid_2 = self.identifyToMasterNode(port=10022) storage_uuid_2 = self.identifyToMasterNode(port=10022)
storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port)) storage_conn_1 = self.getFakeConnection(storage_uuid_1, ("127.0.0.1", self.storage_port))
...@@ -224,7 +223,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -224,7 +223,7 @@ class MasterStorageHandlerTests(NeoTestBase):
tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0] tid_list = protocol._decodeAnswerUnfinishedTransactions(packet._body)[0]
self.assertEqual(len(tid_list), 0) self.assertEqual(len(tid_list), 0)
# create some transaction # create some transaction
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, 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)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
...@@ -242,7 +241,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -242,7 +241,7 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES) packet = Packet(msg_type=NOTIFY_PARTITION_CHANGES)
# do not answer if not a storage node # do not answer if not a storage node
client_uuid = self.identifyToMasterNode(node_type=CLIENT_NODE_TYPE, 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.handleNotifyPartitionChanges, self.checkUnexpectedPacketRaised(service.handleNotifyPartitionChanges,
...@@ -330,7 +329,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -330,7 +329,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE)
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=CLIENT_NODE_TYPE, 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)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -376,7 +375,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -376,7 +375,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
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=CLIENT_NODE_TYPE, 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)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
...@@ -422,7 +421,7 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -422,7 +421,7 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE)
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=CLIENT_NODE_TYPE, 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)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
......
...@@ -22,7 +22,7 @@ from mock import Mock ...@@ -22,7 +22,7 @@ from mock import Mock
from struct import pack, unpack from struct import pack, unpack
import neo import neo
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import Packet, INVALID_UUID from neo.protocol import Packet, NodeTypes, INVALID_UUID
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 import protocol from neo import protocol
...@@ -30,7 +30,6 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \ ...@@ -30,7 +30,6 @@ from neo.protocol import ERROR, ANNOUNCE_PRIMARY_MASTER, \
NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \ NOTIFY_NODE_INFORMATION, ANSWER_LAST_IDS, ANSWER_PARTITION_TABLE, \
ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \ ANSWER_UNFINISHED_TRANSACTIONS, ANSWER_OBJECT_PRESENT, \
ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \ ANSWER_TRANSACTION_INFORMATION, OID_NOT_FOUND_CODE, TID_NOT_FOUND_CODE, \
STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, DISCARDED_STATE
from neo.exception import OperationFailure, ElectionFailure, VerificationFailure from neo.exception import OperationFailure, ElectionFailure, VerificationFailure
...@@ -73,7 +72,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -73,7 +72,7 @@ class MasterVerificationTests(NeoTestBase):
def getLastUUID(self): def getLastUUID(self):
return self.uuid return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=NodeTypes.STORAGE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
""" """
...@@ -87,7 +86,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -87,7 +86,7 @@ class MasterVerificationTests(NeoTestBase):
# Tests # Tests
def test_01_connectionClosed(self): def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, 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(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.connectionClosed(conn) self.verification.connectionClosed(conn)
...@@ -100,7 +99,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -100,7 +99,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, 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(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.timeoutExpired(conn) self.verification.timeoutExpired(conn)
...@@ -113,7 +112,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -113,7 +112,7 @@ class MasterVerificationTests(NeoTestBase):
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE)
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=MASTER_NODE_TYPE, 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(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE)
self.verification.peerBroken(conn) self.verification.peerBroken(conn)
......
...@@ -24,7 +24,6 @@ from neo import protocol ...@@ -24,7 +24,6 @@ from neo import protocol
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.storage.handlers.verification import VerificationHandler from neo.storage.handlers.verification import VerificationHandler
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \ from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
...@@ -33,7 +32,7 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION ...@@ -33,7 +32,7 @@ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION
UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \ UNLOCK_INFORMATION, TID_NOT_FOUND_CODE, ASK_TRANSACTION_INFORMATION, \
COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE COMMIT_TRANSACTION, ASK_UNFINISHED_TRANSACTIONS, SEND_PARTITION_TABLE
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
from neo.protocol import ANSWER_PRIMARY_MASTER from neo.protocol import ANSWER_PRIMARY_MASTER, NodeTypes
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64 from neo.storage.mysqldb import MySQLDatabaseManager, p64, u64
......
...@@ -24,7 +24,7 @@ from neo.pt import PartitionTable ...@@ -24,7 +24,7 @@ from neo.pt import PartitionTable
from neo.storage.app import Application from neo.storage.app import Application
from neo.bootstrap import BootstrapManager from neo.bootstrap import BootstrapManager
from neo import protocol from neo import protocol
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE from neo.protocol import NodeTypes
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION
from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER from neo.protocol import ERROR, BROKEN_NODE_DISALLOWED_CODE, ASK_PRIMARY_MASTER
...@@ -39,7 +39,7 @@ class BootstrapManagerTests(NeoTestBase): ...@@ -39,7 +39,7 @@ class BootstrapManagerTests(NeoTestBase):
self.app = Application(**config) self.app = Application(**config)
for address in self.app.master_node_list: for address in self.app.master_node_list:
self.app.nm.createMaster(address=address) self.app.nm.createMaster(address=address)
self.bootstrap = BootstrapManager(self.app, 'main', protocol.STORAGE_NODE_TYPE) self.bootstrap = BootstrapManager(self.app, 'main', NodeTypes.STORAGE)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.master_port = 10010 self.master_port = 10010
self.storage_port = 10020 self.storage_port = 10020
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID DOWN_STATE, BROKEN_STATE, INVALID_UUID
from time import time from time import time
from neo.connection import BaseConnection, ListeningConnection, Connection, \ from neo.connection import BaseConnection, ListeningConnection, Connection, \
ClientConnection, ServerConnection, MTClientConnection, MTServerConnection ClientConnection, ServerConnection, MTClientConnection, MTServerConnection
......
...@@ -19,8 +19,7 @@ import unittest, os ...@@ -19,8 +19,7 @@ import unittest, os
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import UnexpectedPacketError, MASTER_NODE_TYPE, \ from neo.protocol import UnexpectedPacketError
CLIENT_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE
from neo.protocol import PacketMalformedError, UnexpectedPacketError, \ from neo.protocol import PacketMalformedError, UnexpectedPacketError, \
BrokenNodeDisallowedError, NotReadyError, ProtocolError BrokenNodeDisallowedError, NotReadyError, ProtocolError
......
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
import unittest import unittest
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import RUNNING_STATE, DOWN_STATE, \ from neo.protocol import RUNNING_STATE, DOWN_STATE, UNKNOWN_STATE
UNKNOWN_STATE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \ from neo.protocol import NodeTypes
CLIENT_NODE_TYPE, ADMIN_NODE_TYPE
from neo.node import Node, MasterNode, StorageNode, ClientNode, AdminNode, \ from neo.node import Node, MasterNode, StorageNode, ClientNode, AdminNode, \
NodeManager NodeManager
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
...@@ -90,7 +89,7 @@ class NodesTests(NeoTestBase): ...@@ -90,7 +89,7 @@ class NodesTests(NeoTestBase):
def testMaster(self): def testMaster(self):
""" Check Master sub class """ """ Check Master sub class """
node = MasterNode(self.manager) node = MasterNode(self.manager)
self.assertEqual(node.getType(), protocol.MASTER_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.MASTER)
self.assertTrue(node.isMaster()) self.assertTrue(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
self.assertFalse(node.isClient()) self.assertFalse(node.isClient())
...@@ -99,7 +98,7 @@ class NodesTests(NeoTestBase): ...@@ -99,7 +98,7 @@ class NodesTests(NeoTestBase):
def testStorage(self): def testStorage(self):
""" Check Storage sub class """ """ Check Storage sub class """
node = StorageNode(self.manager) node = StorageNode(self.manager)
self.assertEqual(node.getType(), protocol.STORAGE_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.STORAGE)
self.assertTrue(node.isStorage()) self.assertTrue(node.isStorage())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
self.assertFalse(node.isClient()) self.assertFalse(node.isClient())
...@@ -108,7 +107,7 @@ class NodesTests(NeoTestBase): ...@@ -108,7 +107,7 @@ class NodesTests(NeoTestBase):
def testClient(self): def testClient(self):
""" Check Client sub class """ """ Check Client sub class """
node = ClientNode(self.manager) node = ClientNode(self.manager)
self.assertEqual(node.getType(), protocol.CLIENT_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.CLIENT)
self.assertTrue(node.isClient()) self.assertTrue(node.isClient())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
...@@ -117,7 +116,7 @@ class NodesTests(NeoTestBase): ...@@ -117,7 +116,7 @@ class NodesTests(NeoTestBase):
def testAdmin(self): def testAdmin(self):
""" Check Admin sub class """ """ Check Admin sub class """
node = AdminNode(self.manager) node = AdminNode(self.manager)
self.assertEqual(node.getType(), protocol.ADMIN_NODE_TYPE) self.assertEqual(node.getType(), protocol.NodeTypes.ADMIN)
self.assertTrue(node.isAdmin()) self.assertTrue(node.isAdmin())
self.assertFalse(node.isMaster()) self.assertFalse(node.isMaster())
self.assertFalse(node.isStorage()) self.assertFalse(node.isStorage())
...@@ -249,10 +248,10 @@ class NodeManagerTests(NeoTestBase): ...@@ -249,10 +248,10 @@ class NodeManagerTests(NeoTestBase):
new_address = ('127.0.0.1', 2001) new_address = ('127.0.0.1', 2001)
new_uuid = self.getNewUUID() new_uuid = self.getNewUUID()
node_list = ( node_list = (
(CLIENT_NODE_TYPE, None, self.client.getUUID(), DOWN_STATE), (NodeTypes.CLIENT, None, self.client.getUUID(), DOWN_STATE),
(MASTER_NODE_TYPE, new_address, self.master.getUUID(), RUNNING_STATE), (NodeTypes.MASTER, new_address, self.master.getUUID(), RUNNING_STATE),
(STORAGE_NODE_TYPE, self.storage.getAddress(), new_uuid, RUNNING_STATE), (NodeTypes.STORAGE, self.storage.getAddress(), new_uuid, RUNNING_STATE),
(ADMIN_NODE_TYPE, self.admin.getAddress(), self.admin.getUUID(), UNKNOWN_STATE), (NodeTypes.ADMIN, self.admin.getAddress(), self.admin.getUUID(), UNKNOWN_STATE),
) )
# update manager content # update manager content
manager.update(node_list) manager.update(node_list)
......
...@@ -19,6 +19,7 @@ import unittest, os ...@@ -19,6 +19,7 @@ import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.protocol import NodeTypes
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.util import getNextTID from neo.util import getNextTID
from time import time, gmtime from time import time, gmtime
...@@ -91,10 +92,10 @@ class ProtocolTests(NeoTestBase): ...@@ -91,10 +92,10 @@ class ProtocolTests(NeoTestBase):
def test_11_requestNodeIdentification(self): def test_11_requestNodeIdentification(self):
uuid = self.getNewUUID() uuid = self.getNewUUID()
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, uuid, p = protocol.requestNodeIdentification(NodeTypes.CLIENT, uuid,
("127.0.0.1", 9080), "unittest") ("127.0.0.1", 9080), "unittest")
node, p_uuid, (ip, port), name = p.decode() node, p_uuid, (ip, port), name = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE) self.assertEqual(node, NodeTypes.CLIENT)
self.assertEqual(p_uuid, uuid) self.assertEqual(p_uuid, uuid)
self.assertEqual(ip, "127.0.0.1") self.assertEqual(ip, "127.0.0.1")
self.assertEqual(port, 9080) self.assertEqual(port, 9080)
...@@ -102,10 +103,10 @@ class ProtocolTests(NeoTestBase): ...@@ -102,10 +103,10 @@ class ProtocolTests(NeoTestBase):
def test_12_acceptNodeIdentification(self): def test_12_acceptNodeIdentification(self):
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID() uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
p = protocol.acceptNodeIdentification(CLIENT_NODE_TYPE, uuid1, p = protocol.acceptNodeIdentification(NodeTypes.CLIENT, uuid1,
("127.0.0.1", 9080), 10, 20, uuid2) ("127.0.0.1", 9080), 10, 20, uuid2)
node, p_uuid, (ip, port), nb_partitions, nb_replicas, your_uuid = p.decode() node, p_uuid, (ip, port), nb_partitions, nb_replicas, your_uuid = p.decode()
self.assertEqual(node, CLIENT_NODE_TYPE) self.assertEqual(node, NodeTypes.CLIENT)
self.assertEqual(p_uuid, uuid1) self.assertEqual(p_uuid, uuid1)
self.assertEqual(ip, "127.0.0.1") self.assertEqual(ip, "127.0.0.1")
self.assertEqual(port, 9080) self.assertEqual(port, 9080)
...@@ -143,9 +144,9 @@ class ProtocolTests(NeoTestBase): ...@@ -143,9 +144,9 @@ class ProtocolTests(NeoTestBase):
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
uuid3 = self.getNewUUID() uuid3 = self.getNewUUID()
node_list = [(CLIENT_NODE_TYPE, ("127.0.0.1", 1), uuid1, RUNNING_STATE), node_list = [(NodeTypes.CLIENT, ("127.0.0.1", 1), uuid1, RUNNING_STATE),
(CLIENT_NODE_TYPE, ("127.0.0.2", 2), uuid2, DOWN_STATE), (NodeTypes.CLIENT, ("127.0.0.2", 2), uuid2, DOWN_STATE),
(CLIENT_NODE_TYPE, ("127.0.0.3", 3), uuid3, BROKEN_STATE)] (NodeTypes.CLIENT, ("127.0.0.3", 3), uuid3, BROKEN_STATE)]
p = protocol.notifyNodeInformation(node_list) p = protocol.notifyNodeInformation(node_list)
p_node_list = p.decode()[0] p_node_list = p.decode()[0]
self.assertEqual(node_list, p_node_list) self.assertEqual(node_list, p_node_list)
......
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