Classes lack metaclass decoration

Add decorations where required.

There are roughly a dozen classes in Neutron that define abstract
methods or properties but are not decorated with
@six.add_metaclass(abc.ABCMeta). Without this decoration, children
can be created without defining the required methods or properties.

Decorating RBACColumns in db/rbac_db_models.py causes failures and will
be reported separately.

Decorating unit tests is of dubious benifit and should be addressed
separately (if at all).

There are also several more places where metaclassing isn't correct, to
be taken care of in follow-on patches.

For example, BaseScheduler is using the fact the None doesn't have a
filter_agents() method, which gives developers confusing error messages
when they incorrectly implement the interface, and they won't see any
error until schedule() is called. As an aside, the docstring for this
base class is also incorrect.

Change-Id: I2b2cce37d9b0d40559a715a7d510a969b8ba9963
Closes-Bug: #1577648
This commit is contained in:
John Perkins 2016-05-02 22:52:51 -06:00
parent 261edb48b7
commit 972cdef50c
10 changed files with 20 additions and 0 deletions

View File

@ -172,6 +172,7 @@ class DhcpBase(object):
raise NotImplementedError() raise NotImplementedError()
@six.add_metaclass(abc.ABCMeta)
class DhcpLocalProcess(DhcpBase): class DhcpLocalProcess(DhcpBase):
PORTS = [] PORTS = []

View File

@ -17,6 +17,7 @@ import abc
from neutron_lib.api import converters from neutron_lib.api import converters
from neutron_lib import exceptions from neutron_lib import exceptions
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions from neutron.api import extensions
@ -122,6 +123,7 @@ class Agent(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(abc.ABCMeta)
class AgentPluginBase(object): class AgentPluginBase(object):
"""REST API to operate the Agent. """REST API to operate the Agent.

View File

@ -17,6 +17,7 @@ import abc
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import exceptions from neutron_lib import exceptions
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions from neutron.api import extensions
@ -135,6 +136,7 @@ class NetworkNotHostedByDhcpAgent(exceptions.Conflict):
" by the DHCP agent %(agent_id)s.") " by the DHCP agent %(agent_id)s.")
@six.add_metaclass(abc.ABCMeta)
class DhcpAgentSchedulerPluginBase(object): class DhcpAgentSchedulerPluginBase(object):
"""REST API to operate the DHCP agent scheduler. """REST API to operate the DHCP agent scheduler.

View File

@ -18,6 +18,7 @@ import abc
from neutron_lib.api import converters from neutron_lib.api import converters
from neutron_lib import exceptions as nexception from neutron_lib import exceptions as nexception
from oslo_config import cfg from oslo_config import cfg
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions from neutron.api import extensions
@ -220,6 +221,7 @@ class L3(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(abc.ABCMeta)
class RouterPluginBase(object): class RouterPluginBase(object):
@abc.abstractmethod @abc.abstractmethod

View File

@ -18,6 +18,7 @@ import abc
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import exceptions from neutron_lib import exceptions
from oslo_log import log as logging from oslo_log import log as logging
import six
import webob.exc import webob.exc
from neutron._i18n import _, _LE from neutron._i18n import _, _LE
@ -183,6 +184,7 @@ class DVRL3CannotRemoveFromDvrAgent(exceptions.Conflict):
"an agent in 'dvr' mode.") "an agent in 'dvr' mode.")
@six.add_metaclass(abc.ABCMeta)
class L3AgentSchedulerPluginBase(object): class L3AgentSchedulerPluginBase(object):
"""REST API to operate the l3 agent scheduler. """REST API to operate the l3 agent scheduler.

View File

@ -104,6 +104,7 @@ class L2populationRpcCallBackMixin(object):
pass pass
@six.add_metaclass(abc.ABCMeta)
class L2populationRpcCallBackTunnelMixin(L2populationRpcCallBackMixin): class L2populationRpcCallBackTunnelMixin(L2populationRpcCallBackMixin):
'''Mixin class of L2-population call back for Tunnel. '''Mixin class of L2-population call back for Tunnel.

View File

@ -21,6 +21,7 @@ from oslo_config import cfg
from oslo_db import api as oslo_db_api from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_log import log from oslo_log import log
import six
from six import moves from six import moves
from sqlalchemy import or_ from sqlalchemy import or_
@ -45,6 +46,7 @@ def chunks(iterable, chunk_size):
chunk = list(itertools.islice(iterator, 0, chunk_size)) chunk = list(itertools.islice(iterator, 0, chunk_size))
@six.add_metaclass(abc.ABCMeta)
class TunnelTypeDriver(helpers.SegmentTypeDriver): class TunnelTypeDriver(helpers.SegmentTypeDriver):
"""Define stable abstract interface for ML2 type drivers. """Define stable abstract interface for ML2 type drivers.

View File

@ -15,7 +15,10 @@
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class BaseResourceFilter(object): class BaseResourceFilter(object):
"""Encapsulate logic that is specific to the resource type.""" """Encapsulate logic that is specific to the resource type."""
@abc.abstractmethod @abc.abstractmethod

View File

@ -17,7 +17,10 @@ import abc
from operator import attrgetter from operator import attrgetter
import random import random
import six
@six.add_metaclass(abc.ABCMeta)
class BaseScheduler(object): class BaseScheduler(object):
"""The base scheduler (agnostic to resource type). """The base scheduler (agnostic to resource type).
Child classes of BaseScheduler must define the Child classes of BaseScheduler must define the

View File

@ -16,6 +16,7 @@
import abc import abc
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six
from neutron.api import extensions from neutron.api import extensions
from neutron import wsgi from neutron import wsgi
@ -27,6 +28,7 @@ class FoxInSocksController(wsgi.Controller):
return "Try to say this Mr. Knox, sir..." return "Try to say this Mr. Knox, sir..."
@six.add_metaclass(abc.ABCMeta)
class FoxInSocksPluginInterface(extensions.PluginInterface): class FoxInSocksPluginInterface(extensions.PluginInterface):
@abc.abstractmethod @abc.abstractmethod