]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Don't monkey patch netns_cleanup
authorIhar Hrachyshka <ihrachys@redhat.com>
Thu, 12 Feb 2015 12:51:21 +0000 (13:51 +0100)
committerIhar Hrachyshka <ihrachys@redhat.com>
Wed, 18 Feb 2015 12:33:57 +0000 (13:33 +0100)
There is no reason to monkey patch the tool (it does not rely on any
special kind of model of concurrency). It's better to avoid eventlet
wherever possible, and there are discussions on whether we want to start
dropping eventlet usage agent by agent, so it's worth keeping as much of
code out of monkey business.

Related-Bug: #1418541
Change-Id: I1c1bb5a23e191da660efe9d4179ffaf5fec647f9

neutron/cmd/netns_cleanup.py
neutron/tests/unit/test_netns_cleanup.py

index 8dcf2978f373a44b7f6679ba13acb523dbcf5f2c..cffaa55b4f15e4ca93d44b8b8913faf9a55b6498 100644 (file)
@@ -14,9 +14,7 @@
 #    under the License.
 
 import re
-
-import eventlet
-eventlet.monkey_patch()
+import time
 
 from oslo_config import cfg
 from oslo_utils import importutils
@@ -179,7 +177,7 @@ def main():
                   if eligible_for_deletion(conf, ns, conf.force)]
 
     if candidates:
-        eventlet.sleep(2)
+        time.sleep(2)
 
         for namespace in candidates:
             destroy_namespace(conf, namespace, conf.force)
index 9ca96c3ce115cb28d147c575c93144f402636b71..fd7fbcc6c7d8232c29f5e0788d3ddd64e7288f56 100644 (file)
@@ -200,7 +200,7 @@ class TestNetnsCleanup(base.BaseTestCase):
         with mock.patch('neutron.agent.linux.ip_lib.IPWrapper') as ip_wrap:
             ip_wrap.get_namespaces.return_value = namespaces
 
-            with mock.patch('eventlet.sleep') as eventlet_sleep:
+            with mock.patch('time.sleep') as time_sleep:
                 conf = mock.Mock()
                 conf.force = False
                 methods_to_mock = dict(
@@ -225,14 +225,14 @@ class TestNetnsCleanup(base.BaseTestCase):
                         ip_wrap.assert_has_calls(
                             [mock.call.get_namespaces(conf.AGENT.root_helper)])
 
-                        eventlet_sleep.assert_called_once_with(2)
+                        time_sleep.assert_called_once_with(2)
 
     def test_main_no_candidates(self):
         namespaces = ['ns1', 'ns2']
         with mock.patch('neutron.agent.linux.ip_lib.IPWrapper') as ip_wrap:
             ip_wrap.get_namespaces.return_value = namespaces
 
-            with mock.patch('eventlet.sleep') as eventlet_sleep:
+            with mock.patch('time.sleep') as time_sleep:
                 conf = mock.Mock()
                 conf.force = False
                 methods_to_mock = dict(
@@ -255,4 +255,4 @@ class TestNetnsCleanup(base.BaseTestCase):
 
                         self.assertFalse(mocks['destroy_namespace'].called)
 
-                        self.assertFalse(eventlet_sleep.called)
+                        self.assertFalse(time_sleep.called)