From: Ihar Hrachyshka Date: Thu, 12 Feb 2015 12:51:21 +0000 (+0100) Subject: Don't monkey patch netns_cleanup X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=81ea614570397fbe0722060d3faa703e7ded9151;p=openstack-build%2Fneutron-build.git Don't monkey patch netns_cleanup 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 --- diff --git a/neutron/cmd/netns_cleanup.py b/neutron/cmd/netns_cleanup.py index 8dcf2978f..cffaa55b4 100644 --- a/neutron/cmd/netns_cleanup.py +++ b/neutron/cmd/netns_cleanup.py @@ -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) diff --git a/neutron/tests/unit/test_netns_cleanup.py b/neutron/tests/unit/test_netns_cleanup.py index 9ca96c3ce..fd7fbcc6c 100644 --- a/neutron/tests/unit/test_netns_cleanup.py +++ b/neutron/tests/unit/test_netns_cleanup.py @@ -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)