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