Merge "Remove is_active property from SimpleInterfaceMonitor"

This commit is contained in:
Jenkins 2015-05-03 10:20:07 +00:00 committed by Gerrit Code Review
commit 2921d3c686
3 changed files with 4 additions and 19 deletions

View File

@ -69,12 +69,6 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
) )
self.data_received = False self.data_received = False
@property
def is_active(self):
return (self.data_received and
self._kill_event and
not self._kill_event.ready())
@property @property
def has_updates(self): def has_updates(self):
"""Indicate whether the ovsdb Interface table has been updated. """Indicate whether the ovsdb Interface table has been updated.
@ -84,13 +78,13 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
the absence of updates at the expense of potential false the absence of updates at the expense of potential false
positives. positives.
""" """
return bool(list(self.iter_stdout())) or not self.is_active return bool(list(self.iter_stdout())) or not self.is_active()
def start(self, block=False, timeout=5): def start(self, block=False, timeout=5):
super(SimpleInterfaceMonitor, self).start() super(SimpleInterfaceMonitor, self).start()
if block: if block:
with eventlet.timeout.Timeout(timeout): with eventlet.timeout.Timeout(timeout):
while not self.is_active: while not self.is_active():
eventlet.sleep() eventlet.sleep()
def _kill(self, *args, **kwargs): def _kill(self, *args, **kwargs):

View File

@ -102,6 +102,7 @@ class TestSimpleInterfaceMonitor(BaseMonitorTest):
self.monitor.start(block=True, timeout=timeout) self.monitor.start(block=True, timeout=timeout)
def test_has_updates(self): def test_has_updates(self):
utils.wait_until_true(lambda: self.monitor.data_received is True)
self.assertTrue(self.monitor.has_updates, self.assertTrue(self.monitor.has_updates,
'Initial call should always be true') 'Initial call should always be true')
self.assertFalse(self.monitor.has_updates, self.assertFalse(self.monitor.has_updates,

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import eventlet.event
import mock import mock
from neutron.agent.linux import ovsdb_monitor from neutron.agent.linux import ovsdb_monitor
@ -56,22 +55,13 @@ class TestSimpleInterfaceMonitor(base.BaseTestCase):
super(TestSimpleInterfaceMonitor, self).setUp() super(TestSimpleInterfaceMonitor, self).setUp()
self.monitor = ovsdb_monitor.SimpleInterfaceMonitor() self.monitor = ovsdb_monitor.SimpleInterfaceMonitor()
def test_is_active_is_false_by_default(self):
self.assertFalse(self.monitor.is_active)
def test_is_active_can_be_true(self):
self.monitor.data_received = True
self.monitor._kill_event = eventlet.event.Event()
self.assertTrue(self.monitor.is_active)
def test_has_updates_is_true_by_default(self): def test_has_updates_is_true_by_default(self):
self.assertTrue(self.monitor.has_updates) self.assertTrue(self.monitor.has_updates)
def test_has_updates_is_false_if_active_with_no_output(self): def test_has_updates_is_false_if_active_with_no_output(self):
target = ('neutron.agent.linux.ovsdb_monitor.SimpleInterfaceMonitor' target = ('neutron.agent.linux.ovsdb_monitor.SimpleInterfaceMonitor'
'.is_active') '.is_active')
with mock.patch(target, with mock.patch(target, return_value=True):
new_callable=mock.PropertyMock(return_value=True)):
self.assertFalse(self.monitor.has_updates) self.assertFalse(self.monitor.has_updates)
def test__kill_sets_data_received_to_false(self): def test__kill_sets_data_received_to_false(self):