Commit 8311463f authored by Vincent Pelletier's avatar Vincent Pelletier

Define and use accessors to replace direct access to App's local_var.node_not_ready .

Update test.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@359 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent d3dc0ddc
...@@ -73,7 +73,7 @@ class ConnectionPool(object): ...@@ -73,7 +73,7 @@ class ConnectionPool(object):
# Loop until a connection is obtained. # Loop until a connection is obtained.
while 1: while 1:
logging.info('trying to connect to %s', node) logging.info('trying to connect to %s', node)
app.local_var.node_not_ready = 0 app.setNodeReady()
conn = MTClientConnection(app.em, app.handler, addr, conn = MTClientConnection(app.em, app.handler, addr,
connector_handler=app.connector_handler) connector_handler=app.connector_handler)
conn.lock() conn.lock()
...@@ -100,13 +100,13 @@ class ConnectionPool(object): ...@@ -100,13 +100,13 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node) logging.error('Connection to storage node %s failed', node)
return None return None
if app.local_var.node_not_ready: if app.isNodeReady():
logging.info('connected to storage node %s', node)
return conn
else:
# Connection failed, notify primary master node # Connection failed, notify primary master node
logging.info('Storage node %s not ready', node) logging.info('Storage node %s not ready', node)
return None return None
else:
logging.info('connected to storage node %s', node)
return conn
sleep(1) sleep(1)
...@@ -931,7 +931,7 @@ class Application(object): ...@@ -931,7 +931,7 @@ class Application(object):
# Make application execute remaining message if any # Make application execute remaining message if any
self._waitMessage() self._waitMessage()
while 1: while 1:
self.local_var.node_not_ready = 0 self.setNodeReady()
if self.primary_master_node is None: if self.primary_master_node is None:
# Try with master node defined in config # Try with master node defined in config
try: try:
...@@ -975,7 +975,7 @@ class Application(object): ...@@ -975,7 +975,7 @@ class Application(object):
elif self.primary_master_node.getServer() != (addr, port): elif self.primary_master_node.getServer() != (addr, port):
# Master node changed, connect to new one # Master node changed, connect to new one
break break
elif self.local_var.node_not_ready: elif not self.isNodeReady():
# Wait a bit and reask again # Wait a bit and reask again
break break
elif self.pt is not None and self.pt.operational(): elif self.pt is not None and self.pt.operational():
...@@ -990,3 +990,13 @@ class Application(object): ...@@ -990,3 +990,13 @@ class Application(object):
self.master_conn = conn self.master_conn = conn
finally: finally:
self._connecting_to_master_node_release() self._connecting_to_master_node_release()
def setNodeReady(self):
self.local_var.node_ready = True
def setNodeNotReady(self):
self.local_var.node_ready = False
def isNodeReady(self):
return self.local_var.node_ready
...@@ -311,7 +311,7 @@ class ClientAnswerEventHandler(BaseClientEventHandler): ...@@ -311,7 +311,7 @@ class ClientAnswerEventHandler(BaseClientEventHandler):
def handleNotReady(self, conn, packet, message): def handleNotReady(self, conn, packet, message):
app = self.app app = self.app
app.local_var.node_not_ready = 1 app.setNodeNotReady()
def handleAcceptNodeIdentification(self, conn, packet, node_type, def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, uuid, ip_address, port,
......
...@@ -215,16 +215,12 @@ class ClientEventHandlerTest(unittest.TestCase): ...@@ -215,16 +215,12 @@ class ClientEventHandlerTest(unittest.TestCase):
self._testStorageWithMethod(self._testPeerBroken, state=BROKEN_STATE) self._testStorageWithMethod(self._testPeerBroken, state=BROKEN_STATE)
def test_notReady(self): def test_notReady(self):
class FakeLocal: app = Mock({'setNodeNotReady': None})
node_not_ready = None
class App:
local_var = FakeLocal()
app = App()
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher) client_handler = ClientAnswerEventHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotReady(conn, None, None) client_handler.handleNotReady(conn, None, None)
self.assertEquals(app.local_var.node_not_ready, 1) self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1)
def test_clientAcceptNodeIdentification(self): def test_clientAcceptNodeIdentification(self):
class App: class App:
......
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