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
This commit is contained in:
parent
9e4627fd35
commit
a786a4edad
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue