Remove neutron.wsgi module

We want this module for use elsewhere. This has a natural home in the
neutron.api module so move it there. This is similar to what has
previously been done for nova [1].

Tests for the module are also moved and other tests slightly decoupled.

[1] https://review.opendev.org/c/openstack/nova/+/902686

Change-Id: I835e7ad95b6d7d83d06f4303b476519c16b9a2c8
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-04-19 11:52:27 +01:00 committed by Brian Haley
parent abe8110f53
commit 34fafa2d8c
21 changed files with 48 additions and 49 deletions

View File

@ -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__)

View File

@ -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__)

View File

@ -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__)

View File

@ -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__)

View File

@ -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__)

View File

@ -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'

View File

@ -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'

View File

@ -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 = {

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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):

View File

@ -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'

View File

@ -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):

View File

@ -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):

View File

@ -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(

View File

@ -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):