From fdf0fa8b43537bbd5ab6e1a2e55f694b77209a00 Mon Sep 17 00:00:00 2001 From: John Schwarz Date: Thu, 4 Sep 2014 11:34:29 +0300 Subject: [PATCH] Fix leftover Timeout effecting most eventlet calls When registering a new eventlet.timeout.Timeout object, eventlet automatically starts a timer for most (if not all) future eventlet calls. Normally, eventlet codes do not hold a timeout unless such a timeout is used or a specific timeout length is specified through the API, but once a Timeout object is initialized, it is left there unless canceled. This change fixes an un-canceled Timeout which causes some functional tests to fail, reintroduces a fix for bug #1358206, which was written prior to discovering the uncanceled timeout, and increases the timeout of a test that depended on this timeout. Closes-bug: #1358206 Related-bug: #1364171 Change-Id: I1bfc5af6917c525894eecd8b477d787763edbd02 --- neutron/agent/linux/ovsdb_monitor.py | 13 ++++--------- .../functional/agent/linux/test_ovsdb_monitor.py | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/neutron/agent/linux/ovsdb_monitor.py b/neutron/agent/linux/ovsdb_monitor.py index c49bdc5f191..520865ce735 100644 --- a/neutron/agent/linux/ovsdb_monitor.py +++ b/neutron/agent/linux/ovsdb_monitor.py @@ -69,10 +69,6 @@ class SimpleInterfaceMonitor(OvsdbMonitor): respawn_interval=respawn_interval, ) self.data_received = False - if respawn_interval: - self._default_timeout = respawn_interval / 2 - else: - self._default_timeout = 10 @property def is_active(self): @@ -91,13 +87,12 @@ class SimpleInterfaceMonitor(OvsdbMonitor): """ return bool(list(self.iter_stdout())) or not self.is_active - def start(self, block=False, timeout=None): - timeout = timeout or self._default_timeout + def start(self, block=False, timeout=5): super(SimpleInterfaceMonitor, self).start() if block: - eventlet.timeout.Timeout(timeout) - while not self.is_active: - eventlet.sleep() + with eventlet.timeout.Timeout(timeout): + while not self.is_active: + eventlet.sleep() def _kill(self, *args, **kwargs): self.data_received = False diff --git a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py index 3f37ce0edc4..7d6131ca97c 100644 --- a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py +++ b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py @@ -96,7 +96,7 @@ class TestSimpleInterfaceMonitor(BaseMonitorTest): self.monitor = ovsdb_monitor.SimpleInterfaceMonitor( root_helper=self.root_helper) self.addCleanup(self.monitor.stop) - self.monitor.start(block=True) + self.monitor.start(block=True, timeout=60) def test_has_updates(self): self.assertTrue(self.monitor.has_updates,