diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index a69ad200fc4..a914d02dc76 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -35,10 +35,9 @@ from oslo_utils import excutils from oslo_utils import fileutils import psutil +from neutron.api import wsgi from neutron.conf.agent import common as config from neutron.privileged.agent.linux import utils as priv_utils -from neutron import wsgi - LOG = logging.getLogger(__name__) diff --git a/neutron/api/api_common.py b/neutron/api/api_common.py index 83f2b62d601..095f59b93b2 100644 --- a/neutron/api/api_common.py +++ b/neutron/api/api_common.py @@ -28,7 +28,7 @@ from webob import exc from neutron._i18n import _ from neutron.api import extensions -from neutron import wsgi +from neutron.api import wsgi LOG = logging.getLogger(__name__) diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index 37706d12cfa..9c6db36be14 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -30,11 +30,10 @@ import webob.dec import webob.exc from neutron._i18n import _ +from neutron.api import wsgi from neutron import extensions as core_extensions from neutron.plugins.common import constants as const from neutron.services import provider_configuration -from neutron import wsgi - LOG = logging.getLogger(__name__) diff --git a/neutron/api/v2/resource.py b/neutron/api/v2/resource.py index a272a13734c..03bb1298963 100644 --- a/neutron/api/v2/resource.py +++ b/neutron/api/v2/resource.py @@ -22,9 +22,8 @@ import webob.dec import webob.exc from neutron.api import api_common +from neutron.api import wsgi from neutron.common import utils -from neutron import wsgi - LOG = logging.getLogger(__name__) diff --git a/neutron/wsgi.py b/neutron/api/wsgi.py similarity index 100% rename from neutron/wsgi.py rename to neutron/api/wsgi.py diff --git a/neutron/extensions/dhcpagentscheduler.py b/neutron/extensions/dhcpagentscheduler.py index 53f984ad41e..e5a5787751b 100644 --- a/neutron/extensions/dhcpagentscheduler.py +++ b/neutron/extensions/dhcpagentscheduler.py @@ -27,8 +27,8 @@ from oslo_log import log as logging from neutron.api import extensions from neutron.api.v2 import resource +from neutron.api import wsgi from neutron import policy -from neutron import wsgi LOG = logging.getLogger(__name__) diff --git a/neutron/extensions/l3agentscheduler.py b/neutron/extensions/l3agentscheduler.py index fdc29f7cb40..6d5ac146e3b 100644 --- a/neutron/extensions/l3agentscheduler.py +++ b/neutron/extensions/l3agentscheduler.py @@ -29,13 +29,11 @@ import webob.exc from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import resource +from neutron.api import wsgi from neutron import policy -from neutron import wsgi - LOG = logging.getLogger(__name__) - L3_ROUTER = 'l3-router' L3_ROUTERS = L3_ROUTER + 's' L3_AGENT = 'l3-agent' diff --git a/neutron/extensions/quotasv2.py b/neutron/extensions/quotasv2.py index c360835005d..b18f37e7368 100644 --- a/neutron/extensions/quotasv2.py +++ b/neutron/extensions/quotasv2.py @@ -30,10 +30,10 @@ from neutron._i18n import _ from neutron.api import extensions from neutron.api.v2 import base from neutron.api.v2 import resource +from neutron.api import wsgi from neutron import policy from neutron import quota from neutron.quota import resource_registry -from neutron import wsgi DEFAULT_QUOTAS_ACTION = 'default' diff --git a/neutron/opts.py b/neutron/opts.py index eb3baf32ced..19308564f3b 100644 --- a/neutron/opts.py +++ b/neutron/opts.py @@ -19,6 +19,7 @@ from oslo_config import cfg import neutron.agent.agent_extensions_manager import neutron.agent.securitygroups_rpc +import neutron.api.wsgi import neutron.conf.agent.agent_extensions_manager import neutron.conf.agent.common import neutron.conf.agent.database.agents_db @@ -60,7 +61,6 @@ import neutron.db.migration.cli import neutron.extensions.l3 import neutron.extensions.securitygroup import neutron.plugins.ml2.drivers.mech_sriov.agent.common.config -import neutron.wsgi AUTH_GROUPS_OPTS = { diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py index a0c53e13739..e843c5b9341 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py @@ -47,6 +47,7 @@ from oslo_utils import timeutils from ovsdbapp.backend.ovs_idl import idlutils from neutron._i18n import _ +from neutron.api import wsgi from neutron.common.ovn import acl as ovn_acl from neutron.common.ovn import constants as ovn_const from neutron.common.ovn import exceptions as ovn_exceptions @@ -72,7 +73,6 @@ from neutron.services.logapi.drivers.ovn import driver as log_driver from neutron.services.qos.drivers.ovn import driver as qos_driver from neutron.services.segments import db as segment_service_db from neutron.services.trunk.drivers.ovn import trunk_driver -import neutron.wsgi LOG = log.getLogger(__name__) @@ -299,7 +299,7 @@ class OVNMechanismDriver(api.MechanismDriver): @staticmethod def should_post_fork_initialize(worker_class): - return worker_class in (neutron.wsgi.WorkerService, + return worker_class in (wsgi.WorkerService, worker.MaintenanceWorker, service.RpcWorker) @@ -344,7 +344,7 @@ class OVNMechanismDriver(api.MechanismDriver): self._post_fork_event.clear() self._ovn_client_inst = None - if worker_class == neutron.wsgi.WorkerService: + if worker_class == wsgi.WorkerService: self._setup_hash_ring() n_agent.AgentCache(self) # Initialize singleton agent cache diff --git a/neutron/service.py b/neutron/service.py index 03db5f83378..78d1827dc49 100644 --- a/neutron/service.py +++ b/neutron/service.py @@ -34,11 +34,11 @@ from oslo_utils import excutils from oslo_utils import importutils import psutil +from neutron.api import wsgi from neutron.common import config from neutron.common import profiler from neutron.conf import service from neutron import worker as neutron_worker -from neutron import wsgi service.register_service_opts(service.SERVICE_OPTS) diff --git a/neutron/tests/functional/base.py b/neutron/tests/functional/base.py index 052e9a394d7..097d49ff680 100644 --- a/neutron/tests/functional/base.py +++ b/neutron/tests/functional/base.py @@ -32,6 +32,7 @@ from ovsdbapp.backend.ovs_idl import idlutils from neutron.agent.linux import utils from neutron.api import extensions as exts +from neutron.api import wsgi from neutron.common import utils as n_utils from neutron.conf.agent import common as config from neutron.conf.agent import ovs_conf @@ -53,7 +54,6 @@ from neutron.tests.common import helpers from neutron.tests.functional.resources import process from neutron.tests.unit.extensions import test_securitygroup from neutron.tests.unit.plugins.ml2 import test_plugin -import neutron.wsgi LOG = log.getLogger(__name__) @@ -329,7 +329,7 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase, trigger_cls.trigger.__self__.__class__ = worker.MaintenanceWorker cfg.CONF.set_override('neutron_sync_mode', 'off', 'ovn') else: - trigger_cls.trigger.__self__.__class__ = neutron.wsgi.WorkerService + trigger_cls.trigger.__self__.__class__ = wsgi.WorkerService self.addCleanup(self.stop) # NOTE(ralonsoh): do not access to the DB at exit when the SQL diff --git a/neutron/tests/functional/test_server.py b/neutron/tests/functional/test_server.py index b21ca825135..b59e021d009 100644 --- a/neutron/tests/functional/test_server.py +++ b/neutron/tests/functional/test_server.py @@ -28,16 +28,14 @@ from oslo_config import cfg from oslo_log import log import psutil +from neutron.api import wsgi from neutron.common import utils from neutron import manager from neutron import service from neutron.tests import base as tests_base from neutron.tests.functional import base -from neutron import wsgi - LOG = log.getLogger(__name__) - CONF = cfg.CONF # Those messages will be written to temporary file each time @@ -191,7 +189,7 @@ class TestNeutronServer(base.BaseLoggingTestCase): class TestWsgiServer(TestNeutronServer): - """Tests for neutron.wsgi.Server.""" + """Tests for neutron.api.wsgi.Server.""" def setUp(self): super(TestWsgiServer, self).setUp() @@ -225,8 +223,11 @@ class TestWsgiServer(TestNeutronServer): # Mock start method to check that children are started again on # receiving SIGHUP. - with mock.patch("neutron.wsgi.WorkerService.start") as start_method,\ - mock.patch("neutron.wsgi.WorkerService.reset") as reset_method: + with mock.patch( + "neutron.api.wsgi.WorkerService.start" + ) as start_method, mock.patch( + "neutron.api.wsgi.WorkerService.reset" + ) as reset_method: start_method.side_effect = self._fake_start reset_method.side_effect = self._fake_reset diff --git a/neutron/tests/unit/api/test_extensions.py b/neutron/tests/unit/api/test_extensions.py index a1882460228..b1c3e3bdd35 100644 --- a/neutron/tests/unit/api/test_extensions.py +++ b/neutron/tests/unit/api/test_extensions.py @@ -34,6 +34,7 @@ import webtest import neutron from neutron.api import extensions +from neutron.api import wsgi from neutron.common import config from neutron.plugins.common import constants from neutron import quota @@ -44,8 +45,6 @@ from neutron.tests.unit import extension_stubs as ext_stubs import neutron.tests.unit.extensions from neutron.tests.unit.extensions import extendedattribute as extattr from neutron.tests.unit import testlib_api -from neutron import wsgi - LOG = logging.getLogger(__name__) _uuid = test_base._uuid diff --git a/neutron/tests/unit/test_wsgi.py b/neutron/tests/unit/api/test_wsgi.py similarity index 99% rename from neutron/tests/unit/test_wsgi.py rename to neutron/tests/unit/api/test_wsgi.py index 39d6566d370..bbdd4eb172c 100644 --- a/neutron/tests/unit/test_wsgi.py +++ b/neutron/tests/unit/api/test_wsgi.py @@ -27,8 +27,8 @@ import testtools import webob import webob.exc +from neutron.api import wsgi from neutron.tests import base -from neutron import wsgi CONF = cfg.CONF @@ -52,19 +52,7 @@ def open_no_proxy(*args, **kwargs): return opener.open(*args, **kwargs) -class TestServiceBase(base.BaseTestCase): - """Service tests base.""" - - @mock.patch("neutron.policy.refresh") - @mock.patch("neutron.common.config.setup_logging") - def _test_reset(self, worker_service, setup_logging_mock, refresh_mock): - worker_service.reset() - - setup_logging_mock.assert_called_once_with() - refresh_mock.assert_called_once_with() - - -class TestWorkerService(TestServiceBase): +class TestWorkerService(base.BaseTestCase): """WorkerService tests.""" @mock.patch.object(db_api, 'get_context_manager') @@ -77,6 +65,14 @@ class TestWorkerService(TestServiceBase): workerservice.start() self.assertFalse(apimock.called) + @mock.patch("neutron.policy.refresh") + @mock.patch("neutron.common.config.setup_logging") + def _test_reset(self, worker_service, setup_logging_mock, refresh_mock): + worker_service.reset() + + setup_logging_mock.assert_called_once_with() + refresh_mock.assert_called_once_with() + def test_reset(self): _service = mock.Mock() _app = mock.Mock() diff --git a/neutron/tests/unit/api/v2/test_resource.py b/neutron/tests/unit/api/v2/test_resource.py index 2166ccc4c1e..2c4fb3f3bcc 100644 --- a/neutron/tests/unit/api/v2/test_resource.py +++ b/neutron/tests/unit/api/v2/test_resource.py @@ -23,9 +23,9 @@ import webtest from neutron._i18n import _ from neutron.api.v2 import resource as wsgi_resource +from neutron.api import wsgi from neutron.common import utils from neutron.tests import base -from neutron import wsgi class RequestTestCase(base.BaseTestCase): diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 1a0862f99bc..27ef0ad3d23 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -40,6 +40,7 @@ from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api from neutron.api.rpc.handlers import dhcp_rpc from neutron.api.rpc.handlers import l3_rpc +from neutron.api import wsgi from neutron.db import agents_db from neutron.db import agentschedulers_db from neutron.db.models import agent as agent_model @@ -53,7 +54,6 @@ from neutron.tests.unit.db import test_db_base_plugin_v2 as test_plugin from neutron.tests.unit.extensions import test_agent from neutron.tests.unit.extensions import test_l3 from neutron.tests.unit import testlib_api -from neutron import wsgi L3_HOSTA = 'hosta' diff --git a/neutron/tests/unit/extension_stubs.py b/neutron/tests/unit/extension_stubs.py index 38c8fe642c6..7edcd64d8b6 100644 --- a/neutron/tests/unit/extension_stubs.py +++ b/neutron/tests/unit/extension_stubs.py @@ -18,7 +18,7 @@ import abc from neutron_lib.api import extensions as api_extensions from neutron_lib.services import base -from neutron import wsgi +from neutron.api import wsgi class StubExtension(api_extensions.ExtensionDescriptor): diff --git a/neutron/tests/unit/extensions/foxinsocks.py b/neutron/tests/unit/extensions/foxinsocks.py index a3bbe907acf..b6d27605296 100644 --- a/neutron/tests/unit/extensions/foxinsocks.py +++ b/neutron/tests/unit/extensions/foxinsocks.py @@ -20,7 +20,7 @@ from neutron_lib.services import base from oslo_serialization import jsonutils from neutron.api import extensions -from neutron import wsgi +from neutron.api import wsgi class FoxInSocksController(wsgi.Controller): diff --git a/neutron/tests/unit/test_service.py b/neutron/tests/unit/test_service.py index 96381700b86..3ff02aa0bd1 100644 --- a/neutron/tests/unit/test_service.py +++ b/neutron/tests/unit/test_service.py @@ -23,7 +23,6 @@ from oslo_config import cfg from neutron import service from neutron.tests import base -from neutron.tests.unit import test_wsgi class TestServiceHelpers(base.BaseTestCase): @@ -34,10 +33,19 @@ class TestServiceHelpers(base.BaseTestCase): self.assertLessEqual(num_workers, processutils.get_worker_count()) -class TestRpcWorker(test_wsgi.TestServiceBase): +class TestRpcWorker(base.BaseTestCase): + + @mock.patch("neutron.policy.refresh") + @mock.patch("neutron.common.config.setup_logging") + def _test_reset(self, worker_service, setup_logging_mock, refresh_mock): + worker_service.reset() + + setup_logging_mock.assert_called_once_with() + refresh_mock.assert_called_once_with() def test_reset(self): _plugin = mock.Mock() + rpc_worker = service.RpcWorker(_plugin) self._test_reset(rpc_worker) @@ -84,7 +92,7 @@ class TestRunWsgiApp(base.BaseTestCase): def _test_api_workers(self, config_value, expected_passed_value): if config_value is not None: cfg.CONF.set_override('api_workers', config_value) - with mock.patch('neutron.wsgi.Server') as mock_server: + with mock.patch('neutron.api.wsgi.Server') as mock_server: service.run_wsgi_app(mock.sentinel.app) start_call = mock_server.return_value.start.call_args expected_call = mock.call( diff --git a/neutron/tests/unit/testlib_api.py b/neutron/tests/unit/testlib_api.py index 38cc2ad69bc..5a41ee86ca3 100644 --- a/neutron/tests/unit/testlib_api.py +++ b/neutron/tests/unit/testlib_api.py @@ -23,11 +23,11 @@ from oslo_config import cfg from oslo_db import exception as oslodb_exception from oslo_db.sqlalchemy import provision +from neutron.api import wsgi from neutron.db.migration import cli as migration # Import all data models from neutron.db.migration.models import head # noqa from neutron.tests import base -from neutron import wsgi class ExpectedException(testtools.ExpectedException):