Instead of hardcode to ToStdout in the helper class, we should use
a user provided feedback function. In unittests this is a noop.
Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
@ivar success: Indicates if all action_cb calls were successful
"""
@ivar success: Indicates if all action_cb calls were successful
"""
- def __init__(self, node_list, action_cb, node2ip, port,
+ def __init__(self, node_list, action_cb, node2ip, port, feedback_fn,
_ping_fn=netutils.TcpPing, _sleep_fn=time.sleep):
"""Init the object.
_ping_fn=netutils.TcpPing, _sleep_fn=time.sleep):
"""Init the object.
@type node2ip: dict
@param node2ip: Node to ip mapping
@param port: The port to use for the TCP ping
@type node2ip: dict
@param node2ip: Node to ip mapping
@param port: The port to use for the TCP ping
+ @param feedback_fn: The function used for feedback
@param _ping_fn: Function to check reachabilty (for unittest use only)
@param _sleep_fn: Function to sleep (for unittest use only)
@param _ping_fn: Function to check reachabilty (for unittest use only)
@param _sleep_fn: Function to sleep (for unittest use only)
self.success = True
self.action_cb = action_cb
self.port = port
self.success = True
self.action_cb = action_cb
self.port = port
+ self.feedback_fn = feedback_fn
self._ping_fn = _ping_fn
self._sleep_fn = _sleep_fn
self._ping_fn = _ping_fn
self._sleep_fn = _sleep_fn
for node in self.down:
if self._ping_fn(self.node2ip[node], self.port, timeout=_EPO_PING_TIMEOUT,
live_port_needed=True):
for node in self.down:
if self._ping_fn(self.node2ip[node], self.port, timeout=_EPO_PING_TIMEOUT,
live_port_needed=True):
- ToStdout("Node %s became available", node)
+ self.feedback_fn("Node %s became available" % node)
self.up.add(node)
self.down -= self.up
# If we have a node available there is the possibility to run the
self.up.add(node)
self.down -= self.up
# If we have a node available there is the possibility to run the
for node in node_list)
port = netutils.GetDaemonPort(constants.NODED)
for node in node_list)
port = netutils.GetDaemonPort(constants.NODED)
- helper = _RunWhenNodesReachableHelper(node_list, action_cb, node2ip, port)
+ helper = _RunWhenNodesReachableHelper(node_list, action_cb, node2ip, port,
+ ToStdout)
try:
return utils.Retry(helper, interval, _EPO_REACHABLE_TIMEOUT,
try:
return utils.Retry(helper, interval, _EPO_REACHABLE_TIMEOUT,
self.assert_(secs >= 0 and secs <= 5)
return
self.assert_(secs >= 0 and secs <= 5)
return
+ def _NoopFeedback(self, text):
+ return
+
def testPingFnRemoveHostsUp(self):
seen = set()
def _FakeSeenPing(ip, *args, **kwargs):
def testPingFnRemoveHostsUp(self):
seen = set()
def _FakeSeenPing(ip, *args, **kwargs):
helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes,
self._FakeAction,
helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes,
self._FakeAction,
+ self.nodes2ip, 0,
+ self._NoopFeedback,
_ping_fn=_FakeSeenPing,
_sleep_fn=self._FakeSleep)
_ping_fn=_FakeSeenPing,
_sleep_fn=self._FakeSleep)
return called
helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes, _FalseAction,
return called
helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes, _FalseAction,
+ self.nodes2ip, 0,
+ self._NoopFeedback,
_ping_fn=self._FakePing,
_sleep_fn=self._FakeSleep)
for _ in self.nodes:
_ping_fn=self._FakePing,
_sleep_fn=self._FakeSleep)
for _ in self.nodes: