From dfd495188981697f5c2ad5551d196fc2f859cd6e Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 23 Feb 2017 03:46:59 +0000 Subject: [PATCH] Untangle WaitTimeout class from eventlet.TimeoutError This simplifies test code a bit. Previously, we introduced the WaitTimeout class to replace the eventlet.TimeoutError that inherited from BaseException and hence could interrupt normal test worker run. Now that we were initiating deprecation warning messages for a cycle when the user relied on eventlet.TimeoutError, we should be ok to remove the parent class from the list of inheritance for WaitTimeout. Change-Id: I6160cc1408f72a9f847a59702bc74b8e52a10497 --- neutron/common/utils.py | 33 ++++--------------- neutron/tests/functional/common/test_utils.py | 14 -------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/neutron/common/utils.py b/neutron/common/utils.py index c7d60d45f0a..20819564bd4 100644 --- a/neutron/common/utils.py +++ b/neutron/common/utils.py @@ -29,7 +29,6 @@ import time import uuid import weakref -import debtcollector from debtcollector import removals import eventlet from eventlet.green import subprocess @@ -58,20 +57,8 @@ SYNCHRONIZED_PREFIX = 'neutron-' synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX) -class WaitTimeout(Exception, eventlet.TimeoutError): - """Default exception coming from wait_until_true() function. - - The reason is that eventlet.TimeoutError inherits from BaseException and - testtools.TestCase consumes only Exceptions. Which means in case - TimeoutError is raised, test runner stops and exits while it still has test - cases scheduled for execution. - """ - - def __str__(self): - return Exception.__str__(self) - - def __repr__(self): - return Exception.__repr__(self) +class WaitTimeout(Exception): + """Default exception coming from wait_until_true() function.""" @removals.remove( @@ -669,18 +656,10 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None): while not predicate(): eventlet.sleep(sleep) except eventlet.TimeoutError: - if exception is None: - debtcollector.deprecate( - "Raising eventlet.TimeoutError by default has been deprecated", - message="wait_until_true() now raises WaitTimeout error by " - "default.", - version="Ocata", - removal_version="Pike") - exception = WaitTimeout("Timed out after %d seconds" % timeout) - #NOTE(jlibosva): In case None is passed exception is instantiated on - # the line above. - #pylint: disable=raising-bad-type - raise exception + if exception is not None: + #pylint: disable=raising-bad-type + raise exception + raise WaitTimeout("Timed out after %d seconds" % timeout) class _AuthenticBase(object): diff --git a/neutron/tests/functional/common/test_utils.py b/neutron/tests/functional/common/test_utils.py index 7e7713c07a4..c0043f50342 100644 --- a/neutron/tests/functional/common/test_utils.py +++ b/neutron/tests/functional/common/test_utils.py @@ -12,8 +12,6 @@ import testtools -import eventlet - from neutron.common import utils from neutron.tests import base @@ -25,15 +23,3 @@ class TestWaitUntilTrue(base.BaseTestCase): def test_wait_until_true_predicate_fails(self): with testtools.ExpectedException(utils.WaitTimeout): utils.wait_until_true(lambda: False, 2) - - def test_wait_until_true_predicate_fails_compatibility_test(self): - """This test makes sure that eventlet.TimeoutError can still be caught. - """ - try: - utils.wait_until_true(lambda: False, 2) - except eventlet.TimeoutError: - return - except Exception: - pass - self.fail('wait_until_true() does not raise eventlet.TimeoutError ' - 'compatible exception by default.')