Commit 7331764e authored by Vincent Pelletier's avatar Vincent Pelletier

Add some assertions in code.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1664 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent b89e6617
...@@ -19,6 +19,7 @@ from neo import logging ...@@ -19,6 +19,7 @@ from neo import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import NodeTypes, NodeStates, Packets from neo.protocol import NodeTypes, NodeStates, Packets
from neo.util import dump
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."""
...@@ -86,8 +87,11 @@ class BaseServiceHandler(MasterHandler): ...@@ -86,8 +87,11 @@ class BaseServiceHandler(MasterHandler):
if new_state != NodeStates.BROKEN: if new_state != NodeStates.BROKEN:
new_state = DISCONNECTED_STATE_DICT.get(node.getType(), new_state = DISCONNECTED_STATE_DICT.get(node.getType(),
NodeStates.DOWN) NodeStates.DOWN)
if node.getState() == new_state: assert new_state in (NodeStates.TEMPORARILY_DOWN, NodeStates.DOWN,
return NodeStates.BROKEN), new_state
assert node.getState() not in (NodeStates.TEMPORARILY_DOWN,
NodeStates.DOWN, NodeStates.BROKEN), (dump(self.app.uuid),
node.whoSetState(), new_state)
if new_state != NodeStates.BROKEN 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
......
...@@ -87,6 +87,7 @@ class ClientElectionHandler(ElectionHandler): ...@@ -87,6 +87,7 @@ class ClientElectionHandler(ElectionHandler):
def connectionFailed(self, conn): def connectionFailed(self, conn):
addr = conn.getAddress() addr = conn.getAddress()
node = self.app.nm.getByAddress(addr) node = self.app.nm.getByAddress(addr)
assert node is not None, (dump(self.app.uuid), addr)
assert node.isUnknown(), (dump(self.app.uuid), node.whoSetState(), assert node.isUnknown(), (dump(self.app.uuid), node.whoSetState(),
node.getState()) node.getState())
# connection never success, node is still in unknown state # connection never success, node is still in unknown state
......
...@@ -35,6 +35,7 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -35,6 +35,7 @@ class StorageServiceHandler(BaseServiceHandler):
def nodeLost(self, conn, node): def nodeLost(self, conn, node):
logging.info('storage node lost') logging.info('storage node lost')
assert not node.isRunning(), node.getState()
if not self.app.pt.operational(): if not self.app.pt.operational():
raise OperationFailure, 'cannot continue operation' raise OperationFailure, 'cannot continue operation'
# this is intentionaly placed after the raise because the last cell in a # this is intentionaly placed after the raise because the last cell in a
......
...@@ -218,7 +218,7 @@ class PartitionTable(object): ...@@ -218,7 +218,7 @@ class PartitionTable(object):
self.id = ptid self.id = ptid
for offset, uuid, state in cell_list: for offset, uuid, state in cell_list:
node = nm.getByUUID(uuid) node = nm.getByUUID(uuid)
assert node is not None assert node is not None, 'No node found for uuid %r' % (dump(uuid), )
self.setCell(offset, node, state) self.setCell(offset, node, state)
logging.debug('partition table updated') logging.debug('partition table updated')
self.log() self.log()
......
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