From 6ca8cb84fd8f703367e1bd8ee1a2f26071116725 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Fri, 30 May 2014 15:53:25 +0200 Subject: [PATCH] Monkey patch threading module as early as possible In oslo.messaging, local thread store is used to pass RPC request context [1]. If we try to import oslo.messaging before monkey patching threading library, it attempts to access unpatched storage and fails with AttributeError. [1]: oslo/messaging/localcontext.py#L26 blueprint oslo-messaging Change-Id: Ied7302fcb1d3e14428540e39e3db704550027890 --- neutron/agent/dhcp_agent.py | 3 +- neutron/agent/l3_agent.py | 3 +- neutron/agent/metadata/agent.py | 3 +- neutron/agent/metadata/namespace_proxy.py | 3 +- neutron/agent/netns_cleanup_util.py | 4 +- .../bigswitch/agent/restproxy_agent.py | 5 +- .../hyperv/agent/hyperv_neutron_agent.py | 5 +- .../plugins/ibm/agent/sdnve_neutron_agent.py | 3 +- .../agent/linuxbridge_neutron_agent.py | 3 +- .../mlnx/agent/eswitch_neutron_agent.py | 3 +- .../plugins/nec/agent/nec_neutron_agent.py | 3 +- .../agent/nvsd_neutron_agent.py | 2 +- .../openvswitch/agent/ovs_neutron_agent.py | 3 +- .../plugins/ryu/agent/ryu_neutron_agent.py | 3 +- .../vmware/api_client/eventlet_client.py | 5 +- neutron/server/__init__.py | 6 +- .../firewall/agents/varmour/varmour_router.py | 3 +- neutron/services/loadbalancer/agent/agent.py | 3 +- .../loadbalancer/drivers/radware/driver.py | 4 +- .../metering/agents/metering_agent.py | 3 +- .../unit/hyperv/test_hyperv_neutron_agent.py | 16 ++-- neutron/tests/unit/nec/test_nec_agent.py | 4 +- .../unit/oneconvergence/test_nvsd_agent.py | 4 +- .../services/loadbalancer/agent/test_agent.py | 4 +- neutron/tests/unit/test_metadata_agent.py | 22 +++--- .../unit/test_metadata_namespace_proxy.py | 76 +++++++++---------- neutron/wsgi.py | 2 +- 27 files changed, 99 insertions(+), 99 deletions(-) diff --git a/neutron/agent/dhcp_agent.py b/neutron/agent/dhcp_agent.py index bfdbca371b1..4b62e0dd85d 100644 --- a/neutron/agent/dhcp_agent.py +++ b/neutron/agent/dhcp_agent.py @@ -18,6 +18,8 @@ import os import eventlet +eventlet.monkey_patch() + import netaddr from oslo.config import cfg @@ -607,7 +609,6 @@ def register_options(): def main(): - eventlet.monkey_patch() register_options() cfg.CONF(project='neutron') config.setup_logging(cfg.CONF) diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py index 778b947cce9..7b3df470ed8 100644 --- a/neutron/agent/l3_agent.py +++ b/neutron/agent/l3_agent.py @@ -14,6 +14,8 @@ # import eventlet +eventlet.monkey_patch() + import netaddr from oslo.config import cfg @@ -967,7 +969,6 @@ def agent_updated(self, context, payload): def main(manager='neutron.agent.l3_agent.L3NATAgentWithStateReport'): - eventlet.monkey_patch() conf = cfg.CONF conf.register_opts(L3NATAgent.OPTS) config.register_interface_driver_opts_helper(conf) diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index 83aad7c3feb..92b5fe08b22 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -22,6 +22,8 @@ import socket import eventlet +eventlet.monkey_patch() + import httplib2 from neutronclient.v2_0 import client from oslo.config import cfg @@ -377,7 +379,6 @@ def run(self): def main(): - eventlet.monkey_patch() cfg.CONF.register_opts(UnixDomainMetadataProxy.OPTS) cfg.CONF.register_opts(MetadataProxyHandler.OPTS) cache.register_oslo_configs(cfg.CONF) diff --git a/neutron/agent/metadata/namespace_proxy.py b/neutron/agent/metadata/namespace_proxy.py index 0f32328074b..e330b22cadb 100644 --- a/neutron/agent/metadata/namespace_proxy.py +++ b/neutron/agent/metadata/namespace_proxy.py @@ -20,6 +20,8 @@ import socket import eventlet +eventlet.monkey_patch() + import httplib2 from oslo.config import cfg import six.moves.urllib.parse as urlparse @@ -144,7 +146,6 @@ def run(self): def main(): - eventlet.monkey_patch() opts = [ cfg.StrOpt('network_id', help=_('Network that will have instance metadata ' diff --git a/neutron/agent/netns_cleanup_util.py b/neutron/agent/netns_cleanup_util.py index f43efd38493..c7e5915b32d 100644 --- a/neutron/agent/netns_cleanup_util.py +++ b/neutron/agent/netns_cleanup_util.py @@ -18,6 +18,8 @@ import re import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent.common import config as agent_config @@ -157,8 +159,6 @@ def main(): installation as it will blindly purge namespaces and their devices. This option also kills any lingering DHCP instances. """ - eventlet.monkey_patch() - conf = setup_conf() conf() config.setup_logging(conf) diff --git a/neutron/plugins/bigswitch/agent/restproxy_agent.py b/neutron/plugins/bigswitch/agent/restproxy_agent.py index 91d314055d7..1d42c6df860 100644 --- a/neutron/plugins/bigswitch/agent/restproxy_agent.py +++ b/neutron/plugins/bigswitch/agent/restproxy_agent.py @@ -17,10 +17,12 @@ # under the License. # @author: Kevin Benton, kevin.benton@bigswitch.com -import eventlet import sys import time +import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent.linux import ovs_lib @@ -162,7 +164,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() cfg.CONF(project='neutron') config.setup_logging(cfg.CONF) pl_config.register_config() diff --git a/neutron/plugins/hyperv/agent/hyperv_neutron_agent.py b/neutron/plugins/hyperv/agent/hyperv_neutron_agent.py index 5b6b9e9b00d..032504d484e 100644 --- a/neutron/plugins/hyperv/agent/hyperv_neutron_agent.py +++ b/neutron/plugins/hyperv/agent/hyperv_neutron_agent.py @@ -18,11 +18,13 @@ # @author: Pedro Navarro Perez # @author: Alessandro Pilotti, Cloudbase Solutions Srl -import eventlet import platform import re import time +import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent.common import config @@ -464,7 +466,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() cfg.CONF(project='neutron') logging_config.setup_logging(cfg.CONF) diff --git a/neutron/plugins/ibm/agent/sdnve_neutron_agent.py b/neutron/plugins/ibm/agent/sdnve_neutron_agent.py index 03b419ceea3..dea26bdbd5a 100644 --- a/neutron/plugins/ibm/agent/sdnve_neutron_agent.py +++ b/neutron/plugins/ibm/agent/sdnve_neutron_agent.py @@ -21,6 +21,8 @@ import time import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent.linux import ip_lib @@ -252,7 +254,6 @@ def create_agent_config_map(config): def main(): - eventlet.monkey_patch() cfg.CONF.register_opts(ip_lib.OPTS) cfg.CONF(project='neutron') logging_config.setup_logging(cfg.CONF) diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index 5e5c1524362..5d215791a65 100755 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -27,6 +27,8 @@ import time import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent import l2population_rpc as l2pop_rpc @@ -1025,7 +1027,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() cfg.CONF(project='neutron') logging_config.setup_logging(cfg.CONF) diff --git a/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py b/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py index 35bc015f07e..00ffdd6fdb8 100644 --- a/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py +++ b/neutron/plugins/mlnx/agent/eswitch_neutron_agent.py @@ -21,6 +21,8 @@ import time import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent import rpc as agent_rpc @@ -417,7 +419,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() cfg.CONF(project='neutron') logging_config.setup_logging(cfg.CONF) diff --git a/neutron/plugins/nec/agent/nec_neutron_agent.py b/neutron/plugins/nec/agent/nec_neutron_agent.py index 8ce6426c394..c2d70fbfe0b 100755 --- a/neutron/plugins/nec/agent/nec_neutron_agent.py +++ b/neutron/plugins/nec/agent/nec_neutron_agent.py @@ -24,6 +24,7 @@ import time import eventlet +eventlet.monkey_patch() from neutron.agent.linux import ovs_lib from neutron.agent import rpc as agent_rpc @@ -230,8 +231,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() - config.CONF(project='neutron') logging_config.setup_logging(config.CONF) diff --git a/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py b/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py index a857cff8291..f023a578707 100644 --- a/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py +++ b/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py @@ -20,6 +20,7 @@ import time import eventlet +eventlet.monkey_patch() from neutron.agent.linux import ovs_lib from neutron.agent import rpc as agent_rpc @@ -160,7 +161,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() config.CONF(project='neutron') logging_config.setup_logging(config.CONF) diff --git a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py index 02d81bcd8b7..c0dce0620b8 100644 --- a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py @@ -19,6 +19,8 @@ import time import eventlet +eventlet.monkey_patch() + import netaddr from oslo.config import cfg from six import moves @@ -1461,7 +1463,6 @@ def create_agent_config_map(config): def main(): - eventlet.monkey_patch() cfg.CONF.register_opts(ip_lib.OPTS) cfg.CONF(project='neutron') logging_config.setup_logging(cfg.CONF) diff --git a/neutron/plugins/ryu/agent/ryu_neutron_agent.py b/neutron/plugins/ryu/agent/ryu_neutron_agent.py index 7b16f60289d..01a4fba5ea9 100755 --- a/neutron/plugins/ryu/agent/ryu_neutron_agent.py +++ b/neutron/plugins/ryu/agent/ryu_neutron_agent.py @@ -24,6 +24,8 @@ import time import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from ryu.app import client from ryu.app import conf_switch_key @@ -282,7 +284,6 @@ def daemon_loop(self): def main(): - eventlet.monkey_patch() cfg.CONF(project='neutron') logging_config.setup_logging(cfg.CONF) diff --git a/neutron/plugins/vmware/api_client/eventlet_client.py b/neutron/plugins/vmware/api_client/eventlet_client.py index 8d641ce2e8b..fa0cd1f3eb0 100644 --- a/neutron/plugins/vmware/api_client/eventlet_client.py +++ b/neutron/plugins/vmware/api_client/eventlet_client.py @@ -15,14 +15,15 @@ # under the License. # -import eventlet import time +import eventlet +eventlet.monkey_patch() + from neutron.openstack.common import log as logging from neutron.plugins.vmware.api_client import base from neutron.plugins.vmware.api_client import eventlet_request -eventlet.monkey_patch() LOG = logging.getLogger(__name__) diff --git a/neutron/server/__init__.py b/neutron/server/__init__.py index d5177cb237b..fedefa079d8 100755 --- a/neutron/server/__init__.py +++ b/neutron/server/__init__.py @@ -18,9 +18,11 @@ # If ../neutron/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... -import eventlet import sys +import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.common import config @@ -34,8 +36,6 @@ def main(): - eventlet.monkey_patch() - # the configuration will be read into the cfg.CONF global data structure config.parse(sys.argv[1:]) if not cfg.CONF.config_file: diff --git a/neutron/services/firewall/agents/varmour/varmour_router.py b/neutron/services/firewall/agents/varmour/varmour_router.py index 4fc7c72d7c4..881127b151d 100755 --- a/neutron/services/firewall/agents/varmour/varmour_router.py +++ b/neutron/services/firewall/agents/varmour/varmour_router.py @@ -19,6 +19,8 @@ # import eventlet +eventlet.monkey_patch() + import netaddr from oslo.config import cfg @@ -327,7 +329,6 @@ class vArmourL3NATAgentWithStateReport(vArmourL3NATAgent, def main(): - eventlet.monkey_patch() conf = cfg.CONF conf.register_opts(vArmourL3NATAgent.OPTS) config.register_interface_driver_opts_helper(conf) diff --git a/neutron/services/loadbalancer/agent/agent.py b/neutron/services/loadbalancer/agent/agent.py index d9cc64658e5..0ec14554d9b 100644 --- a/neutron/services/loadbalancer/agent/agent.py +++ b/neutron/services/loadbalancer/agent/agent.py @@ -17,6 +17,8 @@ # @author: Mark McClain, DreamHost import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent.common import config @@ -47,7 +49,6 @@ def start(self): def main(): - eventlet.monkey_patch() cfg.CONF.register_opts(OPTS) cfg.CONF.register_opts(manager.OPTS) # import interface options just in case the driver uses namespaces diff --git a/neutron/services/loadbalancer/drivers/radware/driver.py b/neutron/services/loadbalancer/drivers/radware/driver.py index 7f1942562db..6bf1117d076 100644 --- a/neutron/services/loadbalancer/drivers/radware/driver.py +++ b/neutron/services/loadbalancer/drivers/radware/driver.py @@ -25,6 +25,8 @@ import eventlet +eventlet.monkey_patch(thread=True) + from oslo.config import cfg from neutron.api.v2 import attributes @@ -39,8 +41,6 @@ from neutron.services.loadbalancer.drivers import abstract_driver from neutron.services.loadbalancer.drivers.radware import exceptions as r_exc -eventlet.monkey_patch(thread=True) - LOG = logging.getLogger(__name__) RESP_STATUS = 0 diff --git a/neutron/services/metering/agents/metering_agent.py b/neutron/services/metering/agents/metering_agent.py index a3a20ea5af8..d1bd3c965da 100644 --- a/neutron/services/metering/agents/metering_agent.py +++ b/neutron/services/metering/agents/metering_agent.py @@ -17,6 +17,8 @@ import time import eventlet +eventlet.monkey_patch() + from oslo.config import cfg from neutron.agent.common import config @@ -281,7 +283,6 @@ def agent_updated(self, context, payload): def main(): - eventlet.monkey_patch() conf = cfg.CONF conf.register_opts(MeteringAgent.Opts) config.register_agent_state_opts_helper(conf) diff --git a/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py b/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py index 816b763752f..1ddcbbd056f 100644 --- a/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py +++ b/neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py @@ -213,14 +213,12 @@ def test_main(self): with mock.patch.object(hyperv_neutron_agent, 'HyperVNeutronAgent') as plugin: with mock.patch.object(hyperv_neutron_agent.cfg, 'CONF') as cfg: - with mock.patch('eventlet.monkey_patch') as eventlet: - with mock.patch.object( - hyperv_neutron_agent, - 'logging_config') as logging_config: + with mock.patch.object( + hyperv_neutron_agent, + 'logging_config') as logging_config: - hyperv_neutron_agent.main() + hyperv_neutron_agent.main() - self.assertTrue(cfg.called) - self.assertTrue(eventlet.called) - self.assertTrue(logging_config.setup_logging.called) - plugin.assert_has_calls([mock.call().daemon_loop()]) + self.assertTrue(cfg.called) + self.assertTrue(logging_config.setup_logging.called) + plugin.assert_has_calls([mock.call().daemon_loop()]) diff --git a/neutron/tests/unit/nec/test_nec_agent.py b/neutron/tests/unit/nec/test_nec_agent.py index f23cece8159..16e4031c57f 100644 --- a/neutron/tests/unit/nec/test_nec_agent.py +++ b/neutron/tests/unit/nec/test_nec_agent.py @@ -350,17 +350,15 @@ class TestNecAgentMain(base.BaseTestCase): def test_main(self): with contextlib.nested( mock.patch.object(nec_neutron_agent, 'NECNeutronAgent'), - mock.patch('eventlet.monkey_patch'), mock.patch.object(nec_neutron_agent, 'logging_config'), mock.patch.object(nec_neutron_agent, 'config') - ) as (agent, eventlet, logging_config, cfg): + ) as (agent, logging_config, cfg): cfg.OVS.integration_bridge = 'br-int-x' cfg.AGENT.root_helper = 'dummy-helper' cfg.AGENT.polling_interval = 10 nec_neutron_agent.main() - self.assertTrue(eventlet.called) self.assertTrue(logging_config.setup_logging.called) agent.assert_has_calls([ mock.call('br-int-x', 'dummy-helper', 10), diff --git a/neutron/tests/unit/oneconvergence/test_nvsd_agent.py b/neutron/tests/unit/oneconvergence/test_nvsd_agent.py index 2243aa6ec5d..1a98c1274cd 100644 --- a/neutron/tests/unit/oneconvergence/test_nvsd_agent.py +++ b/neutron/tests/unit/oneconvergence/test_nvsd_agent.py @@ -161,17 +161,15 @@ class TestOneConvergenceAgentMain(base.BaseTestCase): def test_main(self): with contextlib.nested( mock.patch.object(nvsd_neutron_agent, 'NVSDNeutronAgent'), - mock.patch('eventlet.monkey_patch'), mock.patch.object(nvsd_neutron_agent, 'logging_config'), mock.patch.object(nvsd_neutron_agent, 'config') - ) as (agent, eventlet, logging_config, config): + ) as (agent, logging_config, config): config.AGENT.integration_bridge = 'br-int-dummy' config.AGENT.root_helper = 'root-helper' config.AGENT.polling_interval = 5 nvsd_neutron_agent.main() - self.assertTrue(eventlet.called) self.assertTrue(logging_config.setup_logging.called) agent.assert_has_calls([ mock.call('br-int-dummy', 'root-helper', 5), diff --git a/neutron/tests/unit/services/loadbalancer/agent/test_agent.py b/neutron/tests/unit/services/loadbalancer/agent/test_agent.py index ef66e29219a..b00c5233008 100644 --- a/neutron/tests/unit/services/loadbalancer/agent/test_agent.py +++ b/neutron/tests/unit/services/loadbalancer/agent/test_agent.py @@ -42,12 +42,10 @@ def test_main(self): with contextlib.nested( mock.patch(logging_str), mock.patch.object(agent.service, 'launch'), - mock.patch.object(agent, 'eventlet'), mock.patch('sys.argv'), mock.patch.object(agent.manager, 'LbaasAgentManager'), mock.patch.object(cfg.CONF, 'register_opts') - ) as (mock_logging, mock_launch, mock_eventlet, sys_argv, mgr_cls, ro): + ) as (mock_logging, mock_launch, sys_argv, mgr_cls, ro): agent.main() - self.assertTrue(mock_eventlet.monkey_patch.called) mock_launch.assert_called_once_with(mock.ANY) diff --git a/neutron/tests/unit/test_metadata_agent.py b/neutron/tests/unit/test_metadata_agent.py index 2185e469d92..872adaef390 100644 --- a/neutron/tests/unit/test_metadata_agent.py +++ b/neutron/tests/unit/test_metadata_agent.py @@ -551,18 +551,16 @@ def test_run(self): def test_main(self): with mock.patch.object(agent, 'UnixDomainMetadataProxy') as proxy: - with mock.patch('eventlet.monkey_patch') as eventlet: - with mock.patch.object(agent, 'config') as config: - with mock.patch.object(agent, 'cfg') as cfg: - with mock.patch.object(utils, 'cfg'): - agent.main() - - self.assertTrue(eventlet.called) - self.assertTrue(config.setup_logging.called) - proxy.assert_has_calls([ - mock.call(cfg.CONF), - mock.call().run()] - ) + with mock.patch.object(agent, 'config') as config: + with mock.patch.object(agent, 'cfg') as cfg: + with mock.patch.object(utils, 'cfg'): + agent.main() + + self.assertTrue(config.setup_logging.called) + proxy.assert_has_calls([ + mock.call(cfg.CONF), + mock.call().run()] + ) def test_init_state_reporting(self): with mock.patch('os.makedirs'): diff --git a/neutron/tests/unit/test_metadata_namespace_proxy.py b/neutron/tests/unit/test_metadata_namespace_proxy.py index 8aafc33a45e..416a113b36f 100644 --- a/neutron/tests/unit/test_metadata_namespace_proxy.py +++ b/neutron/tests/unit/test_metadata_namespace_proxy.py @@ -312,46 +312,42 @@ def test_run(self): def test_main(self): with mock.patch.object(ns_proxy, 'ProxyDaemon') as daemon: - with mock.patch('eventlet.monkey_patch') as eventlet: - with mock.patch.object(ns_proxy, 'config') as config: - with mock.patch.object(ns_proxy, 'cfg') as cfg: - with mock.patch.object(utils, 'cfg') as utils_cfg: - cfg.CONF.router_id = 'router_id' - cfg.CONF.network_id = None - cfg.CONF.metadata_port = 9697 - cfg.CONF.pid_file = 'pidfile' - cfg.CONF.daemonize = True - utils_cfg.CONF.log_opt_values.return_value = None - ns_proxy.main() - - self.assertTrue(eventlet.called) - self.assertTrue(config.setup_logging.called) - daemon.assert_has_calls([ - mock.call('pidfile', 9697, - router_id='router_id', - network_id=None), - mock.call().start()] - ) + with mock.patch.object(ns_proxy, 'config') as config: + with mock.patch.object(ns_proxy, 'cfg') as cfg: + with mock.patch.object(utils, 'cfg') as utils_cfg: + cfg.CONF.router_id = 'router_id' + cfg.CONF.network_id = None + cfg.CONF.metadata_port = 9697 + cfg.CONF.pid_file = 'pidfile' + cfg.CONF.daemonize = True + utils_cfg.CONF.log_opt_values.return_value = None + ns_proxy.main() + + self.assertTrue(config.setup_logging.called) + daemon.assert_has_calls([ + mock.call('pidfile', 9697, + router_id='router_id', + network_id=None), + mock.call().start()] + ) def test_main_dont_fork(self): with mock.patch.object(ns_proxy, 'ProxyDaemon') as daemon: - with mock.patch('eventlet.monkey_patch') as eventlet: - with mock.patch.object(ns_proxy, 'config') as config: - with mock.patch.object(ns_proxy, 'cfg') as cfg: - with mock.patch.object(utils, 'cfg') as utils_cfg: - cfg.CONF.router_id = 'router_id' - cfg.CONF.network_id = None - cfg.CONF.metadata_port = 9697 - cfg.CONF.pid_file = 'pidfile' - cfg.CONF.daemonize = False - utils_cfg.CONF.log_opt_values.return_value = None - ns_proxy.main() - - self.assertTrue(eventlet.called) - self.assertTrue(config.setup_logging.called) - daemon.assert_has_calls([ - mock.call('pidfile', 9697, - router_id='router_id', - network_id=None), - mock.call().run()] - ) + with mock.patch.object(ns_proxy, 'config') as config: + with mock.patch.object(ns_proxy, 'cfg') as cfg: + with mock.patch.object(utils, 'cfg') as utils_cfg: + cfg.CONF.router_id = 'router_id' + cfg.CONF.network_id = None + cfg.CONF.metadata_port = 9697 + cfg.CONF.pid_file = 'pidfile' + cfg.CONF.daemonize = False + utils_cfg.CONF.log_opt_values.return_value = None + ns_proxy.main() + + self.assertTrue(config.setup_logging.called) + daemon.assert_has_calls([ + mock.call('pidfile', 9697, + router_id='router_id', + network_id=None), + mock.call().run()] + ) diff --git a/neutron/wsgi.py b/neutron/wsgi.py index c13c8034826..4487d654aef 100644 --- a/neutron/wsgi.py +++ b/neutron/wsgi.py @@ -30,7 +30,7 @@ from xml.parsers import expat import eventlet.wsgi -eventlet.patcher.monkey_patch(all=False, socket=True) +eventlet.patcher.monkey_patch(all=False, socket=True, thread=True) from oslo.config import cfg import routes.middleware import webob.dec