]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove is_active property from SimpleInterfaceMonitor
authorrossella <rsblendido@suse.com>
Thu, 23 Apr 2015 22:57:18 +0000 (22:57 +0000)
committerrossella <rsblendido@suse.com>
Wed, 29 Apr 2015 22:39:10 +0000 (22:39 +0000)
is_active property from SimpleInterfaceMonitor shadows
the method is_active inherited from AsyncProcess.
The property checks that ovsdb monitor is running and
that it received some data. When ovsdb monitor starts
it always receives data, since it processes the interfaces
present on the machine, so the flag data_received will
always be set to true right after SimpleInterfaceMonitor
starts. Considering that, is_active can be removed and
the method is_active inherited from AsyncProcess can be
used instead.

Change-Id: I05faeddd061ab45af51c044a10462c3a57593d4d

neutron/agent/linux/ovsdb_monitor.py
neutron/tests/functional/agent/linux/test_ovsdb_monitor.py
neutron/tests/unit/agent/linux/test_ovsdb_monitor.py

index 02f45f6b1b93c3cb5ae26c5c8e7703045e13d1f6..7e0ef251184e2d5dc52bbb511ede307b93f97f42 100644 (file)
@@ -69,12 +69,6 @@ class SimpleInterfaceMonitor(OvsdbMonitor):
         )
         self.data_received = False
 
-    @property
-    def is_active(self):
-        return (self.data_received and
-                self._kill_event and
-                not self._kill_event.ready())
-
     @property
     def has_updates(self):
         """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
         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):
         super(SimpleInterfaceMonitor, self).start()
         if block:
             with eventlet.timeout.Timeout(timeout):
-                while not self.is_active:
+                while not self.is_active():
                     eventlet.sleep()
 
     def _kill(self, *args, **kwargs):
index d1de2068f9d7ee84e667618bdbaaed7a133b2903..58ca74db5f72030515f1ae090721af725ab78b6f 100644 (file)
@@ -102,6 +102,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')
         self.assertFalse(self.monitor.has_updates,
index bf13fd4d851a923dd47a949728bd675dee667131..9b8b97687060f31cc9579ea6736abadc50aeaa01 100644 (file)
@@ -12,7 +12,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import eventlet.event
 import mock
 
 from neutron.agent.linux import ovsdb_monitor
@@ -56,22 +55,13 @@ class TestSimpleInterfaceMonitor(base.BaseTestCase):
         super(TestSimpleInterfaceMonitor, self).setUp()
         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):
         self.assertTrue(self.monitor.has_updates)
 
     def test_has_updates_is_false_if_active_with_no_output(self):
         target = ('neutron.agent.linux.ovsdb_monitor.SimpleInterfaceMonitor'
                   '.is_active')
-        with mock.patch(target,
-                        new_callable=mock.PropertyMock(return_value=True)):
+        with mock.patch(target, return_value=True):
             self.assertFalse(self.monitor.has_updates)
 
     def test__kill_sets_data_received_to_false(self):