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

Factory cluster name verification. Do not use the decorator previously commited

since the 'name' handler parameter is not positional-fixed nor a keyword
argument.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@671 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent c5d9d9a9
......@@ -123,9 +123,7 @@ class AdminEventHandler(BaseEventHandler):
conn.answer(p, packet)
def handleSetClusterState(self, conn, packet, name, state):
if name != self.app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
self.checkClusterName(name)
# forward to primary
master_conn = self.app.master_conn
p = protocol.setClusterState(name, state)
......
......@@ -21,14 +21,6 @@ from neo import protocol
# Some decorators useful to avoid duplication of patterns in handlers
def check_cluster_name(handler):
def wrapper(self, conn, packet, name, *args, **kwargs):
if self.app.name != name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
handler(self, conn, packet, name, *args, **kwargs)
return wrapper
def identification_required(handler):
""" Raise UnexpectedPacketError if the identification has not succeed """
def wrapper(self, conn, packet, *args, **kwargs):
......
......@@ -151,6 +151,12 @@ class EventHandler(object):
except ProtocolError, e:
self.protocolError(conn, packet, *e.args)
def checkClusterName(self, name):
# raise an exception if the fiven name mismatch the current cluster name
if self.app.name != name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
# Packet handlers.
def handleError(self, conn, packet, code, message):
......
......@@ -171,14 +171,11 @@ class ElectionEventHandler(MasterEventHandler):
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if node_type != MASTER_NODE_TYPE:
logging.info('reject a connection from a non-master')
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByServer(addr)
if node is None:
......
......@@ -66,14 +66,11 @@ class RecoveryEventHandler(MasterEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type, uuid,
ip_address, port, name):
self.checkClusterName(name)
app = self.app
if node_type not in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE):
logging.info('reject a connection from a client')
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
if node_type is STORAGE_NODE_TYPE and uuid is INVALID_UUID:
# refuse an empty storage node (with no UUID) to avoid potential
# UUID conflict
......
......@@ -59,11 +59,8 @@ class SecondaryEventHandler(MasterEventHandler):
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
# Add a node only if it is a master node and I do not know it yet.
if node_type == MASTER_NODE_TYPE and uuid != INVALID_UUID:
addr = (ip_address, port)
......
......@@ -135,11 +135,8 @@ class ServiceEventHandler(MasterEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
# Here are many situations. In principle, a node should be identified
# by an UUID, since an UUID never change when moving a storage node
# to a different server, and an UUID always changes for a master node
......
......@@ -90,14 +90,11 @@ class VerificationEventHandler(MasterEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if node_type not in (MASTER_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE):
logging.info('reject a connection from a client')
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
# Here are many situations. In principle, a node should be identified by
# an UUID, since an UUID never change when moving a storage node to a different
# server, and an UUID always changes for a master node and a client node whenever
......
......@@ -109,14 +109,11 @@ class BootstrapEventHandler(StorageEventHandler):
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if node_type != MASTER_NODE_TYPE:
logging.info('reject a connection from a non-master')
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError( 'invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByServer(addr)
if node is None:
......
......@@ -135,11 +135,8 @@ class OperationEventHandler(StorageEventHandler):
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByUUID(uuid)
if node is None:
......
......@@ -65,13 +65,11 @@ class VerificationEventHandler(StorageEventHandler):
@decorators.server_connection_required
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
self.checkClusterName(name)
app = self.app
if node_type != MASTER_NODE_TYPE:
logging.info('reject a connection from a non-master')
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
raise protocol.ProtocolError('invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByServer(addr)
......
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