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):
# Loop until a connection is obtained.
while 1:
logging.info('trying to connect to %s', node)
app.local_var.node_not_ready = 0
app.setNodeReady()
conn = MTClientConnection(app.em, app.handler, addr,
connector_handler=app.connector_handler)
conn.lock()
......@@ -100,13 +100,13 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node)
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
logging.info('Storage node %s not ready', node)
return None
else:
logging.info('connected to storage node %s', node)
return conn
sleep(1)
......@@ -931,7 +931,7 @@ class Application(object):
# Make application execute remaining message if any
self._waitMessage()
while 1:
self.local_var.node_not_ready = 0
self.setNodeReady()
if self.primary_master_node is None:
# Try with master node defined in config
try:
......@@ -975,7 +975,7 @@ class Application(object):
elif self.primary_master_node.getServer() != (addr, port):
# Master node changed, connect to new one
break
elif self.local_var.node_not_ready:
elif not self.isNodeReady():
# Wait a bit and reask again
break
elif self.pt is not None and self.pt.operational():
......@@ -990,3 +990,13 @@ class Application(object):
self.master_conn = conn
finally:
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):
def handleNotReady(self, conn, packet, message):
app = self.app
app.local_var.node_not_ready = 1
app.setNodeNotReady()
def handleAcceptNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port,
......
......@@ -215,16 +215,12 @@ class ClientEventHandlerTest(unittest.TestCase):
self._testStorageWithMethod(self._testPeerBroken, state=BROKEN_STATE)
def test_notReady(self):
class FakeLocal:
node_not_ready = None
class App:
local_var = FakeLocal()
app = App()
app = Mock({'setNodeNotReady': None})
dispatcher = self.getDispatcher()
client_handler = ClientAnswerEventHandler(app, dispatcher)
conn = self.getConnection()
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):
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