From 972cdef50cd32837b8328466e4d821bb36535130 Mon Sep 17 00:00:00 2001 From: John Perkins Date: Mon, 2 May 2016 22:52:51 -0600 Subject: [PATCH] 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 --- neutron/agent/linux/dhcp.py | 1 + neutron/extensions/agent.py | 2 ++ neutron/extensions/dhcpagentscheduler.py | 2 ++ neutron/extensions/l3.py | 2 ++ neutron/extensions/l3agentscheduler.py | 2 ++ .../plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py | 1 + neutron/plugins/ml2/drivers/type_tunnel.py | 2 ++ neutron/scheduler/base_resource_filter.py | 3 +++ neutron/scheduler/base_scheduler.py | 3 +++ neutron/tests/unit/extensions/foxinsocks.py | 2 ++ 10 files changed, 20 insertions(+) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 97e96fd81f0..ee855dc9acc 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -172,6 +172,7 @@ class DhcpBase(object): raise NotImplementedError() +@six.add_metaclass(abc.ABCMeta) class DhcpLocalProcess(DhcpBase): PORTS = [] diff --git a/neutron/extensions/agent.py b/neutron/extensions/agent.py index 13a8a39db94..bda48582952 100644 --- a/neutron/extensions/agent.py +++ b/neutron/extensions/agent.py @@ -17,6 +17,7 @@ import abc from neutron_lib.api import converters from neutron_lib import exceptions +import six from neutron._i18n import _ from neutron.api import extensions @@ -122,6 +123,7 @@ class Agent(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(abc.ABCMeta) class AgentPluginBase(object): """REST API to operate the Agent. diff --git a/neutron/extensions/dhcpagentscheduler.py b/neutron/extensions/dhcpagentscheduler.py index 413387ea3c3..41f922e9f21 100644 --- a/neutron/extensions/dhcpagentscheduler.py +++ b/neutron/extensions/dhcpagentscheduler.py @@ -17,6 +17,7 @@ import abc from neutron_lib import constants from neutron_lib import exceptions +import six from neutron._i18n import _ from neutron.api import extensions @@ -135,6 +136,7 @@ class NetworkNotHostedByDhcpAgent(exceptions.Conflict): " by the DHCP agent %(agent_id)s.") +@six.add_metaclass(abc.ABCMeta) class DhcpAgentSchedulerPluginBase(object): """REST API to operate the DHCP agent scheduler. diff --git a/neutron/extensions/l3.py b/neutron/extensions/l3.py index d82decc0af8..a47cab61e7b 100644 --- a/neutron/extensions/l3.py +++ b/neutron/extensions/l3.py @@ -18,6 +18,7 @@ import abc from neutron_lib.api import converters from neutron_lib import exceptions as nexception from oslo_config import cfg +import six from neutron._i18n import _ from neutron.api import extensions @@ -220,6 +221,7 @@ class L3(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(abc.ABCMeta) class RouterPluginBase(object): @abc.abstractmethod diff --git a/neutron/extensions/l3agentscheduler.py b/neutron/extensions/l3agentscheduler.py index 33f5c31ad1c..f67ca0f51f7 100644 --- a/neutron/extensions/l3agentscheduler.py +++ b/neutron/extensions/l3agentscheduler.py @@ -18,6 +18,7 @@ import abc from neutron_lib import constants from neutron_lib import exceptions from oslo_log import log as logging +import six import webob.exc from neutron._i18n import _, _LE @@ -183,6 +184,7 @@ class DVRL3CannotRemoveFromDvrAgent(exceptions.Conflict): "an agent in 'dvr' mode.") +@six.add_metaclass(abc.ABCMeta) class L3AgentSchedulerPluginBase(object): """REST API to operate the l3 agent scheduler. diff --git a/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py b/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py index 09e53d60739..3273a1e785d 100644 --- a/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py +++ b/neutron/plugins/ml2/drivers/l2pop/rpc_manager/l2population_rpc.py @@ -104,6 +104,7 @@ class L2populationRpcCallBackMixin(object): pass +@six.add_metaclass(abc.ABCMeta) class L2populationRpcCallBackTunnelMixin(L2populationRpcCallBackMixin): '''Mixin class of L2-population call back for Tunnel. diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py index 2f877e13729..d5804bbe10a 100644 --- a/neutron/plugins/ml2/drivers/type_tunnel.py +++ b/neutron/plugins/ml2/drivers/type_tunnel.py @@ -21,6 +21,7 @@ from oslo_config import cfg from oslo_db import api as oslo_db_api from oslo_db import exception as db_exc from oslo_log import log +import six from six import moves from sqlalchemy import or_ @@ -45,6 +46,7 @@ def chunks(iterable, chunk_size): chunk = list(itertools.islice(iterator, 0, chunk_size)) +@six.add_metaclass(abc.ABCMeta) class TunnelTypeDriver(helpers.SegmentTypeDriver): """Define stable abstract interface for ML2 type drivers. diff --git a/neutron/scheduler/base_resource_filter.py b/neutron/scheduler/base_resource_filter.py index a2b1729123c..115b2be1e5f 100644 --- a/neutron/scheduler/base_resource_filter.py +++ b/neutron/scheduler/base_resource_filter.py @@ -15,7 +15,10 @@ import abc +import six + +@six.add_metaclass(abc.ABCMeta) class BaseResourceFilter(object): """Encapsulate logic that is specific to the resource type.""" @abc.abstractmethod diff --git a/neutron/scheduler/base_scheduler.py b/neutron/scheduler/base_scheduler.py index 561d12e38c9..96be86f7fc7 100644 --- a/neutron/scheduler/base_scheduler.py +++ b/neutron/scheduler/base_scheduler.py @@ -17,7 +17,10 @@ import abc from operator import attrgetter import random +import six + +@six.add_metaclass(abc.ABCMeta) class BaseScheduler(object): """The base scheduler (agnostic to resource type). Child classes of BaseScheduler must define the diff --git a/neutron/tests/unit/extensions/foxinsocks.py b/neutron/tests/unit/extensions/foxinsocks.py index d77dc764c95..1edde476790 100644 --- a/neutron/tests/unit/extensions/foxinsocks.py +++ b/neutron/tests/unit/extensions/foxinsocks.py @@ -16,6 +16,7 @@ import abc from oslo_serialization import jsonutils +import six from neutron.api import extensions from neutron import wsgi @@ -27,6 +28,7 @@ class FoxInSocksController(wsgi.Controller): return "Try to say this Mr. Knox, sir..." +@six.add_metaclass(abc.ABCMeta) class FoxInSocksPluginInterface(extensions.PluginInterface): @abc.abstractmethod