def testPingFnRemoveHostsUp(self): seen = set() def _FakeSeenPing(ip, *args, **kwargs): node = self.ips2node[ip] self.assertFalse(node in seen) seen.add(node) return True helper = gnt_cluster._RunWhenNodesReachableHelper( self.nodes, self._FakeAction, self.nodes2ip, 0, self._NoopFeedback, _ping_fn=_FakeSeenPing, _sleep_fn=self._FakeSleep) nodes_len = len(self.nodes) for (num, _) in enumerate(self.nodes): helper.Wait(5) if num < nodes_len - 1: self.assertRaises(utils.RetryAgain, helper) else: helper() self.assertEqual(seen, self.nodes) self.assertFalse(helper.down) self.assertEqual(helper.up, self.nodes)
def testPingFnRemoveHostsUp(self): seen = set() def _FakeSeenPing(ip, *args, **kwargs): node = self.ips2node[ip] self.assertFalse(node in seen) seen.add(node) return True helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes, self._FakeAction, self.nodes2ip, 0, self._NoopFeedback, _ping_fn=_FakeSeenPing, _sleep_fn=self._FakeSleep) nodes_len = len(self.nodes) for (num, _) in enumerate(self.nodes): helper.Wait(5) if num < nodes_len - 1: self.assertRaises(utils.RetryAgain, helper) else: helper() self.assertEqual(seen, self.nodes) self.assertFalse(helper.down) self.assertEqual(helper.up, self.nodes)
def testActionReturnFalseSetsHelperFalse(self): called = False def _FalseAction(*args): 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: try: helper() except utils.RetryAgain: called = True self.assertFalse(helper.success)