From a786a4edadcb939065e16dd0503c8e07412151e4 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 17 Sep 2015 15:52:29 +0200 Subject: [PATCH] SimpleInterfaceMonitor: get rid of self.data_received flag It's not used anywhere outside tests, and there are better ways to wait for updates. The flag was once used to influence the state of activeness for the monitor, but not anymore [1]. This cleanup also allows us to remove custom _read_stdout from the monitor and reuse the one inherited from AsyncProcess. Meaning, we also can safely get rid of another pile of duplicate tests. [1]: I05faeddd061ab45af51c044a10462c3a57593d4d Change-Id: I612d492c8f65a70e18f782a5e4d055de5f7948ef --- neutron/agent/linux/ovsdb_monitor.py | 11 --------- .../agent/linux/test_ovsdb_monitor.py | 6 ++--- .../unit/agent/linux/test_ovsdb_monitor.py | 24 ------------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/neutron/agent/linux/ovsdb_monitor.py b/neutron/agent/linux/ovsdb_monitor.py index feed5c3ff..0300728a3 100644 --- a/neutron/agent/linux/ovsdb_monitor.py +++ b/neutron/agent/linux/ovsdb_monitor.py @@ -60,7 +60,6 @@ class SimpleInterfaceMonitor(OvsdbMonitor): format='json', respawn_interval=respawn_interval, ) - self.data_received = False self.new_events = {'added': [], 'removed': []} @property @@ -109,13 +108,3 @@ class SimpleInterfaceMonitor(OvsdbMonitor): with eventlet.timeout.Timeout(timeout): while not self.is_active(): eventlet.sleep() - - def _kill(self, *args, **kwargs): - self.data_received = False - super(SimpleInterfaceMonitor, self)._kill(*args, **kwargs) - - def _read_stdout(self): - data = super(SimpleInterfaceMonitor, self)._read_stdout() - if data and not self.data_received: - self.data_received = True - return data diff --git a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py index c2d5db446..8fa8ed267 100644 --- a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py +++ b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py @@ -91,9 +91,7 @@ class TestSimpleInterfaceMonitor(BaseMonitorTest): self.monitor.start(block=True, timeout=timeout) def test_has_updates(self): - utils.wait_until_true(lambda: self.monitor.data_received is True) - self.assertTrue(self.monitor.has_updates, - 'Initial call should always be true') + utils.wait_until_true(lambda: self.monitor.has_updates) # clear the event list self.monitor.get_events() self.useFixture(net_helpers.OVSPortFixture()) @@ -118,7 +116,7 @@ class TestSimpleInterfaceMonitor(BaseMonitorTest): return True def test_get_events(self): - utils.wait_until_true(lambda: self.monitor.data_received is True) + utils.wait_until_true(lambda: self.monitor.has_updates) devices = self.monitor.get_events() self.assertTrue(devices.get('added'), 'Initial call should always be true') diff --git a/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py b/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py index dc41c96e0..73a3a0870 100644 --- a/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py +++ b/neutron/tests/unit/agent/linux/test_ovsdb_monitor.py @@ -52,30 +52,6 @@ class TestSimpleInterfaceMonitor(base.BaseTestCase): with mock.patch(target, return_value=True): self.assertFalse(self.monitor.has_updates) - def test__kill_sets_data_received_to_false(self): - self.monitor.data_received = True - with mock.patch( - 'neutron.agent.linux.ovsdb_monitor.OvsdbMonitor._kill'): - self.monitor._kill() - self.assertFalse(self.monitor.data_received) - - def test__read_stdout_sets_data_received_and_returns_output(self): - output = 'foo' - with mock.patch( - 'neutron.agent.linux.ovsdb_monitor.OvsdbMonitor._read_stdout', - return_value=output): - result = self.monitor._read_stdout() - self.assertTrue(self.monitor.data_received) - self.assertEqual(result, output) - - def test__read_stdout_does_not_set_data_received_for_empty_ouput(self): - output = None - with mock.patch( - 'neutron.agent.linux.ovsdb_monitor.OvsdbMonitor._read_stdout', - return_value=output): - self.monitor._read_stdout() - self.assertFalse(self.monitor.data_received) - def test_has_updates_after_calling_get_events_is_false(self): with mock.patch.object( self.monitor, 'process_events') as process_events: -- 2.45.2