Revision 506be7c5
b/lib/utils.py | ||
---|---|---|
2499 | 2499 |
"""Retry loop timed out. |
2500 | 2500 |
|
2501 | 2501 |
""" |
2502 |
def RaiseInner(self): |
|
2503 |
if self.args and isinstance(self.args[0], Exception): |
|
2504 |
raise self.args[0] |
|
2505 |
else: |
|
2506 |
raise RetryTimeout(*self.args) |
|
2502 | 2507 |
|
2503 | 2508 |
|
2504 | 2509 |
class RetryAgain(Exception): |
... | ... | |
2612 | 2617 |
assert calc_delay is None or callable(calc_delay) |
2613 | 2618 |
|
2614 | 2619 |
while True: |
2620 |
retry_args = [] |
|
2615 | 2621 |
try: |
2616 | 2622 |
# pylint: disable-msg=W0142 |
2617 | 2623 |
return fn(*args) |
2618 |
except RetryAgain: |
|
2619 |
pass
|
|
2624 |
except RetryAgain, err:
|
|
2625 |
retry_args = err.args
|
|
2620 | 2626 |
except RetryTimeout: |
2621 | 2627 |
raise errors.ProgrammerError("Nested retry loop detected that didn't" |
2622 | 2628 |
" handle RetryTimeout") |
... | ... | |
2624 | 2630 |
remaining_time = end_time - _time_fn() |
2625 | 2631 |
|
2626 | 2632 |
if remaining_time < 0.0: |
2627 |
raise RetryTimeout() |
|
2633 |
# pylint: disable-msg=W0142 |
|
2634 |
raise RetryTimeout(*retry_args) |
|
2628 | 2635 |
|
2629 | 2636 |
assert remaining_time >= 0.0 |
2630 | 2637 |
|
b/test/ganeti.utils_unittest.py | ||
---|---|---|
1612 | 1612 |
def _RaiseRetryAgain(): |
1613 | 1613 |
raise utils.RetryAgain() |
1614 | 1614 |
|
1615 |
@staticmethod |
|
1616 |
def _RaiseRetryAgainWithArg(args): |
|
1617 |
raise utils.RetryAgain(*args) |
|
1618 |
|
|
1615 | 1619 |
def _WrongNestedLoop(self): |
1616 | 1620 |
return utils.Retry(self._RaiseRetryAgain, 0.01, 0.02) |
1617 | 1621 |
|
... | ... | |
1642 | 1646 |
except utils.RetryTimeout: |
1643 | 1647 |
self.fail("Didn't detect inner loop's exception") |
1644 | 1648 |
|
1649 |
def testTimeoutArgument(self): |
|
1650 |
retry_arg="my_important_debugging_message" |
|
1651 |
try: |
|
1652 |
utils.Retry(self._RaiseRetryAgainWithArg, 0.01, 0.02, args=[[retry_arg]]) |
|
1653 |
except utils.RetryTimeout, err: |
|
1654 |
self.failUnlessEqual(err.args, (retry_arg, )) |
|
1655 |
else: |
|
1656 |
self.fail("Expected timeout didn't happen") |
|
1657 |
|
|
1658 |
def testRaiseInnerWithExc(self): |
|
1659 |
retry_arg="my_important_debugging_message" |
|
1660 |
try: |
|
1661 |
try: |
|
1662 |
utils.Retry(self._RaiseRetryAgainWithArg, 0.01, 0.02, |
|
1663 |
args=[[errors.GenericError(retry_arg, retry_arg)]]) |
|
1664 |
except utils.RetryTimeout, err: |
|
1665 |
err.RaiseInner() |
|
1666 |
else: |
|
1667 |
self.fail("Expected timeout didn't happen") |
|
1668 |
except errors.GenericError, err: |
|
1669 |
self.failUnlessEqual(err.args, (retry_arg, retry_arg)) |
|
1670 |
else: |
|
1671 |
self.fail("Expected GenericError didn't happen") |
|
1672 |
|
|
1673 |
def testRaiseInnerWithMsg(self): |
|
1674 |
retry_arg="my_important_debugging_message" |
|
1675 |
try: |
|
1676 |
try: |
|
1677 |
utils.Retry(self._RaiseRetryAgainWithArg, 0.01, 0.02, |
|
1678 |
args=[[retry_arg, retry_arg]]) |
|
1679 |
except utils.RetryTimeout, err: |
|
1680 |
err.RaiseInner() |
|
1681 |
else: |
|
1682 |
self.fail("Expected timeout didn't happen") |
|
1683 |
except utils.RetryTimeout, err: |
|
1684 |
self.failUnlessEqual(err.args, (retry_arg, retry_arg)) |
|
1685 |
else: |
|
1686 |
self.fail("Expected RetryTimeout didn't happen") |
|
1687 |
|
|
1645 | 1688 |
|
1646 | 1689 |
class TestLineSplitter(unittest.TestCase): |
1647 | 1690 |
def test(self): |
Also available in: Unified diff