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
This commit is contained in:
Ihar Hrachyshka 2015-02-12 13:51:21 +01:00
parent 3486a33994
commit 81ea614570
2 changed files with 6 additions and 8 deletions

View 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)

View 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)