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

Last commit of exception-based error handling serie. Raise ProtocolError

exception for all others errors.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@508 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 1b70a832
......@@ -172,6 +172,11 @@ class EventHandler(object):
conn.answer(protocol.notReady('retry later'), packet)
conn.abort()
def protocolError(self, conn, packet, message):
""" Called for any other protocol error """
conn.answer(protocol.protocolError(message), packet)
conn.abort()
def dispatch(self, conn, packet):
"""This is a helper method to handle various packet types."""
t = packet.getType()
......@@ -189,6 +194,8 @@ class EventHandler(object):
self.brokenNodeDisallowedError(conn, packet, msg)
except NotReadyError, msg:
self.notReadyError(conn, packet, msg)
except ProtocolError, msg:
self.protocolError(self, conn, packet, msg)
# Packet handlers.
......
......@@ -178,9 +178,7 @@ class ElectionEventHandler(MasterEventHandler):
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
raise protocol.ProtocolError('invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByServer(addr)
......
......@@ -72,9 +72,7 @@ class RecoveryEventHandler(MasterEventHandler):
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
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
......@@ -116,11 +114,7 @@ class RecoveryEventHandler(MasterEventHandler):
if node.getNodeType() != MASTER_NODE_TYPE or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as a master
# node.
p = protocol.protocolError('invalid server address')
conn.answer(p, packet)
conn.abort()
return
raise protocol.ProtocolError('invalid server address')
node.setUUID(uuid)
if node.getState() != RUNNING_STATE:
node.setState(RUNNING_STATE)
......@@ -129,37 +123,28 @@ class RecoveryEventHandler(MasterEventHandler):
# This node has a different UUID.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
p = protocol.protocolError('invalid server address')
conn.answer(p, packet)
conn.abort()
return
else:
# Otherwise, forget the old one.
node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node)
# And insert a new one.
node.setUUID(uuid)
node.setState(RUNNING_STATE)
app.broadcastNodeInformation(node)
else:
# I know this node by the UUID.
if node.getServer() != addr:
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
p = protocol.protocolError('invalid server address')
conn.answer(p, packet)
conn.abort()
return
else:
raise protocol.ProtocolError('invalid server address')
# Otherwise, forget the old one.
node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node)
# And insert a new one.
node.setServer(addr)
node.setUUID(uuid)
node.setState(RUNNING_STATE)
app.broadcastNodeInformation(node)
else:
# I know this node by the UUID.
if node.getServer() != addr:
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
raise protocol.ProtocolError('invalid server address')
# Otherwise, forget the old one.
node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node)
# And insert a new one.
node.setServer(addr)
node.setState(RUNNING_STATE)
app.broadcastNodeInformation(node)
else:
# If this node is broken, reject it. Otherwise, assume that it is
# working again.
......
......@@ -63,9 +63,7 @@ class SecondaryEventHandler(MasterEventHandler):
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
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:
......
......@@ -154,9 +154,7 @@ class ServiceEventHandler(MasterEventHandler):
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
conn.notify(protocol.protocolError('invalid cluster name'))
conn.abort()
return
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
......@@ -202,9 +200,7 @@ class ServiceEventHandler(MasterEventHandler):
or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as
# a master node.
conn.notify(protocol.protocolError( 'invalid server address'))
conn.abort()
return
raise protocol.ProtocolError('invalid server address')
node.setUUID(uuid)
if node.getState() != RUNNING_STATE:
......@@ -215,37 +211,7 @@ class ServiceEventHandler(MasterEventHandler):
# This node has a different UUID.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.notify(protocol.protocolError('invalid server address'))
conn.abort()
return
else:
# Otherwise, forget the old one.
node.setState(DOWN_STATE)
logging.debug('broadcasting node information')
app.broadcastNodeInformation(node)
app.nm.remove(node)
old_node = node
node = copy(node)
# And insert a new one.
node.setUUID(uuid)
node.setState(RUNNING_STATE)
logging.debug('broadcasting node information')
app.broadcastNodeInformation(node)
app.nm.add(node)
else:
# I know this node by the UUID.
try:
ip_address, port = node.getServer()
except TypeError:
ip_address, port = '0.0.0.0', 0
if (ip_address, port) != addr:
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.notify(protocol.protocolError('invalid server address'))
conn.abort()
return
else:
raise protocol.ProtocolError('invalid server address')
# Otherwise, forget the old one.
node.setState(DOWN_STATE)
logging.debug('broadcasting node information')
......@@ -254,11 +220,35 @@ class ServiceEventHandler(MasterEventHandler):
old_node = node
node = copy(node)
# And insert a new one.
node.setServer(addr)
node.setUUID(uuid)
node.setState(RUNNING_STATE)
logging.debug('broadcasting node information')
app.broadcastNodeInformation(node)
app.nm.add(node)
else:
# I know this node by the UUID.
try:
ip_address, port = node.getServer()
except TypeError:
ip_address, port = '0.0.0.0', 0
if (ip_address, port) != addr:
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
raise protocol.ProtocolError('invalid server address')
# Otherwise, forget the old one.
node.setState(DOWN_STATE)
logging.debug('broadcasting node information')
app.broadcastNodeInformation(node)
app.nm.remove(node)
old_node = node
node = copy(node)
# And insert a new one.
node.setServer(addr)
node.setState(RUNNING_STATE)
logging.debug('broadcasting node information')
app.broadcastNodeInformation(node)
app.nm.add(node)
else:
# If this node is broken, reject it. Otherwise, assume that
# it is working again.
......
......@@ -134,6 +134,10 @@ server: 127.0.0.1:10023
# Delete tmp file
os.remove(self.tmp_path)
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
def checkUnexpectedPacketRaised(self, method, *args, **kwargs):
""" Check if the UnexpectedPacketError exception wxas raised """
self.assertRaises(protocol.UnexpectedPacketError, method, *args, **kwargs)
......@@ -521,14 +525,15 @@ server: 127.0.0.1:10023
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None,
"isServerConnection" : True})
election.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
election.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
# test connection of a storage node
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None,
"isServerConnection" : True})
......
......@@ -144,6 +144,10 @@ server: 127.0.0.1:10023
self.checkCalledAcceptNodeIdentification(conn)
return uuid
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
def checkUnexpectedPacketRaised(self, method, *args, **kwargs):
""" Check if the UnexpectedPacketError exception wxas raised """
self.assertRaises(protocol.UnexpectedPacketError, method, *args, **kwargs)
......@@ -264,14 +268,15 @@ server: 127.0.0.1:10023
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
recovery.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
recovery.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
# test connection from a client node, rejectet
uuid = self.getNewUUID()
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
......@@ -295,18 +300,19 @@ server: 127.0.0.1:10023
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleRequestNodeIdentification(conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
self.checkProtocolErrorRaised(
recovery.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.checkCalledAbort(conn)
# 2. unknown master node with known address, will be accepted
uuid = self.getNewUUID()
......@@ -346,14 +352,15 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), RUNNING_STATE)
self.assertEqual(node.getUUID(), old_uuid)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
recovery.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
recovery.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
# 4. unknown master node with known address but different uuid and broken state, will be accepted
uuid = self.getNewUUID()
......@@ -429,14 +436,15 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), DOWN_STATE)
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
recovery.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.2',
port=self.master_port,
name=self.app.name,)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
recovery.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.2',
port=self.master_port,
name=self.app.name,)
# 7. known node but broken
conn = Mock({"addPacket" : None,
......
......@@ -116,6 +116,10 @@ server: 127.0.0.1:10023
# Delete tmp file
os.remove(self.tmp_path)
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
def checkUnexpectedPacketRaised(self, method, *args, **kwargs):
""" Check if the UnexpectedPacketError exception wxas raised """
self.assertRaises(protocol.UnexpectedPacketError, method, *args, **kwargs)
......@@ -143,16 +147,6 @@ server: 127.0.0.1:10023
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledNotifyAbort(self, conn, packet_number=0):
"""Check the abort method has been called and an error packet has been sent"""
# sometimes we answer an error, sometimes we just send it
self.assertEquals(len(conn.mockGetNamedCalls("notify")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("abort")), 1)
call = conn.mockGetNamedCalls("notify")[packet_number]
packet = call.getParam(0)
self.assertTrue(isinstance(packet, Packet))
self.assertEquals(packet.getType(), ERROR)
def checkCalledAcceptNodeIdentification(self, conn, packet_number=0):
""" Check Accept Node Identification has been send"""
self.assertEquals(len(conn.mockGetNamedCalls("answer")), 1)
......@@ -260,8 +254,7 @@ server: 127.0.0.1:10023
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
ptid = self.app.lptid
service.handleRequestNodeIdentification(conn, packet, *args)
self.checkCalledNotifyAbort(conn)
self.checkProtocolErrorRaised(service.handleRequestNodeIdentification, conn, packet, *args)
self.assertEquals(len(self.app.nm.getStorageNodeList()), 0)
self.assertEquals(self.app.lptid, ptid)
......@@ -307,14 +300,15 @@ server: 127.0.0.1:10023
ptid = self.app.lptid
new_uuid = self.getNewUUID()
service.handleRequestNodeIdentification(conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=new_uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
self.checkCalledNotifyAbort(conn)
self.checkProtocolErrorRaised(
service.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=new_uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name=self.app.name,)
sn = self.app.nm.getStorageNodeList()[0]
self.assertEquals(sn.getServer(), ('127.0.0.1', self.storage_port))
self.assertEquals(sn.getUUID(), uuid)
......
......@@ -123,6 +123,10 @@ server: 127.0.0.1:10023
# Delete tmp file
os.remove(self.tmp_path)
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
def checkUnexpectedPacketRaised(self, method, *args, **kwargs):
""" Check if the UnexpectedPacketError exception wxas raised """
self.assertRaises(protocol.UnexpectedPacketError, method, *args, **kwargs)
......@@ -288,13 +292,14 @@ server: 127.0.0.1:10023
packet = protocol.requestNodeIdentification(*args)
# test alien cluster
conn = Mock({"addPacket" : None, "abort" : None})
verification.handleRequestNodeIdentification(conn, packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
verification.handleRequestNodeIdentification,
conn, packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.storage_port,
name="INVALID_NAME",)
# test connection from a client node, rejectet
uuid = self.getNewUUID()
conn = Mock({"addPacket" : None, "abort" : None, "expectMessage" : None})
......@@ -318,18 +323,19 @@ server: 127.0.0.1:10023
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
verification.handleRequestNodeIdentification(conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
self.checkProtocolErrorRaised(
verification.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=STORAGE_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
self.assertNotEqual(self.app.nm.getNodeByServer(conn.getAddress()), None)
self.assertEqual(self.app.nm.getNodeByUUID(conn.getUUID()), None)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
self.checkCalledAbort(conn)
# 2. unknown master node with known address, will be accepted
uuid = self.getNewUUID()
......@@ -369,14 +375,15 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), RUNNING_STATE)
self.assertEqual(node.getUUID(), old_uuid)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 1)
verification.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
verification.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.1',
port=self.master_port,
name=self.app.name,)
# 4. unknown master node with known address but different uuid and broken state, will be accepted
uuid = self.getNewUUID()
......@@ -451,14 +458,15 @@ server: 127.0.0.1:10023
self.assertEqual(node.getState(), DOWN_STATE)
self.assertEqual(node.getUUID(), uuid)
self.assertEqual(len(self.app.nm.getMasterNodeList()), 2)
verification.handleRequestNodeIdentification(conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.2',
port=self.master_port,
name=self.app.name,)
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
verification.handleRequestNodeIdentification,
conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
uuid=uuid,
ip_address='127.0.0.2',
port=self.master_port,
name=self.app.name,)
# 7. known node but broken
conn = Mock({"addPacket" : None,
......
......@@ -96,9 +96,7 @@ class VerificationEventHandler(MasterEventHandler):
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
conn.answer(protocol.protocolError('invalid cluster name'), packet)
conn.abort()
return
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
......@@ -140,11 +138,7 @@ class VerificationEventHandler(MasterEventHandler):
if node.getNodeType() != MASTER_NODE_TYPE or node_type != MASTER_NODE_TYPE:
# Error. This node uses the same server address as a master
# node.
conn.answer(protocol.protocolError(
'invalid server address'), packet)
conn.abort()
return
raise protocol.ProtocolError('invalid server address')
node.setUUID(uuid)
if node.getState() != RUNNING_STATE:
node.setState(RUNNING_STATE)
......@@ -153,36 +147,28 @@ class VerificationEventHandler(MasterEventHandler):
# This node has a different UUID.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.answer(protocol.protocolError(
'invalid server address'), packet)
conn.abort()
return
else:
# Otherwise, forget the old one.
node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node)
# And insert a new one.
node.setUUID(uuid)
node.setState(RUNNING_STATE)
app.broadcastNodeInformation(node)
else:
# I know this node by the UUID.
if node.getServer() != addr:
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
conn.answer(protocol.protocolError(
'invalid server address'), packet)
conn.abort()
return
else:
raise protocol.ProtocolError('invalid server address')
# Otherwise, forget the old one.
node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node)
# And insert a new one.
node.setServer(addr)
node.setUUID(uuid)
node.setState(RUNNING_STATE)
app.broadcastNodeInformation(node)
else:
# I know this node by the UUID.
if node.getServer() != addr:
# This node has a different server address.
if node.getState() == RUNNING_STATE:
# If it is still running, reject this node.
raise protocol.ProtocolError('invalid server address')
# Otherwise, forget the old one.
node.setState(BROKEN_STATE)
app.broadcastNodeInformation(node)
# And insert a new one.
node.setServer(addr)
node.setState(RUNNING_STATE)
app.broadcastNodeInformation(node)
else:
# If this node is broken, reject it. Otherwise, assume that it is
# working again.
......
......@@ -139,10 +139,7 @@ class OperationEventHandler(StorageEventHandler):
app = self.app
if name != app.name:
logging.error('reject an alien cluster')
p = protocol.protocolError('invalid cluster name')
conn.answer(p, packet)
conn.abort()
return
raise protocol.ProtocolError('invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByUUID(uuid)
......@@ -319,8 +316,7 @@ class OperationEventHandler(StorageEventHandler):
# This method is complicated, because I must return TIDs only
# about usable partitions assigned to me.
if first >= last:
conn.answer(protocol.protocolError( 'invalid offsets'), packet)
return
raise protocol.ProtocolError('invalid offsets')
app = self.app
......@@ -342,8 +338,7 @@ class OperationEventHandler(StorageEventHandler):
def handleAskObjectHistory(self, conn, packet, oid, first, last):
if first >= last:
conn.answer(protocol.protocolError( 'invalid offsets'), packet)
return
raise protocol.ProtocolError( 'invalid offsets')
app = self.app
history_list = app.dm.getObjectHistory(oid, first, last - first)
......@@ -432,8 +427,7 @@ class OperationEventHandler(StorageEventHandler):
# This method is complicated, because I must return OIDs only
# about usable partitions assigned to me.
if first >= last:
conn.answer(protocol.protocolError( 'invalid offsets'), packet)
return
raise protocol.ProtocolError('invalid offsets')
app = self.app
......
......@@ -51,6 +51,10 @@ class StorageOperationTests(unittest.TestCase):
return min(ptids), max(ptids)
ptid = min(ptids)
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
def checkUnexpectedPacketRaised(self, method, *args, **kwargs):
""" Check if the UnexpectedPacketError exception wxas raised """
self.assertRaises(protocol.UnexpectedPacketError, method, *args, **kwargs)
......@@ -360,7 +364,8 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.master_port),
})
count = len(self.app.nm.getNodeList())
self.operation.handleRequestNodeIdentification(
self.checkProtocolErrorRaised(
self.operation.handleRequestNodeIdentification,
conn=conn,
packet=packet,
node_type=MASTER_NODE_TYPE,
......@@ -368,7 +373,6 @@ server: 127.0.0.1:10020
ip_address='127.0.0.1',
port=self.master_port,
name='INVALID_NAME')
self.checkCalledAbort(conn)
self.assertEquals(len(self.app.nm.getNodeList()), count)
def test_09_handleRequestNodeIdentification3(self):
......@@ -803,11 +807,9 @@ server: 127.0.0.1:10020
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=ASK_TIDS)
self.operation.handleAskTIDs(conn, packet, 1, 1, None)
self.checkPacket(conn, packet_type=ERROR)
self.checkProtocolErrorRaised(self.operation.handleAskTIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getTIDList')), 0)
def test_25_handleAskTIDs2(self):
# well case => answer
......@@ -848,8 +850,7 @@ server: 127.0.0.1:10020
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=ASK_OBJECT_HISTORY)
self.operation.handleAskObjectHistory(conn, packet, 1, 1, None)
self.checkPacket(conn, packet_type=ERROR)
self.checkProtocolErrorRaised(self.operation.handleAskObjectHistory, conn, packet, 1, 1, None)
self.assertEquals(len(app.dm.mockGetNamedCalls('getObjectHistory')), 0)
def test_26_handleAskObjectHistory2(self):
......@@ -1059,8 +1060,7 @@ server: 127.0.0.1:10020
app.dm = Mock()
conn = Mock({})
packet = Packet(msg_type=ASK_OIDS)
self.operation.handleAskOIDs(conn, packet, 1, 1, None)
self.checkPacket(conn, packet_type=ERROR)
self.checkProtocolErrorRaised(self.operation.handleAskOIDs, conn, packet, 1, 1, None)
self.assertEquals(len(app.pt.mockGetNamedCalls('getCellList')), 0)
self.assertEquals(len(app.dm.mockGetNamedCalls('getOIDList')), 0)
......
......@@ -127,6 +127,10 @@ server: 127.0.0.1:10020
return min(ptids), max(ptids)
ptid = min(ptids)
def checkProtocolErrorRaised(self, method, *args, **kwargs):
""" Check if the ProtocolError exception was raised """
self.assertRaises(protocol.ProtocolError, method, *args, **kwargs)
def checkUnexpectedPacketRaised(self, method, *args, **kwargs):
""" Check if the UnexpectedPacketError exception wxas raised """
self.assertRaises(protocol.UnexpectedPacketError, method, *args, **kwargs)
......@@ -256,9 +260,9 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.master_port),
"isServerConnection" : True})
p = Packet(msg_type=REQUEST_NODE_IDENTIFICATION)
self.verification.handleRequestNodeIdentification(conn, p, MASTER_NODE_TYPE,
uuid, "127.0.0.1", self.client_port, "zatt")
self.checkCalledAbort(conn)
self.checkProtocolErrorRaised(
self.verification.handleRequestNodeIdentification,
conn, p, MASTER_NODE_TYPE, uuid, "127.0.0.1", self.client_port, "zatt")
# new node
uuid = self.getNewUUID()
......
......@@ -72,10 +72,7 @@ class VerificationEventHandler(StorageEventHandler):
raise protocol.NotReadyError
if name != app.name:
logging.error('reject an alien cluster')
conn.answer(protocol.protocolError(
'invalid cluster name'), packet)
conn.abort()
return
raise protocol.ProtocolError('invalid cluster name')
addr = (ip_address, port)
node = app.nm.getNodeByServer(addr)
......@@ -137,9 +134,7 @@ class VerificationEventHandler(StorageEventHandler):
pass
row_list.append((offset, row))
except IndexError:
p = protocol.protocolError( 'invalid partition table offset')
conn.answer(p, packer)
return
raise protocol.ProtocolError('invalid partition table offset')
p = protocol.answerPartitionTable(app.ptid, row_list)
conn.answer(p, packet)
......
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