Commit 6d746894 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use new Enum class for Node States and remove unused imports.


git-svn-id: https://svn.erp5.org/repos/neo/trunk@1338 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 01fab3d2
...@@ -32,3 +32,5 @@ def setupLog(name='NEO', filename=None, verbose=False): ...@@ -32,3 +32,5 @@ def setupLog(name='NEO', filename=None, verbose=False):
format = PREFIX + SUFFIX format = PREFIX + SUFFIX
logging_std.basicConfig(filename=filename, level=level, format=format) logging_std.basicConfig(filename=filename, level=level, format=format)
logging = logging_std.getLogger(name.upper()) logging = logging_std.getLogger(name.upper())
from neo import protocol
...@@ -28,7 +28,7 @@ from neo.bootstrap import BootstrapManager ...@@ -28,7 +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 from neo.protocol import NodeTypes, NodeStates
class Dispatcher: class Dispatcher:
"""Dispatcher use to redirect master request to handler""" """Dispatcher use to redirect master request to handler"""
...@@ -129,7 +129,7 @@ class Application(object): ...@@ -129,7 +129,7 @@ class Application(object):
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
nm.update([(node.getType(), node.getAddress(), node.getUUID(), nm.update([(node.getType(), node.getAddress(), node.getUUID(),
protocol.RUNNING_STATE)]) NodeStates.RUNNING)])
self.master_node = node self.master_node = node
self.master_conn = conn self.master_conn = conn
self.uuid = uuid self.uuid = uuid
......
...@@ -19,8 +19,7 @@ from neo import logging ...@@ -19,8 +19,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.protocol import NodeTypes, NodeStates
from neo.protocol import NodeTypes
from neo.util import dump from neo.util import dump
class PrimaryBootstrapHandler(AnswerBaseHandler): class PrimaryBootstrapHandler(AnswerBaseHandler):
...@@ -165,7 +164,7 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -165,7 +164,7 @@ class PrimaryNotificationsHandler(BaseHandler):
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 != NodeTypes.STORAGE \ if node_type != NodeTypes.STORAGE \
or state != protocol.RUNNING_STATE: or state != NodeStates.RUNNING:
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)
......
...@@ -19,7 +19,6 @@ from neo import logging ...@@ -19,7 +19,6 @@ from neo import logging
from ZODB.TimeStamp import TimeStamp 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.protocol import NodeTypes from neo.protocol import NodeTypes
class StorageEventHandler(BaseHandler): class StorageEventHandler(BaseHandler):
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import NodeStates
from neo.protocol import PacketMalformedError, UnexpectedPacketError, \ from neo.protocol import PacketMalformedError, UnexpectedPacketError, \
BrokenNodeDisallowedError, NotReadyError, ProtocolError BrokenNodeDisallowedError, NotReadyError, ProtocolError
from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -141,17 +142,17 @@ class EventHandler(object): ...@@ -141,17 +142,17 @@ class EventHandler(object):
def timeoutExpired(self, conn): def timeoutExpired(self, conn):
"""Called when a timeout event occurs.""" """Called when a timeout event occurs."""
logging.debug('timeout expired for %s:%d', *(conn.getAddress())) logging.debug('timeout expired for %s:%d', *(conn.getAddress()))
self.connectionLost(conn, protocol.TEMPORARILY_DOWN_STATE) self.connectionLost(conn, NodeStates.TEMPORARILY_DOWN)
def connectionClosed(self, conn): def connectionClosed(self, conn):
"""Called when a connection is closed by the peer.""" """Called when a connection is closed by the peer."""
logging.debug('connection closed for %s:%d', *(conn.getAddress())) logging.debug('connection closed for %s:%d', *(conn.getAddress()))
self.connectionLost(conn, protocol.TEMPORARILY_DOWN_STATE) self.connectionLost(conn, NodeStates.TEMPORARILY_DOWN)
def peerBroken(self, conn): def peerBroken(self, conn):
"""Called when a peer is broken.""" """Called when a peer is broken."""
logging.error('%s:%d is broken', *(conn.getAddress())) logging.error('%s:%d is broken', *(conn.getAddress()))
self.connectionLost(conn, protocol.BROKEN_STATE) self.connectionLost(conn, NodeStates.BROKEN)
def connectionLost(self, conn, new_state): def connectionLost(self, conn, new_state):
""" this is a method to override in sub-handlers when there is no need """ this is a method to override in sub-handlers when there is no need
......
...@@ -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, NodeTypes from neo.protocol import UUID_NAMESPACES, ClusterStates, NodeStates, 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
...@@ -724,7 +724,7 @@ class Application(object): ...@@ -724,7 +724,7 @@ class Application(object):
node = self.nm.getByUUID(c.getUUID()) node = self.nm.getByUUID(c.getUUID())
if node.isClient(): if node.isClient():
node_list = [(node.getType(), node.getAddress(), node_list = [(node.getType(), node.getAddress(),
node.getUUID(), protocol.DOWN_STATE)] node.getUUID(), NodeStates.DOWN)]
c.notify(protocol.notifyNodeInformation(node_list)) c.notify(protocol.notifyNodeInformation(node_list))
# then ask storages and master nodes to shutdown # then ask storages and master nodes to shutdown
logging.info("asking all remaining nodes to shutdown") logging.info("asking all remaining nodes to shutdown")
...@@ -732,13 +732,13 @@ class Application(object): ...@@ -732,13 +732,13 @@ class Application(object):
node = self.nm.getByUUID(c.getUUID()) node = self.nm.getByUUID(c.getUUID())
if node.isStorage() or node.isMaster(): if node.isStorage() or node.isMaster():
node_list = [(node.getType(), node.getAddress(), node_list = [(node.getType(), node.getAddress(),
node.getUUID(), protocol.DOWN_STATE)] node.getUUID(), NodeStates.DOWN)]
c.notify(protocol.notifyNodeInformation(node_list)) c.notify(protocol.notifyNodeInformation(node_list))
# then shutdown # then shutdown
sys.exit("Cluster has been asked to shut down") sys.exit("Cluster has been asked to shut down")
def identifyStorageNode(self, uuid, node): def identifyStorageNode(self, uuid, node):
state = protocol.RUNNING_STATE state = NodeStates.RUNNING
handler = None handler = None
if self.cluster_state == ClusterStates.RECOVERING: if self.cluster_state == ClusterStates.RECOVERING:
if uuid is None: if uuid is None:
...@@ -752,12 +752,12 @@ class Application(object): ...@@ -752,12 +752,12 @@ class Application(object):
# Here the uuid is not cleared to allow lookup pending nodes by # Here the uuid is not cleared to allow lookup pending nodes by
# uuid from the test framework. It's safe since nodes with a # uuid from the test framework. It's safe since nodes with a
# conflicting UUID are rejected in the identification handler. # conflicting UUID are rejected in the identification handler.
state = protocol.PENDING_STATE state = NodeStates.PENDING
handler = verification.VerificationHandler handler = verification.VerificationHandler
elif self.cluster_state == ClusterStates.RUNNING: elif self.cluster_state == ClusterStates.RUNNING:
if uuid is None or node is None: if uuid is None or node is None:
# same as for verification # same as for verification
state = protocol.PENDING_STATE state = NodeStates.PENDING
handler = storage.StorageServiceHandler handler = storage.StorageServiceHandler
elif self.cluster_state == ClusterStates.STOPPING: elif self.cluster_state == ClusterStates.STOPPING:
raise protocol.NotReadyError raise protocol.NotReadyError
...@@ -767,7 +767,7 @@ class Application(object): ...@@ -767,7 +767,7 @@ class Application(object):
def identifyNode(self, node_type, uuid, node): def identifyNode(self, node_type, uuid, node):
state = protocol.RUNNING_STATE state = NodeStates.RUNNING
handler = identification.IdentificationHandler handler = identification.IdentificationHandler
if node_type == NodeTypes.ADMIN: if node_type == NodeTypes.ADMIN:
......
...@@ -19,7 +19,7 @@ from neo import logging ...@@ -19,7 +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 from neo.protocol import NodeTypes, NodeStates
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."""
...@@ -72,7 +72,7 @@ class MasterHandler(EventHandler): ...@@ -72,7 +72,7 @@ class MasterHandler(EventHandler):
DISCONNECTED_STATE_DICT = { DISCONNECTED_STATE_DICT = {
NodeTypes.STORAGE: protocol.TEMPORARILY_DOWN_STATE, NodeTypes.STORAGE: NodeStates.TEMPORARILY_DOWN,
} }
class BaseServiceHandler(MasterHandler): class BaseServiceHandler(MasterHandler):
...@@ -86,11 +86,11 @@ class BaseServiceHandler(MasterHandler): ...@@ -86,11 +86,11 @@ class BaseServiceHandler(MasterHandler):
def connectionLost(self, conn, new_state): def connectionLost(self, conn, new_state):
node = self.app.nm.getByUUID(conn.getUUID()) node = self.app.nm.getByUUID(conn.getUUID())
assert node is not None assert node is not None
if new_state != protocol.BROKEN_STATE: if new_state != NodeStates.BROKEN:
new_state = DISCONNECTED_STATE_DICT.get(node.getType(), protocol.DOWN_STATE) new_state = DISCONNECTED_STATE_DICT.get(node.getType(), NodeStates.DOWN)
if node.getState() == new_state: if node.getState() == new_state:
return return
if new_state != protocol.BROKEN_STATE and node.isPending(): if new_state != NodeStates.BROKEN and node.isPending():
# was in pending state, so drop it from the node manager to forget # was in pending state, so drop it from the node manager to forget
# it and do not set in running state when it comes back # it and do not set in running state when it comes back
logging.info('drop a pending node from the node manager') logging.info('drop a pending node from the node manager')
......
...@@ -19,7 +19,7 @@ from neo import logging ...@@ -19,7 +19,7 @@ from neo import logging
from neo import protocol from neo import protocol
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.protocol import ClusterStates, RUNNING_STATE from neo.protocol import ClusterStates, NodeStates
from neo.util import dump from neo.util import dump
class AdministrationHandler(MasterHandler): class AdministrationHandler(MasterHandler):
...@@ -52,7 +52,7 @@ class AdministrationHandler(MasterHandler): ...@@ -52,7 +52,7 @@ class AdministrationHandler(MasterHandler):
if uuid == app.uuid: if uuid == app.uuid:
node.setState(state) node.setState(state)
# get message for self # get message for self
if state != RUNNING_STATE: if state != NodeStates.RUNNING:
p = protocol.noError('node state changed') p = protocol.noError('node state changed')
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
app.shutdown() app.shutdown()
...@@ -63,7 +63,7 @@ class AdministrationHandler(MasterHandler): ...@@ -63,7 +63,7 @@ class AdministrationHandler(MasterHandler):
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
return return
if state == protocol.RUNNING_STATE: if state == NodeStates.RUNNING:
# first make sure to have a connection to the node # first make sure to have a connection to the node
node_conn = None node_conn = None
for node_conn in app.em.getConnectionList(): for node_conn in app.em.getConnectionList():
...@@ -73,7 +73,7 @@ class AdministrationHandler(MasterHandler): ...@@ -73,7 +73,7 @@ class AdministrationHandler(MasterHandler):
# no connection to the node # no connection to the node
raise protocol.ProtocolError('no connection to the node') raise protocol.ProtocolError('no connection to the node')
elif state == protocol.DOWN_STATE and node.isStorage(): elif state == NodeStates.DOWN and node.isStorage():
# modify the partition table if required # modify the partition table if required
cell_list = [] cell_list = []
if modify_partition_table: if modify_partition_table:
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from neo import logging from neo import logging
from neo import protocol from neo import protocol
from neo.protocol import HIDDEN_STATE from neo.protocol import NodeStates
from neo.master.handlers import BaseServiceHandler from neo.master.handlers import BaseServiceHandler
from neo.protocol import UnexpectedPacketError from neo.protocol import UnexpectedPacketError
from neo.util import dump, getNextTID from neo.util import dump, getNextTID
...@@ -113,7 +113,7 @@ class ClientServiceHandler(BaseServiceHandler): ...@@ -113,7 +113,7 @@ class ClientServiceHandler(BaseServiceHandler):
uuid_set = set() uuid_set = set()
for part in partition_set: for part in partition_set:
uuid_set.update((cell.getUUID() for cell in app.pt.getCellList(part) \ uuid_set.update((cell.getUUID() for cell in app.pt.getCellList(part) \
if cell.getNodeState() != HIDDEN_STATE)) if cell.getNodeState() != NodeStates.HIDDEN))
# Request locking data. # Request locking data.
# build a new set as we may not send the message to all nodes as some # build a new set as we may not send the message to all nodes as some
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +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.protocol import NodeTypes, NodeStates
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
...@@ -50,7 +50,7 @@ class ElectionHandler(MasterHandler): ...@@ -50,7 +50,7 @@ class ElectionHandler(MasterHandler):
if node.getUUID() is None: if node.getUUID() is None:
node.setUUID(uuid) node.setUUID(uuid)
if state in (node.getState(), protocol.RUNNING_STATE): if state in (node.getState(), NodeStates.RUNNING):
# No change. Don't care. # No change. Don't care.
continue continue
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,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.protocol import ClusterStates, NodeStates, NodeTypes
from neo.protocol import ClusterStates, NodeTypes
action_dict = { action_dict = {
'print': { 'print': {
...@@ -44,9 +43,7 @@ class TerminalNeoCTL(object): ...@@ -44,9 +43,7 @@ class TerminalNeoCTL(object):
# Utility methods (could be functions) # Utility methods (could be functions)
def asNodeState(self, value): def asNodeState(self, value):
if not value.endswith('_STATE'): return NodeStates.getByName(value.upper())
value += '_STATE'
return protocol.node_states.getFromStr(value)
def asNodeType(self, value): def asNodeType(self, value):
return NodeTypes.getByName(value.upper()) return NodeTypes.getByName(value.upper())
...@@ -197,7 +194,7 @@ class Application(object): ...@@ -197,7 +194,7 @@ class Application(object):
def execute(self, args): def execute(self, args):
"""Execute the command given.""" """Execute the command given."""
# print node type : print list of node of the given type (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...) # print node type : print list of node of the given type (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...)
# set node uuid state [1|0] : set the node for the given uuid to the state (RUNNING_STATE, DOWN_STATE...) # set node uuid state [1|0] : set the node for the given uuid to the state (RUNNING, DOWN...)
# and modify the partition if asked # and modify the partition if asked
# set cluster name [shutdown|operational] : either shutdown the cluster or mark it as operational # set cluster name [shutdown|operational] : either shutdown the cluster or mark it as operational
current_action = action_dict current_action = action_dict
......
...@@ -20,7 +20,7 @@ from neo.connection import ClientConnection ...@@ -20,7 +20,7 @@ from neo.connection import ClientConnection
from neo.event import EventManager from neo.event import EventManager
from neo.neoctl.handler import CommandEventHandler from neo.neoctl.handler import CommandEventHandler
from neo import protocol from neo import protocol
from neo.protocol import ClusterStates from neo.protocol import ClusterStates, NodeStates
class NotReadyException(Exception): class NotReadyException(Exception):
pass pass
...@@ -133,7 +133,7 @@ class NeoCTL(object): ...@@ -133,7 +133,7 @@ class NeoCTL(object):
""" """
Set node into "down" state and remove it from partition table. Set node into "down" state and remove it from partition table.
""" """
self.setNodeState(node, protocol.DOWN_STATE, update_partition_table=1) self.setNodeState(node, NodeStates.DOWN, update_partition_table=1)
def getPrimaryMaster(self): def getPrimaryMaster(self):
""" """
......
...@@ -18,15 +18,14 @@ ...@@ -18,15 +18,14 @@
from time import time from time import time
from neo import logging from neo import logging
from neo import protocol
from neo.util import dump from neo.util import dump
from neo.protocol import NodeTypes from neo.protocol import NodeTypes, NodeStates
class Node(object): class Node(object):
"""This class represents a node.""" """This class represents a node."""
def __init__(self, manager, address=None, uuid=None, def __init__(self, manager, address=None, uuid=None,
state=protocol.UNKNOWN_STATE): state=NodeStates.UNKNOWN):
self._state = state self._state = state
self._address = address self._address = address
self._uuid = uuid self._uuid = uuid
...@@ -89,42 +88,42 @@ class Node(object): ...@@ -89,42 +88,42 @@ class Node(object):
def isRunning(self): def isRunning(self):
# FIXME: is it like 'connected' ? # FIXME: is it like 'connected' ?
return self._state == protocol.RUNNING_STATE return self._state == NodeStates.RUNNING
def isTemporarilyDown(self): def isTemporarilyDown(self):
# FIXME: is it like 'unconnected' or UNKNOWN_STATE ? # FIXME: is it like 'unconnected' or UNKNOWN state ?
return self._state == protocol.TEMPORARILY_DOWN_STATE return self._state == NodeStates.TEMPORARILY_DOWN
def isDown(self): def isDown(self):
# FIXME: is it like 'unconnected' or 'forgotten' ? # FIXME: is it like 'unconnected' or 'forgotten' ?
return self._state == protocol.DOWN_STATE return self._state == NodeStates.DOWN
def isBroken(self): def isBroken(self):
return self._state == protocol.BROKEN_STATE return self._state == NodeStates.BROKEN
def isHidden(self): def isHidden(self):
return self._state == protocol.HIDDEN_STATE return self._state == NodeStates.HIDDEN
def isPending(self): def isPending(self):
return self._state == protocol.PENDING_STATE return self._state == NodeStates.PENDING
def setRunning(self): def setRunning(self):
self.setState(protocol.RUNNING_STATE) self.setState(NodeStates.RUNNING)
def setTemporarilyDown(self): def setTemporarilyDown(self):
self.setState(protocol.TEMPORARILY_DOWN_STATE) self.setState(NodeStates.TEMPORARILY_DOWN)
def setDown(self): def setDown(self):
self.setState(protocol.DOWN_STATE) self.setState(NodeStates.DOWN)
def setBroken(self): def setBroken(self):
self.setState(protocol.BROKEN_STATE) self.setState(NodeStates.BROKEN)
def setHidden(self): def setHidden(self):
self.setState(protocol.HIDDEN_STATE) self.setState(NodeStates.HIDDEN)
def setPending(self): def setPending(self):
self.setState(protocol.PENDING_STATE) self.setState(NodeStates.PENDING)
def asTuple(self): def asTuple(self):
""" Returned tuple is intented to be used in procotol encoders """ """ Returned tuple is intented to be used in procotol encoders """
...@@ -318,7 +317,7 @@ class NodeManager(object): ...@@ -318,7 +317,7 @@ class NodeManager(object):
node = node_by_uuid or node_by_addr node = node_by_uuid or node_by_addr
log_args = (node_type, dump(uuid), addr, state) log_args = (node_type, dump(uuid), addr, state)
if state == protocol.DOWN_STATE: if state == NodeStates.DOWN:
# drop down nodes # drop down nodes
logging.debug('drop node %s %s %s %s' % log_args) logging.debug('drop node %s %s %s %s' % log_args)
self.remove(node) self.remove(node)
......
...@@ -336,26 +336,27 @@ class NodeTypes(Enum): ...@@ -336,26 +336,27 @@ class NodeTypes(Enum):
NodeTypes = NodeTypes() NodeTypes = NodeTypes()
# Node states. class NodeStates(Enum):
node_states = OldEnum({
'RUNNING_STATE': 0, RUNNING = Enum.Item(1)
'TEMPORARILY_DOWN_STATE': 1, TEMPORARILY_DOWN = Enum.Item(2)
'DOWN_STATE': 2, DOWN = Enum.Item(3)
'BROKEN_STATE': 3, BROKEN = Enum.Item(4)
'HIDDEN_STATE' : 4, HIDDEN = Enum.Item(5)
'PENDING_STATE': 5, PENDING = Enum.Item(6)
'UNKNOWN_STATE': 6, UNKNOWN = Enum.Item(7)
})
NodeStates = NodeStates()
# used for logging # used for logging
node_state_prefix_dict = { node_state_prefix_dict = {
RUNNING_STATE: 'R', NodeStates.RUNNING: 'R',
TEMPORARILY_DOWN_STATE: 'T', NodeStates.TEMPORARILY_DOWN: 'T',
DOWN_STATE: 'D', NodeStates.DOWN: 'D',
BROKEN_STATE: 'B', NodeStates.BROKEN: 'B',
HIDDEN_STATE: 'H', NodeStates.HIDDEN: 'H',
PENDING_STATE: 'P', NodeStates.PENDING: 'P',
UNKNOWN_STATE: 'U', NodeStates.UNKNOWN: 'U',
} }
# Partition cell states. # Partition cell states.
...@@ -505,7 +506,7 @@ def _decodeClusterState(state): ...@@ -505,7 +506,7 @@ def _decodeClusterState(state):
return cluster_state return cluster_state
def _decodeNodeState(state): def _decodeNodeState(state):
node_state = node_states.get(state) node_state = NodeStates.get(state)
if node_state is None: if node_state is None:
raise PacketMalformedError('invalid node state %d' % state) raise PacketMalformedError('invalid node state %d' % state)
return node_state return node_state
......
...@@ -219,7 +219,7 @@ class PartitionTable(object): ...@@ -219,7 +219,7 @@ class PartitionTable(object):
DEBUG:root:pt: 00000000: .UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU. DEBUG:root:pt: 00000000: .UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.
DEBUG:root:pt: 00000009: U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U DEBUG:root:pt: 00000009: U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U
Here, there are 4 nodes in RUNNING_STATE. Here, there are 4 nodes in RUNNING state.
The first partition has 2 replicas in UP_TO_DATE_STATE, on nodes 1 and The first partition has 2 replicas in UP_TO_DATE_STATE, on nodes 1 and
2 (nodes 0 and 3 are displayed as unused for that partition by 2 (nodes 0 and 3 are displayed as unused for that partition by
displaying a dot). displaying a dot).
......
...@@ -19,10 +19,9 @@ from neo import logging ...@@ -19,10 +19,9 @@ 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, \
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
from neo.protocol import NodeStates
class BaseStorageHandler(EventHandler): class BaseStorageHandler(EventHandler):
"""This class implements a generic part of the event handlers.""" """This class implements a generic part of the event handlers."""
...@@ -52,11 +51,12 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -52,11 +51,12 @@ class BaseMasterHandler(BaseStorageHandler):
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
logging.info("I was told I'm %s" %(state)) logging.info("I was told I'm %s" %(state))
if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, BROKEN_STATE): if state in (NodeStates.DOWN, NodeStates.TEMPORARILY_DOWN,
NodeStates.BROKEN):
conn.close() conn.close()
erase = state == DOWN_STATE erase = state == NodeStates.DOWN
self.app.shutdown(erase=erase) self.app.shutdown(erase=erase)
elif state == HIDDEN_STATE: elif state == NodeStates.HIDDEN:
raise OperationFailure raise OperationFailure
......
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
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, DOWN_STATE, \ from neo.protocol import DISCARDED_STATE, OUT_OF_DATE_STATE
TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE from neo.protocol import NodeTypes, NodeStates
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."""
...@@ -38,9 +37,10 @@ class HiddenHandler(BaseMasterHandler): ...@@ -38,9 +37,10 @@ class HiddenHandler(BaseMasterHandler):
if node_type == NodeTypes.STORAGE: 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 (NodeStates.DOWN, NodeStates.TEMPORARILY_DOWN,
NodeStates.BROKEN):
conn.close() conn.close()
erase_db = state == DOWN_STATE erase_db = state == NodeStates.DOWN
self.app.shutdown(erase=erase_db) self.app.shutdown(erase=erase_db)
def handleRequestNodeIdentification(self, conn, packet, node_type, def handleRequestNodeIdentification(self, conn, packet, node_type,
......
...@@ -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 UP_TO_DATE_STATE, OUT_OF_DATE_STATE, RUNNING_STATE from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE
from neo.protocol import NodeTypes from neo.protocol import NodeTypes, NodeStates
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.util import dump from neo.util import dump
...@@ -155,7 +155,7 @@ class Replicator(object): ...@@ -155,7 +155,7 @@ class Replicator(object):
cell_list = app.pt.getCellList(self.current_partition.getRID(), cell_list = app.pt.getCellList(self.current_partition.getRID(),
readable=True) readable=True)
node_list = [cell.getNode() for cell in cell_list node_list = [cell.getNode() for cell in cell_list
if cell.getNodeState() == RUNNING_STATE] if cell.getNodeState() == NodeStates.RUNNING]
node = choice(node_list) node = choice(node_list)
except IndexError: except IndexError:
# Not operational. # Not operational.
......
...@@ -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 NodeTypes, INVALID_PTID, \ from neo.protocol import NodeTypes, NodeStates, INVALID_PTID, \
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
from neo.client.handlers.master import PrimaryBootstrapHandler from neo.client.handlers.master import PrimaryBootstrapHandler
...@@ -90,7 +89,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -90,7 +89,7 @@ class ClientHandlerTests(NeoTestBase):
#self.assertEquals(app.master_conn, None) #self.assertEquals(app.master_conn, None)
#self.assertEquals(app.primary_master_node, None) #self.assertEquals(app.primary_master_node, None)
def _testStorageWithMethod(self, method, handler_class, state=TEMPORARILY_DOWN_STATE): def _testStorageWithMethod(self, method, handler_class, state=NodeStates.TEMPORARILY_DOWN):
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()
...@@ -200,9 +199,9 @@ class ClientHandlerTests(NeoTestBase): ...@@ -200,9 +199,9 @@ class ClientHandlerTests(NeoTestBase):
def test_storagePeerBroken(self): def test_storagePeerBroken(self):
self._testStorageWithMethod(self._testPeerBroken, self._testStorageWithMethod(self._testPeerBroken,
StorageBootstrapHandler, state=BROKEN_STATE) StorageBootstrapHandler, state=NodeStates.BROKEN)
self._testStorageWithMethod(self._testPeerBroken, self._testStorageWithMethod(self._testPeerBroken,
StorageAnswersHandler, state=BROKEN_STATE) StorageAnswersHandler, state=NodeStates.BROKEN)
def test_notReady(self): def test_notReady(self):
app = Mock({'setNodeNotReady': None}) app = Mock({'setNodeNotReady': None})
...@@ -571,7 +570,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -571,7 +570,7 @@ class ClientHandlerTests(NeoTestBase):
# first notify unknown master nodes # first notify unknown master nodes
uuid = self.getNewUUID() uuid = self.getNewUUID()
test_node = (NodeTypes.MASTER, '127.0.0.1', 10010, uuid, test_node = (NodeTypes.MASTER, '127.0.0.1', 10010, uuid,
RUNNING_STATE) NodeStates.RUNNING)
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)
add_call_list = nm.mockGetNamedCalls('add') add_call_list = nm.mockGetNamedCalls('add')
...@@ -585,7 +584,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -585,7 +584,7 @@ class ClientHandlerTests(NeoTestBase):
node = Mock({}) node = Mock({})
uuid = self.getNewUUID() uuid = self.getNewUUID()
test_node = (NodeTypes.MASTER, '127.0.0.1', 10010, uuid, test_node = (NodeTypes.MASTER, '127.0.0.1', 10010, uuid,
RUNNING_STATE) NodeStates.RUNNING)
nm = self._testNotifyNodeInformation(test_node, getByAddress=node, nm = self._testNotifyNodeInformation(test_node, getByAddress=node,
getByUUID=node) getByUUID=node)
# Check that node got replaced # Check that node got replaced
...@@ -600,7 +599,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -600,7 +599,7 @@ class ClientHandlerTests(NeoTestBase):
def test_unknownStorageNotifyNodeInformation(self): def test_unknownStorageNotifyNodeInformation(self):
test_node = (NodeTypes.STORAGE, '127.0.0.1', 10010, self.getNewUUID(), test_node = (NodeTypes.STORAGE, '127.0.0.1', 10010, self.getNewUUID(),
RUNNING_STATE) NodeStates.RUNNING)
nm = self._testNotifyNodeInformation(test_node, getByUUID=None) nm = self._testNotifyNodeInformation(test_node, getByUUID=None)
# Check that node got added # Check that node got added
add_call_list = nm.mockGetNamedCalls('add') add_call_list = nm.mockGetNamedCalls('add')
...@@ -615,7 +614,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -615,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 = (NodeTypes.STORAGE, '127.0.0.1', 10010, self.getNewUUID(), test_node = (NodeTypes.STORAGE, '127.0.0.1', 10010, self.getNewUUID(),
RUNNING_STATE) NodeStates.RUNNING)
nm = self._testNotifyNodeInformation(test_node, getByUUID=node) nm = self._testNotifyNodeInformation(test_node, getByUUID=node)
# Check that node got replaced # Check that node got replaced
add_call_list = nm.mockGetNamedCalls('add') add_call_list = nm.mockGetNamedCalls('add')
...@@ -735,7 +734,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -735,7 +734,7 @@ class ClientHandlerTests(NeoTestBase):
setCell_call_list[0].checkArgs(test_cell_list[0][0], added_node, setCell_call_list[0].checkArgs(test_cell_list[0][0], added_node,
test_cell_list[0][2]) test_cell_list[0][2])
# TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN_STATE (implementation is unclear) # TODO: confirm condition under which an unknown node should be added with a TEMPORARILY_DOWN (implementation is unclear)
def test_knownNodeNotifyPartitionChanges(self): def test_knownNodeNotifyPartitionChanges(self):
test_ptid = 1 test_ptid = 1
...@@ -764,8 +763,8 @@ class ClientHandlerTests(NeoTestBase): ...@@ -764,8 +763,8 @@ class ClientHandlerTests(NeoTestBase):
self.assertEquals(calls[0].getParam(0).getUUID(), uuid2) self.assertEquals(calls[0].getParam(0).getUUID(), uuid2)
self.assertEquals(calls[1].getParam(0).getUUID(), uuid3) self.assertEquals(calls[1].getParam(0).getUUID(), uuid3)
self.assertEquals(calls[2].getParam(0).getUUID(), uuid4) self.assertEquals(calls[2].getParam(0).getUUID(), uuid4)
self.assertEquals(calls[0].getParam(0).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(calls[0].getParam(0).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(calls[1].getParam(0).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(calls[1].getParam(0).getState(), NodeStates.TEMPORARILY_DOWN)
# and the others are updated # and the others are updated
self.assertEqual(app.ptid, test_ptid + 1) self.assertEqual(app.ptid, test_ptid + 1)
calls = app.pt.mockGetNamedCalls('setCell') calls = app.pt.mockGetNamedCalls('setCell')
......
...@@ -20,6 +20,7 @@ import unittest ...@@ -20,6 +20,7 @@ import unittest
from neo.tests.functional import NEOCluster, NEOFunctionalTest from neo.tests.functional import NEOCluster, NEOFunctionalTest
from neo.neoctl.neoctl import NotReadyException from neo.neoctl.neoctl import NotReadyException
from neo import protocol from neo import protocol
from neo.protocol import NodeStates
from neo.util import dump from neo.util import dump
MASTER_NODE_COUNT = 3 MASTER_NODE_COUNT = 3
...@@ -62,7 +63,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -62,7 +63,7 @@ class MasterTests(NEOFunctionalTest):
self.assertEqual(len(killed_uuid_list), 1) self.assertEqual(len(killed_uuid_list), 1)
uuid = killed_uuid_list[0] uuid = killed_uuid_list[0]
# Check the state of the primary we just killed # Check the state of the primary we just killed
self.neo.expectMasterState(uuid, (None, protocol.UNKNOWN_STATE)) self.neo.expectMasterState(uuid, (None, NodeStates.UNKNOWN))
self.assertEqual(self.neo.getPrimaryMaster(), None) self.assertEqual(self.neo.getPrimaryMaster(), None)
# Check that a primary master arised. # Check that a primary master arised.
self.neo.expectPrimaryMaster(timeout=10) self.neo.expectPrimaryMaster(timeout=10)
...@@ -72,7 +73,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -72,7 +73,7 @@ class MasterTests(NEOFunctionalTest):
def testStoppingPrimaryMasterWithOneSecondary(self): def testStoppingPrimaryMasterWithOneSecondary(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT, self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=protocol.RUNNING_STATE) state=NodeStates.RUNNING)
# Kill one secondary master. # Kill one secondary master.
killed_uuid_list = self.neo.killSecondaryMaster() killed_uuid_list = self.neo.killSecondaryMaster()
...@@ -86,7 +87,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -86,7 +87,7 @@ class MasterTests(NEOFunctionalTest):
self.assertEqual(len(killed_uuid_list), 1) self.assertEqual(len(killed_uuid_list), 1)
uuid = killed_uuid_list[0] uuid = killed_uuid_list[0]
# Check the state of the primary we just killed # Check the state of the primary we just killed
self.neo.expectMasterState(uuid, (None, protocol.UNKNOWN_STATE)) self.neo.expectMasterState(uuid, (None, NodeStates.UNKNOWN))
self.assertEqual(self.neo.getPrimaryMaster(), None) self.assertEqual(self.neo.getPrimaryMaster(), None)
# Check that a primary master arised. # Check that a primary master arised.
self.neo.expectPrimaryMaster(timeout=10) self.neo.expectPrimaryMaster(timeout=10)
...@@ -96,7 +97,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -96,7 +97,7 @@ class MasterTests(NEOFunctionalTest):
def testMasterSequentialStart(self): def testMasterSequentialStart(self):
self.neo.expectAllMasters(MASTER_NODE_COUNT, self.neo.expectAllMasters(MASTER_NODE_COUNT,
state=protocol.RUNNING_STATE) state=NodeStates.RUNNING)
master_list = self.neo.getMasterProcessList() master_list = self.neo.getMasterProcessList()
# Stop the cluster (so we can start processes manually) # Stop the cluster (so we can start processes manually)
...@@ -110,7 +111,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -110,7 +111,7 @@ class MasterTests(NEOFunctionalTest):
self.neo.expectPrimaryMaster(first_master_uuid, timeout=30) self.neo.expectPrimaryMaster(first_master_uuid, timeout=30)
# Check that no other node is known as running. # Check that no other node is known as running.
self.assertEqual(len(self.neo.getMasterList( self.assertEqual(len(self.neo.getMasterList(
state=protocol.RUNNING_STATE)), 1) state=NodeStates.RUNNING)), 1)
# Start a second master. # Start a second master.
second_master = master_list[1] second_master = master_list[1]
...@@ -120,7 +121,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -120,7 +121,7 @@ class MasterTests(NEOFunctionalTest):
second_master.start() second_master.start()
# Check that the second master is running under his known UUID. # Check that the second master is running under his known UUID.
self.neo.expectMasterState(second_master.getUUID(), self.neo.expectMasterState(second_master.getUUID(),
protocol.RUNNING_STATE) NodeStates.RUNNING)
# Check that the primary master didn't change. # Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimaryMaster(), first_master_uuid) self.assertEqual(self.neo.getPrimaryMaster(), first_master_uuid)
...@@ -132,7 +133,7 @@ class MasterTests(NEOFunctionalTest): ...@@ -132,7 +133,7 @@ class MasterTests(NEOFunctionalTest):
third_master.start() third_master.start()
# Check that the third master is running under his known UUID. # Check that the third master is running under his known UUID.
self.neo.expectMasterState(third_master.getUUID(), self.neo.expectMasterState(third_master.getUUID(),
protocol.RUNNING_STATE) NodeStates.RUNNING)
# Check that the primary master didn't change. # Check that the primary master didn't change.
self.assertEqual(self.neo.getPrimaryMaster(), first_master_uuid) self.assertEqual(self.neo.getPrimaryMaster(), first_master_uuid)
......
...@@ -23,7 +23,7 @@ from Persistence import Persistent ...@@ -23,7 +23,7 @@ from Persistence import Persistent
from neo.tests.functional import NEOCluster, NEOFunctionalTest from neo.tests.functional import NEOCluster, NEOFunctionalTest
from neo.client.Storage import Storage as NEOStorage from neo.client.Storage import Storage as NEOStorage
from neo import protocol from neo import protocol
from neo.protocol import ClusterStates from neo.protocol import ClusterStates, NodeStates
class PObject(Persistent): class PObject(Persistent):
...@@ -106,18 +106,18 @@ class StorageTests(NEOFunctionalTest): ...@@ -106,18 +106,18 @@ class StorageTests(NEOFunctionalTest):
self.__checkDatabase(db_name) self.__checkDatabase(db_name)
# check storages state # check storages state
storage_list = self.neo.getStorageList(protocol.RUNNING_STATE) storage_list = self.neo.getStorageList(NodeStates.RUNNING)
self.assertEqual(len(storage_list), 2) self.assertEqual(len(storage_list), 2)
def __expectRunning(self, process): def __expectRunning(self, process):
self.neo.expectStorageState(process.getUUID(), protocol.RUNNING_STATE) self.neo.expectStorageState(process.getUUID(), NodeStates.RUNNING)
def __expectPending(self, process): def __expectPending(self, process):
self.neo.expectStorageState(process.getUUID(), protocol.PENDING_STATE) self.neo.expectStorageState(process.getUUID(), NodeStates.PENDING)
def __expectUnavailable(self, process): def __expectUnavailable(self, process):
self.neo.expectStorageState(process.getUUID(), self.neo.expectStorageState(process.getUUID(),
protocol.TEMPORARILY_DOWN_STATE) NodeStates.TEMPORARILY_DOWN)
def __expectNotKnown(self, process): def __expectNotKnown(self, process):
def expected_storage_not_known(last_try): def expected_storage_not_known(last_try):
......
...@@ -23,16 +23,14 @@ from struct import pack, unpack ...@@ -23,16 +23,14 @@ 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, NodeTypes, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, 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, \
REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \ REELECT_PRIMARY_MASTER, NOTIFY_NODE_INFORMATION, \
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
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 from neo.exception import OperationFailure, ElectionFailure
class MasterClientHandlerTests(NeoTestBase): class MasterClientHandlerTests(NeoTestBase):
...@@ -76,7 +74,7 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -76,7 +74,7 @@ class MasterClientHandlerTests(NeoTestBase):
node_type, node_type,
address=(ip, port), address=(ip, port),
uuid=uuid, uuid=uuid,
state=protocol.RUNNING_STATE, state=NodeStates.RUNNING,
) )
return uuid return uuid
...@@ -87,24 +85,28 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -87,24 +85,28 @@ 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 = [(NodeTypes.MASTER, ('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, NodeStates.DOWN),]
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 = [(NodeTypes.MASTER, ('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, NodeStates.RUNNING),]
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 = [(NodeTypes.CLIENT, ('127.0.0.1', self.client_port), new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.CLIENT, ('127.0.0.1', self.client_port),
new_uuid, NodeStates.BROKEN),]
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 = [(NodeTypes.STORAGE, ('127.0.0.1', 11010), new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11010), new_uuid,
NodeStates.BROKEN),]
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")
...@@ -114,34 +116,37 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -114,34 +116,37 @@ 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 = [(NodeTypes.STORAGE, ('127.0.0.1', 11012), uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', 11012), uuid, NodeStates.BROKEN),]
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 = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, RUNNING_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid,
NodeStates.RUNNING),]
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 = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, TEMPORARILY_DOWN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid,
NodeStates.TEMPORARILY_DOWN),]
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")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
self.assertEquals(sn.getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(sn.getState(), NodeStates.TEMPORARILY_DOWN)
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 = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, ('127.0.0.1', self.storage_port), uuid,
NodeStates.BROKEN),]
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")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
self.assertEquals(sn.getState(), BROKEN_STATE) self.assertEquals(sn.getState(), NodeStates.BROKEN)
self.failUnless(ptid < self.app.pt.getID()) self.failUnless(ptid < self.app.pt.getID())
...@@ -308,16 +313,18 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -308,16 +313,18 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1)) conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.peerBroken(conn) service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn) self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -328,7 +335,8 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -328,7 +335,8 @@ class MasterClientHandlerTests(NeoTestBase):
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn) service.peerBroken(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
...@@ -349,16 +357,18 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -349,16 +357,18 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1)) conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.timeoutExpired(conn) service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn) self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -369,7 +379,8 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -369,7 +379,8 @@ class MasterClientHandlerTests(NeoTestBase):
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn) service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
...@@ -390,16 +401,18 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -390,16 +401,18 @@ class MasterClientHandlerTests(NeoTestBase):
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1)) conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.connectionClosed(conn) service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn) self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -410,7 +423,8 @@ class MasterClientHandlerTests(NeoTestBase): ...@@ -410,7 +423,8 @@ class MasterClientHandlerTests(NeoTestBase):
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn) service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
......
...@@ -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, NodeTypes, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, INVALID_UUID
from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler from neo.master.handlers.election import ClientElectionHandler, ServerElectionHandler
from neo.master.app import Application from neo.master.app import Application
from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -41,10 +41,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF ...@@ -41,10 +41,7 @@ from neo.protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIF
ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \ ANSWER_TRANSACTION_INFORMATION, ASK_OBJECT_HISTORY, ANSWER_OBJECT_HISTORY, \
ASK_OIDS, ANSWER_OIDS, \ ASK_OIDS, ANSWER_OIDS, \
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, \
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 from neo.exception import OperationFailure, ElectionFailure
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
from neo.connection import ClientConnection from neo.connection import ClientConnection
...@@ -75,7 +72,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -75,7 +72,7 @@ class MasterClientElectionTests(NeoTestBase):
self.app.negotiating_master_node_set = set() self.app.negotiating_master_node_set = set()
for node in self.app.nm.getMasterList(): for node in self.app.nm.getMasterList():
self.app.unconnected_master_node_set.add(node.getAddress()) self.app.unconnected_master_node_set.add(node.getAddress())
node.setState(RUNNING_STATE) node.setState(NodeStates.RUNNING)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.client_port = 11022 self.client_port = 11022
self.storage_port = 10021 self.storage_port = 10021
...@@ -96,7 +93,7 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -96,7 +93,7 @@ class MasterClientElectionTests(NeoTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
address = (ip, port) address = (ip, port)
self.app.nm.createMaster(address=address, uuid=uuid, self.app.nm.createMaster(address=address, uuid=uuid,
state=protocol.RUNNING_STATE) state=NodeStates.RUNNING)
return uuid return uuid
def test_01_connectionStarted(self): def test_01_connectionStarted(self):
...@@ -127,11 +124,13 @@ class MasterClientElectionTests(NeoTestBase): ...@@ -127,11 +124,13 @@ class MasterClientElectionTests(NeoTestBase):
self.election.connectionStarted(conn) self.election.connectionStarted(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.election.connectionFailed(conn) self.election.connectionFailed(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 1) self.assertEqual(len(self.app.unconnected_master_node_set), 1)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_11_handleAskPrimaryMaster(self): def test_11_handleAskPrimaryMaster(self):
election = self.election election = self.election
...@@ -276,7 +275,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -276,7 +275,7 @@ class MasterServerElectionTests(NeoTestBase):
self.app.negotiating_master_node_set = set() self.app.negotiating_master_node_set = set()
for node in self.app.nm.getMasterList(): for node in self.app.nm.getMasterList():
self.app.unconnected_master_node_set.add(node.getAddress()) self.app.unconnected_master_node_set.add(node.getAddress())
node.setState(RUNNING_STATE) node.setState(NodeStates.RUNNING)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.client_port = 11022 self.client_port = 11022
self.storage_port = 10021 self.storage_port = 10021
...@@ -316,11 +315,13 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -316,11 +315,13 @@ class MasterServerElectionTests(NeoTestBase):
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.election.connectionClosed(conn) self.election.connectionClosed(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 1) self.assertEqual(len(self.app.unconnected_master_node_set), 1)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_05_timeoutExpired(self): def test_05_timeoutExpired(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
...@@ -328,11 +329,13 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -328,11 +329,13 @@ class MasterServerElectionTests(NeoTestBase):
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodesStates.RUNNING)
self.election.timeoutExpired(conn) self.election.timeoutExpired(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 1) self.assertEqual(len(self.app.unconnected_master_node_set), 1)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_06_peerBroken1(self): def test_06_peerBroken1(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
...@@ -340,11 +343,13 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -340,11 +343,13 @@ class MasterServerElectionTests(NeoTestBase):
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.election.peerBroken(conn) self.election.peerBroken(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 0) self.assertEqual(len(self.app.negotiating_master_node_set), 0)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.DOWN)
def test_06_peerBroken2(self): def test_06_peerBroken2(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
...@@ -357,11 +362,13 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -357,11 +362,13 @@ class MasterServerElectionTests(NeoTestBase):
self.election.connectionStarted(conn) self.election.connectionStarted(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.election.peerBroken(conn) self.election.peerBroken(conn)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), BROKEN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.BROKEN)
def test_07_packetReceived(self): def test_07_packetReceived(self):
uuid = self.identifyToMasterNode(port=self.master_port) uuid = self.identifyToMasterNode(port=self.master_port)
...@@ -373,12 +380,14 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -373,12 +380,14 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
node = self.app.nm.getByAddress(conn.getAddress()) node = self.app.nm.getByAddress(conn.getAddress())
node.setState(DOWN_STATE) node.setState(NodeStates.DOWN)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.DOWN)
self.election.packetReceived(conn, p) self.election.packetReceived(conn, p)
self.assertEqual(len(self.app.unconnected_master_node_set), 0) self.assertEqual(len(self.app.unconnected_master_node_set), 0)
self.assertEqual(len(self.app.negotiating_master_node_set), 1) self.assertEqual(len(self.app.negotiating_master_node_set), 1)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
def test_08_handleAcceptNodeIdentification1(self): def test_08_handleAcceptNodeIdentification1(self):
# test with storage node, must be rejected # test with storage node, must be rejected
...@@ -483,7 +492,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -483,7 +492,7 @@ class MasterServerElectionTests(NeoTestBase):
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
node = self.app.nm.getMasterList()[0] node = self.app.nm.getMasterList()[0]
self.assertEqual(node.getUUID(), None) self.assertEqual(node.getUUID(), None)
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), NodeStates.RUNNING)
election.handleRequestNodeIdentification(conn, election.handleRequestNodeIdentification(conn,
packet=packet, packet=packet,
node_type=NodeTypes.MASTER, node_type=NodeTypes.MASTER,
...@@ -492,7 +501,7 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -492,7 +501,7 @@ class MasterServerElectionTests(NeoTestBase):
name=self.app.name,) name=self.app.name,)
self.assertEqual(len(self.app.nm.getMasterList()), 1) self.assertEqual(len(self.app.nm.getMasterList()), 1)
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), NodeStates.RUNNING)
self.checkAcceptNodeIdentification(conn, answered_packet=packet) self.checkAcceptNodeIdentification(conn, answered_packet=packet)
# unknown node # unknown node
conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None, conn = Mock({"_addPacket" : None, "abort" : None, "expectMessage" : None,
...@@ -517,9 +526,9 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -517,9 +526,9 @@ class MasterServerElectionTests(NeoTestBase):
"isServer" : True}) "isServer" : True})
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.getUUID(), new_uuid) self.assertEqual(node.getUUID(), new_uuid)
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), NodeStates.RUNNING)
node.setState(BROKEN_STATE) node.setState(NodeStates.BROKEN)
self.assertEqual(node.getState(), BROKEN_STATE) self.assertEqual(node.getState(), NodeStates.BROKEN)
self.checkBrokenNodeDisallowedErrorRaised( self.checkBrokenNodeDisallowedErrorRaised(
election.handleRequestNodeIdentification, election.handleRequestNodeIdentification,
conn, conn,
...@@ -585,7 +594,8 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -585,7 +594,8 @@ 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 = [(NodeTypes.MASTER, ('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, NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
election.handleNotifyNodeInformation(conn, packet, node_list) election.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -594,35 +604,39 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -594,35 +604,39 @@ 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 = [(NodeTypes.STORAGE, ('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(), NodeStates.DOWN),]
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 = [(NodeTypes.CLIENT, ('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(), NodeStates.DOWN),]
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 = [(NodeTypes.MASTER, ('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(), NodeStates.RUNNING),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port+1))
self.assertEqual(node, None) self.assertEqual(node, None)
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)
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(), NodeStates.RUNNING)
# tell that node is down # tell that node is down
node_list = [(NodeTypes.MASTER, '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(), NodeStates.DOWN),]
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)
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(), DOWN_STATE) self.assertEqual(node.getState(), NodeStates.DOWN)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
from neo.protocol import NodeStates
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ DISCARDED_STATE, INVALID_UUID
BROKEN_STATE, INVALID_UUID
from neo.pt import Cell from neo.pt import Cell
from neo.master.pt import PartitionTable from neo.master.pt import PartitionTable
from neo.node import StorageNode from neo.node import StorageNode
...@@ -115,15 +115,15 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -115,15 +115,15 @@ class MasterPartitionTableTests(NeoTestBase):
num_replicas = 3 num_replicas = 3
pt = PartitionTable(num_partitions, num_replicas) pt = PartitionTable(num_partitions, num_replicas)
pt.setCell(0, sn1, OUT_OF_DATE_STATE) pt.setCell(0, sn1, OUT_OF_DATE_STATE)
sn1.setState(RUNNING_STATE) sn1.setState(NodeStates.RUNNING)
pt.setCell(1, sn2, UP_TO_DATE_STATE) pt.setCell(1, sn2, UP_TO_DATE_STATE)
sn2.setState(TEMPORARILY_DOWN_STATE) sn2.setState(NodeStates.TEMPORARILY_DOWN)
pt.setCell(2, sn3, UP_TO_DATE_STATE) pt.setCell(2, sn3, UP_TO_DATE_STATE)
sn3.setState(DOWN_STATE) sn3.setState(NodeStates.DOWN)
pt.setCell(3, sn4, UP_TO_DATE_STATE) pt.setCell(3, sn4, UP_TO_DATE_STATE)
sn4.setState(BROKEN_STATE) sn4.setState(NodeStates.BROKEN)
pt.setCell(4, sn5, UP_TO_DATE_STATE) pt.setCell(4, sn5, UP_TO_DATE_STATE)
sn5.setState(RUNNING_STATE) sn5.setState(NodeStates.RUNNING)
# outdate nodes # outdate nodes
cells_outdated = pt.outdate() cells_outdated = pt.outdate()
self.assertEqual(len(cells_outdated), 3) self.assertEqual(len(cells_outdated), 3)
...@@ -373,7 +373,7 @@ class MasterPartitionTableTests(NeoTestBase): ...@@ -373,7 +373,7 @@ class MasterPartitionTableTests(NeoTestBase):
uuid2 = self.getNewUUID() uuid2 = self.getNewUUID()
server2 = ("127.0.0.2", 19001) server2 = ("127.0.0.2", 19001)
sn2 = StorageNode(Mock(), server2, uuid2) sn2 = StorageNode(Mock(), server2, uuid2)
sn2.setState(TEMPORARILY_DOWN_STATE) sn2.setState(NodeStates.TEMPORARILY_DOWN)
# add node without uuid # add node without uuid
server3 = ("127.0.0.3", 19001) server3 = ("127.0.0.3", 19001)
sn3 = StorageNode(Mock(), server3, None) sn3 = StorageNode(Mock(), server3, 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, NodeTypes, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, 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, \
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
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
...@@ -64,7 +63,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -64,7 +63,7 @@ class MasterRecoveryTests(NeoTestBase):
self.app.negotiating_master_node_set = set() self.app.negotiating_master_node_set = set()
for node in self.app.nm.getMasterList(): for node in self.app.nm.getMasterList():
self.app.unconnected_master_node_set.add(node.getAddress()) self.app.unconnected_master_node_set.add(node.getAddress())
node.setState(RUNNING_STATE) node.setState(NodeStates.RUNNING)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.client_port = 11022 self.client_port = 11022
...@@ -91,24 +90,30 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -91,24 +90,30 @@ class MasterRecoveryTests(NeoTestBase):
def test_01_connectionClosed(self): def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
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(),
NodeStates.TEMPORARILY_DOWN)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.recovery.timeoutExpired(conn) self.recovery.timeoutExpired(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.recovery.peerBroken(conn) self.recovery.peerBroken(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), BROKEN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.BROKEN)
def test_08_handleNotifyNodeInformation(self): def test_08_handleNotifyNodeInformation(self):
recovery = self.recovery recovery = self.recovery
...@@ -116,14 +121,16 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -116,14 +121,16 @@ class MasterRecoveryTests(NeoTestBase):
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 = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, self.getNewUUID(), DOWN_STATE),] node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port,
self.getNewUUID(), NodeStates.DOWN),]
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 = [(NodeTypes.MASTER, '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, NodeStates.RUNNING),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
self.assertEqual(node, None) self.assertEqual(node, None)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
...@@ -131,35 +138,39 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -131,35 +138,39 @@ 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 = [(NodeTypes.MASTER, '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, NodeStates.DOWN),]
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port-1))
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 = [(NodeTypes.STORAGE, '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(), NodeStates.DOWN),]
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 = [(NodeTypes.MASTER, '127.0.0.2', self.master_port, uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.2', self.master_port, uuid,
NodeStates.DOWN),]
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(), NodeStates.RUNNING)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), RUNNING_STATE) self.assertEqual(node.getState(), NodeStates.RUNNING)
# 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 = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, uuid, DOWN_STATE),] node_list = [(NodeTypes.MASTER, '127.0.0.1', self.master_port, uuid,
NodeStates.DOWN),]
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(), NodeStates.RUNNING)
recovery.handleNotifyNodeInformation(conn, packet, node_list) recovery.handleNotifyNodeInformation(conn, packet, node_list)
node = self.app.nm.getByAddress(("127.0.0.1", self.master_port)) node = self.app.nm.getByAddress(("127.0.0.1", self.master_port))
self.assertEqual(node.getState(), DOWN_STATE) self.assertEqual(node.getState(), NodeStates.DOWN)
def test_09_handleAnswerLastIDs(self): def test_09_handleAnswerLastIDs(self):
...@@ -225,7 +236,7 @@ class MasterRecoveryTests(NeoTestBase): ...@@ -225,7 +236,7 @@ class MasterRecoveryTests(NeoTestBase):
self.assertEquals(self.app.target_uuid, uuid) self.assertEquals(self.app.target_uuid, uuid)
offset = 1000000 offset = 1000000
self.assertFalse(self.app.pt.hasOffset(offset)) self.assertFalse(self.app.pt.hasOffset(offset))
cell_list = [(offset, ((uuid, DOWN_STATE,),),)] cell_list = [(offset, ((uuid, NodeStates.DOWN,),),)]
self.checkUnexpectedPacketRaised(recovery.handleAnswerPartitionTable, conn, packet, None, cell_list) self.checkUnexpectedPacketRaised(recovery.handleAnswerPartitionTable, conn, packet, None, cell_list)
......
...@@ -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, NodeTypes, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, 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, \
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
...@@ -77,24 +76,28 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -77,24 +76,28 @@ 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 = [(NodeTypes.MASTER, '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, NodeStates.DOWN),]
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 = [(NodeTypes.MASTER, '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, NodeStates.RUNNING),]
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 = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.CLIENT, '127.0.0.1', self.client_port, new_uuid,
NodeStates.BROKEN),]
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 = [(NodeTypes.STORAGE, '127.0.0.1', 11010, new_uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11010, new_uuid,
NodeStates.BROKEN),]
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")
...@@ -104,29 +107,32 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -104,29 +107,32 @@ 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 = [(NodeTypes.STORAGE, '127.0.0.1', 11012, uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', 11012, uuid, NodeStates.BROKEN),]
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 = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, RUNNING_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid,
NodeStates.RUNNING),]
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 = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, TEMPORARILY_DOWN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid,
NodeStates.TEMPORARILY_DOWN),]
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")
sn = self.app.nm.getStorageList()[0] sn = self.app.nm.getStorageList()[0]
self.assertEquals(sn.getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(sn.getState(), NodeStates.TEMPORARILY_DOWN)
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 = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid, BROKEN_STATE),] node_list = [(NodeTypes.STORAGE, '127.0.0.1', self.storage_port, uuid,
NodeStates.BROKEN),]
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")
...@@ -305,9 +311,9 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -305,9 +311,9 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
# do nothing if no uuid # do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address) conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
service.peerBroken(conn) service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as broken # add a second storage node and then declare it as broken
self.identifyToMasterNode(port = self.storage_port+2) self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1) storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
...@@ -317,16 +323,18 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -317,16 +323,18 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1)) conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.peerBroken(conn) service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn) self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), BROKEN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -337,7 +345,8 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -337,7 +345,8 @@ class MasterStorageHandlerTests(NeoTestBase):
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn) service.peerBroken(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
...@@ -351,9 +360,9 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -351,9 +360,9 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
# do nothing if no uuid # do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address) conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
service.timeoutExpired(conn) service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as temp down # add a second storage node and then declare it as temp down
self.identifyToMasterNode(port = self.storage_port+2) self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1) storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
...@@ -363,16 +372,18 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -363,16 +372,18 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1)) conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.timeoutExpired(conn) service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn) self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -383,7 +394,8 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -383,7 +394,8 @@ class MasterStorageHandlerTests(NeoTestBase):
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn) service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
...@@ -397,9 +409,9 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -397,9 +409,9 @@ class MasterStorageHandlerTests(NeoTestBase):
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
# do nothing if no uuid # do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address) conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
service.connectionClosed(conn) service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as temp down # add a second storage node and then declare it as temp down
self.identifyToMasterNode(port = self.storage_port+2) self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1) storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
...@@ -409,16 +421,18 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -409,16 +421,18 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertTrue(self.app.pt.operational()) self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1)) conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.connectionClosed(conn) service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn) self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), TEMPORARILY_DOWN_STATE) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -429,7 +443,8 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -429,7 +443,8 @@ class MasterStorageHandlerTests(NeoTestBase):
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
service.handleAskBeginTransaction(conn, packet) service.handleAskBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), RUNNING_STATE) self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn) service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains # node must be have been remove, and no more transaction must remains
......
...@@ -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, NodeTypes, INVALID_UUID from neo.protocol import Packet, NodeTypes, NodeStates, 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, \
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
from neo.tests import DoNothingConnector from neo.tests import DoNothingConnector
...@@ -56,7 +55,7 @@ class MasterVerificationTests(NeoTestBase): ...@@ -56,7 +55,7 @@ class MasterVerificationTests(NeoTestBase):
self.app.ltid = '\0' * 8 self.app.ltid = '\0' * 8
for node in self.app.nm.getMasterList(): for node in self.app.nm.getMasterList():
self.app.unconnected_master_node_set.add(node.getAddress()) self.app.unconnected_master_node_set.add(node.getAddress())
node.setState(RUNNING_STATE) node.setState(NodeStates.RUNNING)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.client_port = 11022 self.client_port = 11022
...@@ -88,41 +87,53 @@ class MasterVerificationTests(NeoTestBase): ...@@ -88,41 +87,53 @@ class MasterVerificationTests(NeoTestBase):
def test_01_connectionClosed(self): def test_01_connectionClosed(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.verification.connectionClosed(conn) self.verification.connectionClosed(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
# test a storage, must raise as cluster no longer op # test a storage, must raise as cluster no longer op
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn) self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_02_timeoutExpired(self): def test_02_timeoutExpired(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.verification.timeoutExpired(conn) self.verification.timeoutExpired(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
# test a storage, must raise as cluster no longer op # test a storage, must raise as cluster no longer op
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn) self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_03_peerBroken(self): def test_03_peerBroken(self):
uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(node_type=NodeTypes.MASTER, port=self.master_port)
conn = self.getFakeConnection(uuid, self.master_address) conn = self.getFakeConnection(uuid, self.master_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.verification.peerBroken(conn) self.verification.peerBroken(conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), BROKEN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.BROKEN)
# test a storage, must raise as cluster no longer op # test a storage, must raise as cluster no longer op
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), RUNNING_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.RUNNING)
self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn) self.assertRaises(VerificationFailure, self.verification.connectionClosed,conn)
self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(), TEMPORARILY_DOWN_STATE) self.assertEqual(self.app.nm.getByAddress(conn.getAddress()).getState(),
NodeStates.TEMPORARILY_DOWN)
def test_09_handleAnswerLastIDs(self): def test_09_handleAnswerLastIDs(self):
verification = self.verification verification = self.verification
......
...@@ -24,7 +24,7 @@ from neo import protocol ...@@ -24,7 +24,7 @@ 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.initialization import InitializationHandler from neo.storage.handlers.initialization import InitializationHandler
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \ from neo.protocol import Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_TID, PROTOCOL_ERROR_CODE UP_TO_DATE_STATE, 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, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
......
...@@ -24,7 +24,7 @@ from neo import protocol ...@@ -24,7 +24,7 @@ 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 BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \ from neo.protocol import 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, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
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, 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
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
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, UNKNOWN_STATE from neo.protocol import NodeTypes, NodeStates
from neo.protocol import NodeTypes
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
...@@ -45,7 +44,7 @@ class NodesTests(NeoTestBase): ...@@ -45,7 +44,7 @@ class NodesTests(NeoTestBase):
address = ('127.0.0.1', 10000) address = ('127.0.0.1', 10000)
uuid = self.getNewUUID() uuid = self.getNewUUID()
node = Node(self.manager, address=address, uuid=uuid) node = Node(self.manager, address=address, uuid=uuid)
self.assertEqual(node.getState(), protocol.UNKNOWN_STATE) self.assertEqual(node.getState(), NodeStates.UNKNOWN)
self.assertEqual(node.getAddress(), address) self.assertEqual(node.getAddress(), address)
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
...@@ -53,11 +52,11 @@ class NodesTests(NeoTestBase): ...@@ -53,11 +52,11 @@ class NodesTests(NeoTestBase):
def testState(self): def testState(self):
""" Check if the last changed time is updated when state is changed """ """ Check if the last changed time is updated when state is changed """
node = Node(self.manager) node = Node(self.manager)
self.assertEqual(node.getState(), protocol.UNKNOWN_STATE) self.assertEqual(node.getState(), NodeStates.UNKNOWN)
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
previous_time = node.getLastStateChange() previous_time = node.getLastStateChange()
node.setState(protocol.RUNNING_STATE) node.setState(NodeStates.RUNNING)
self.assertEqual(node.getState(), protocol.RUNNING_STATE) self.assertEqual(node.getState(), NodeStates.RUNNING)
self.assertTrue(previous_time < node.getLastStateChange()) self.assertTrue(previous_time < node.getLastStateChange())
self.assertTrue(time() - 1 < node.getLastStateChange() < time()) self.assertTrue(time() - 1 < node.getLastStateChange() < time())
...@@ -248,10 +247,12 @@ class NodeManagerTests(NeoTestBase): ...@@ -248,10 +247,12 @@ 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 = (
(NodeTypes.CLIENT, None, self.client.getUUID(), DOWN_STATE), (NodeTypes.CLIENT, None, self.client.getUUID(), NodeStates.DOWN),
(NodeTypes.MASTER, new_address, self.master.getUUID(), RUNNING_STATE), (NodeTypes.MASTER, new_address, self.master.getUUID(), NodeStates.RUNNING),
(NodeTypes.STORAGE, self.storage.getAddress(), new_uuid, RUNNING_STATE), (NodeTypes.STORAGE, self.storage.getAddress(), new_uuid,
(NodeTypes.ADMIN, self.admin.getAddress(), self.admin.getUUID(), UNKNOWN_STATE), NodeStates.RUNNING),
(NodeTypes.ADMIN, self.admin.getAddress(), self.admin.getUUID(),
NodeStates.UNKNOWN),
) )
# update manager content # update manager content
manager.update(node_list) manager.update(node_list)
...@@ -266,11 +267,11 @@ class NodeManagerTests(NeoTestBase): ...@@ -266,11 +267,11 @@ class NodeManagerTests(NeoTestBase):
self.assertNotEqual(manager.getStorageList(), [self.storage]) self.assertNotEqual(manager.getStorageList(), [self.storage])
self.assertTrue(len(manager.getStorageList()), 1) self.assertTrue(len(manager.getStorageList()), 1)
new_storage = manager.getStorageList()[0] new_storage = manager.getStorageList()[0]
self.assertEqual(new_storage.getState(), RUNNING_STATE) self.assertEqual(new_storage.getState(), NodeStates.RUNNING)
self.assertNotEqual(new_storage, self.storage) self.assertNotEqual(new_storage, self.storage)
# admin is still here but in UNKNOWN_STATE # admin is still here but in UNKNOWN state
self.checkNodes([self.master, self.admin, new_storage]) self.checkNodes([self.master, self.admin, new_storage])
self.assertEqual(self.admin.getState(), UNKNOWN_STATE) self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
import unittest, os import unittest, os
from mock import Mock from mock import Mock
from neo.protocol import NodeStates
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \ from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ DISCARDED_STATE, INVALID_UUID
BROKEN_STATE, INVALID_UUID, UNKNOWN_STATE
from neo.pt import Cell, PartitionTable from neo.pt import Cell, PartitionTable
from neo.node import StorageNode from neo.node import StorageNode
from neo.tests import NeoTestBase from neo.tests import NeoTestBase
...@@ -39,7 +39,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -39,7 +39,7 @@ class PartitionTableTests(NeoTestBase):
# check getter # check getter
self.assertEquals(cell.getNode(), sn) self.assertEquals(cell.getNode(), sn)
self.assertEquals(cell.getState(), OUT_OF_DATE_STATE) self.assertEquals(cell.getState(), OUT_OF_DATE_STATE)
self.assertEquals(cell.getNodeState(), UNKNOWN_STATE) self.assertEquals(cell.getNodeState(), NodeStates.UNKNOWN)
self.assertEquals(cell.getUUID(), uuid) self.assertEquals(cell.getUUID(), uuid)
self.assertEquals(cell.getAddress(), server) self.assertEquals(cell.getAddress(), server)
# check state setter # check state setter
...@@ -114,12 +114,12 @@ class PartitionTableTests(NeoTestBase): ...@@ -114,12 +114,12 @@ class PartitionTableTests(NeoTestBase):
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0) self.assertEqual(pt.count_dict[sn1], 0)
sn1.setState(BROKEN_STATE) sn1.setState(NodeStates.BROKEN)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
self.assertEqual(pt.count_dict[sn1], 0) self.assertEqual(pt.count_dict[sn1], 0)
sn1.setState(DOWN_STATE) sn1.setState(NodeStates.DOWN)
pt.setCell(0, sn1, UP_TO_DATE_STATE) pt.setCell(0, sn1, UP_TO_DATE_STATE)
for x in xrange(num_partitions): for x in xrange(num_partitions):
self.assertEqual(len(pt.partition_list[x]), 0) self.assertEqual(len(pt.partition_list[x]), 0)
...@@ -332,7 +332,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -332,7 +332,7 @@ class PartitionTableTests(NeoTestBase):
pt.setCell(x, sn1, UP_TO_DATE_STATE) pt.setCell(x, sn1, UP_TO_DATE_STATE)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
# it's up to date and running, so operational # it's up to date and running, so operational
sn1.setState(RUNNING_STATE) sn1.setState(NodeStates.RUNNING)
self.assertTrue(pt.operational()) self.assertTrue(pt.operational())
# same with feeding state # same with feeding state
pt.clear() pt.clear()
...@@ -346,7 +346,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -346,7 +346,7 @@ class PartitionTableTests(NeoTestBase):
pt.setCell(x, sn1, FEEDING_STATE) pt.setCell(x, sn1, FEEDING_STATE)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
# it's feeding and running, so operational # it's feeding and running, so operational
sn1.setState(RUNNING_STATE) sn1.setState(NodeStates.RUNNING)
self.assertTrue(pt.operational()) self.assertTrue(pt.operational())
# same with feeding state but non running node # same with feeding state but non running node
...@@ -357,7 +357,7 @@ class PartitionTableTests(NeoTestBase): ...@@ -357,7 +357,7 @@ class PartitionTableTests(NeoTestBase):
uuid1 = self.getNewUUID() uuid1 = self.getNewUUID()
server1 = ("127.0.0.1", 19001) server1 = ("127.0.0.1", 19001)
sn1 = StorageNode(Mock(), server1, uuid1) sn1 = StorageNode(Mock(), server1, uuid1)
sn1.setState(TEMPORARILY_DOWN_STATE) sn1.setState(NodeStates.TEMPORARILY_DOWN)
for x in xrange(num_partitions): for x in xrange(num_partitions):
pt.setCell(x, sn1, FEEDING_STATE) pt.setCell(x, sn1, FEEDING_STATE)
self.assertTrue(pt.filled()) self.assertTrue(pt.filled())
......
...@@ -19,7 +19,7 @@ import unittest, os ...@@ -19,7 +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.protocol import NodeTypes, NodeStates
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
...@@ -144,9 +144,9 @@ class ProtocolTests(NeoTestBase): ...@@ -144,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 = [(NodeTypes.CLIENT, ("127.0.0.1", 1), uuid1, RUNNING_STATE), node_list = [(NodeTypes.CLIENT, ("127.0.0.1", 1), uuid1, NodeStates.RUNNING),
(NodeTypes.CLIENT, ("127.0.0.2", 2), uuid2, DOWN_STATE), (NodeTypes.CLIENT, ("127.0.0.2", 2), uuid2, NodeStates.DOWN),
(NodeTypes.CLIENT, ("127.0.0.3", 3), uuid3, BROKEN_STATE)] (NodeTypes.CLIENT, ("127.0.0.3", 3), uuid3, NodeStates.BROKEN)]
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