Browse Source

Consume ServicePluginBase from neutron-lib

Neutron lib now contains ServicePluginBase [1]. In accordance
with the discussion in [2], this patch:
- Removes ServicePluginBase from neutron and replaces all uses
with neutron-lib.
- Removes PluginInterface; the plugin interface for extensions
is ServicePluginBase; that's what's used by everyone today.
- Updates a few UTs, based on the above.

NB: A subsequent patch will address the WorkerSupportServiceMixin
so its untouched herein.

NeutronLibImpact

[1] I2b1131ac53e9bfeb42a92f9ef134be6ff4cfe5a3
[2] https://review.openstack.org/#/c/424151/

Change-Id: I1e8f2ee6a96df9ba07dae37f1a80e61ad20693cc
changes/29/441129/4
Boden R 4 years ago
parent
commit
a6a344c7b5
  1. 26
      neutron/api/extensions.py
  2. 2
      neutron/extensions/metering.py
  3. 2
      neutron/extensions/qos.py
  4. 2
      neutron/extensions/tag.py
  5. 3
      neutron/services/flavors/flavors_plugin.py
  6. 2
      neutron/services/l3_router/l3_router_plugin.py
  7. 2
      neutron/services/loki/loki_plugin.py
  8. 2
      neutron/services/revisions/revision_plugin.py
  9. 25
      neutron/services/service_base.py
  10. 3
      neutron/services/timestamp/timestamp_plugin.py
  11. 2
      neutron/services/trunk/plugin.py
  12. 59
      neutron/tests/unit/api/test_extensions.py
  13. 2
      neutron/tests/unit/dummy_plugin.py
  14. 10
      neutron/tests/unit/extension_stubs.py
  15. 3
      neutron/tests/unit/extensions/foxinsocks.py

26
neutron/api/extensions.py

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import abc
import collections
import imp
import os
@ -60,31 +59,6 @@ def register_custom_supported_check(alias, f, plugin_agnostic=False):
_PLUGIN_AGNOSTIC_EXTENSIONS.add(alias)
@six.add_metaclass(abc.ABCMeta)
class PluginInterface(object):
@classmethod
def __subclasshook__(cls, klass):
"""Checking plugin class.
The __subclasshook__ method is a class method
that will be called every time a class is tested
using issubclass(klass, PluginInterface).
In that case, it will check that every method
marked with the abstractmethod decorator is
provided by the plugin class.
"""
if not cls.__abstractmethods__:
return NotImplemented
for method in cls.__abstractmethods__:
if any(method in base.__dict__ for base in klass.__mro__):
continue
return NotImplemented
return True
class ActionExtensionController(wsgi.Controller):
def __init__(self, application):

2
neutron/extensions/metering.py

@ -18,12 +18,12 @@ from neutron_lib.api import converters
from neutron_lib.api import extensions
from neutron_lib.db import constants as db_const
from neutron_lib import exceptions as nexception
from neutron_lib.services import base as service_base
import six
from neutron._i18n import _
from neutron.api.v2 import resource_helper
from neutron.plugins.common import constants
from neutron.services import service_base
class MeteringLabelNotFound(nexception.NotFound):

2
neutron/extensions/qos.py

@ -21,6 +21,7 @@ from neutron_lib.api import converters
from neutron_lib.api import extensions as api_extensions
from neutron_lib.db import constants as db_const
from neutron_lib.plugins import directory
from neutron_lib.services import base as service_base
import six
from neutron.api import extensions
@ -30,7 +31,6 @@ from neutron.common import constants as common_constants
from neutron.objects.qos import rule as rule_object
from neutron.plugins.common import constants
from neutron.services.qos import qos_consts
from neutron.services import service_base
QOS_PREFIX = "/qos"

2
neutron/extensions/tag.py

@ -17,6 +17,7 @@ from neutron_lib.api import extensions as api_extensions
from neutron_lib.api import validators
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from neutron_lib.services import base as service_base
import six
import webob.exc
@ -26,7 +27,6 @@ from neutron.api.v2 import attributes
from neutron.api.v2 import base
from neutron.api.v2 import resource as api_resource
from neutron.common import rpc as n_rpc
from neutron.services import service_base
TAG = 'tag'

3
neutron/services/flavors/flavors_plugin.py

@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.services import base as service_base
from neutron.db import flavors_db
from neutron.plugins.common import constants
from neutron.services import service_base
class FlavorsPlugin(service_base.ServicePluginBase,

2
neutron/services/l3_router/l3_router_plugin.py

@ -14,6 +14,7 @@
# under the License.
from neutron_lib import constants as n_const
from neutron_lib.services import base as service_base
from oslo_config import cfg
from oslo_log import helpers as log_helpers
from oslo_utils import importutils
@ -36,7 +37,6 @@ from neutron.extensions import l3
from neutron.quota import resource_registry
from neutron import service
from neutron.services.l3_router.service_providers import driver_controller
from neutron.services import service_base
class L3RouterPlugin(service_base.ServicePluginBase,

2
neutron/services/loki/loki_plugin.py

@ -15,8 +15,8 @@ import random
import time
from neutron.db import api as db_api
from neutron.services import service_base
from neutron_lib.services import base as service_base
from oslo_db import exception as db_exc
from oslo_log import log as logging
from sqlalchemy.orm import session as se

2
neutron/services/revisions/revision_plugin.py

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.services import base as service_base
from oslo_log import log as logging
import sqlalchemy
from sqlalchemy.orm import exc
@ -20,7 +21,6 @@ from neutron._i18n import _, _LW
from neutron.db import _resource_extend as resource_extend
from neutron.db import api as db_api
from neutron.db import standard_attr
from neutron.services import service_base
LOG = logging.getLogger(__name__)

25
neutron/services/service_base.py

@ -13,42 +13,17 @@
# License for the specific language governing permissions and limitations
# under the License.
import abc
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import importutils
import six
from neutron._i18n import _LE, _LI
from neutron.api import extensions
from neutron.db import servicetype_db as sdb
from neutron.services import provider_configuration as pconf
from neutron import worker as neutron_worker
LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class ServicePluginBase(extensions.PluginInterface,
neutron_worker.WorkerSupportServiceMixin):
"""Define base interface for any Advanced Service plugin."""
supported_extension_aliases = []
@abc.abstractmethod
def get_plugin_type(self):
"""Return one of predefined service types.
See neutron/plugins/common/constants.py
"""
pass
@abc.abstractmethod
def get_plugin_description(self):
"""Return string description of the plugin."""
pass
def load_drivers(service_type, plugin):
"""Loads drivers for specific service.

3
neutron/services/timestamp/timestamp_plugin.py

@ -12,12 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.services import base as service_base
from neutron.db import _model_query as model_query
from neutron.db import _resource_extend as resource_extend
from neutron.db import models_v2
from neutron.db import standard_attr
from neutron.objects import base as base_obj
from neutron.services import service_base
from neutron.services.timestamp import timestamp_db as ts_db

2
neutron/services/trunk/plugin.py

@ -15,6 +15,7 @@
import copy
from neutron_lib import context
from neutron_lib.services import base as service_base
from oslo_log import log as logging
from oslo_utils import uuidutils
@ -29,7 +30,6 @@ from neutron.db import db_base_plugin_common
from neutron.extensions import portbindings
from neutron.objects import base as objects_base
from neutron.objects import trunk as trunk_objects
from neutron.services import service_base
from neutron.services.trunk import callbacks
from neutron.services.trunk import constants
from neutron.services.trunk import drivers

59
neutron/tests/unit/api/test_extensions.py

@ -13,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import abc
import copy
import fixtures
import mock
from neutron_lib import constants as lib_const
from neutron_lib.plugins import directory
from neutron_lib.services import base as service_base
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
@ -85,7 +85,7 @@ class ExtensionsTestApp(base_wsgi.Router):
super(ExtensionsTestApp, self).__init__(mapper)
class FakePluginWithExtension(object):
class FakePluginWithExtension(service_base.ServicePluginBase):
"""A fake plugin used only for extension testing in this file."""
supported_extension_aliases = ["FOXNSOX"]
@ -93,6 +93,12 @@ class FakePluginWithExtension(object):
def method_to_support_foxnsox_extension(self, context):
self._log("method_to_support_foxnsox_extension", context)
def get_plugin_type(self):
pass
def get_plugin_description(self):
pass
class ExtensionPathTest(base.BaseTestCase):
@ -128,47 +134,6 @@ class ExtensionPathTest(base.BaseTestCase):
self.assertEqual(path, '%s:path1' % self.base_path)
class PluginInterfaceTest(base.BaseTestCase):
def test_issubclass_hook(self):
class A(object):
def f(self):
pass
class B(extensions.PluginInterface):
@abc.abstractmethod
def f(self):
pass
self.assertTrue(issubclass(A, B))
def test_issubclass_hook_class_without_abstract_methods(self):
class A(object):
def f(self):
pass
class B(extensions.PluginInterface):
def f(self):
pass
self.assertFalse(issubclass(A, B))
def test_issubclass_hook_not_all_methods_implemented(self):
class A(object):
def f(self):
pass
class B(extensions.PluginInterface):
@abc.abstractmethod
def f(self):
pass
@abc.abstractmethod
def g(self):
pass
self.assertFalse(issubclass(A, B))
class ResourceExtensionTest(base.BaseTestCase):
class ResourceExtensionController(wsgi.Controller):
@ -752,13 +717,19 @@ class PluginAwareExtensionManagerTest(base.BaseTestCase):
def test_extensions_are_loaded_for_plugin_with_expected_interface(self):
class PluginWithExpectedInterface(object):
class PluginWithExpectedInterface(service_base.ServicePluginBase):
"""Implements get_foo method as expected by extension."""
supported_extension_aliases = ["supported_extension"]
def get_foo(self, bar=None):
pass
def get_plugin_type(self):
pass
def get_plugin_description(self):
pass
plugin_info = {lib_const.CORE: PluginWithExpectedInterface()}
with mock.patch("neutron.api.extensions.PluginAwareExtensionManager."
"check_if_plugin_extensions_loaded"):

2
neutron/tests/unit/dummy_plugin.py

@ -15,6 +15,7 @@
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from neutron_lib.services import base as service_base
from oslo_utils import uuidutils
from neutron.api import extensions
@ -22,7 +23,6 @@ from neutron.api.v2 import base
from neutron.db import servicetype_db
from neutron.extensions import servicetype
from neutron.plugins.common import constants
from neutron.services import service_base
RESOURCE_NAME = "dummy"

10
neutron/tests/unit/extension_stubs.py

@ -16,8 +16,8 @@
import abc
from neutron_lib.api import extensions as api_extensions
from neutron_lib.services import base
from neutron.api import extensions
from neutron import wsgi
@ -67,12 +67,18 @@ class ExtensionExpectingPluginInterface(StubExtension):
return StubPluginInterface
class StubPluginInterface(extensions.PluginInterface):
class StubPluginInterface(base.ServicePluginBase):
@abc.abstractmethod
def get_foo(self, bar=None):
pass
def get_plugin_type(self):
pass
def get_plugin_description(self):
pass
class StubBaseAppController(wsgi.Controller):

3
neutron/tests/unit/extensions/foxinsocks.py

@ -16,6 +16,7 @@
import abc
from neutron_lib.api import extensions as api_extensions
from neutron_lib.services import base
from oslo_serialization import jsonutils
import six
@ -30,7 +31,7 @@ class FoxInSocksController(wsgi.Controller):
@six.add_metaclass(abc.ABCMeta)
class FoxInSocksPluginInterface(extensions.PluginInterface):
class FoxInSocksPluginInterface(base.ServicePluginBase):
@abc.abstractmethod
def method_to_support_foxnsox_extension(self):

Loading…
Cancel
Save