From: Ihar Hrachyshka Date: Mon, 10 Aug 2015 06:29:52 +0000 (+0200) Subject: Removed configuration option for qos agent driver selection X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ca0d7bce211d33ef8081684542ba4854cb743d74;p=openstack-build%2Fneutron-build.git Removed configuration option for qos agent driver selection There is no (general) use case to allow users to configure qos driver to load by qos l2 agent extension. So instead of getting the driver name from the configuration file, hardcode it and potentially reuse for other extensions that may also be interested in splitting extension into agent agnostic and agent specific pieces. Added driver_type parameter to AgentCoreResourceExtension.initialize(). Also updated the method signature to reflect that we expect l2 extensions to receive connection. Finally, removed #noqa import for openvswitch.common.config from qos extension unit test since it seems unneeded. Change-Id: Iae4dcc20c967d1da216772a3a3660e0421263527 Partially-Implements: quantum-qos-api --- diff --git a/etc/neutron/plugins/ml2/openvswitch_agent.ini b/etc/neutron/plugins/ml2/openvswitch_agent.ini index 5a23d1ea2..b6fd3e01a 100644 --- a/etc/neutron/plugins/ml2/openvswitch_agent.ini +++ b/etc/neutron/plugins/ml2/openvswitch_agent.ini @@ -147,10 +147,6 @@ # It should be false when you use nova security group. # enable_security_group = True -[qos] -# QoS agent driver -# agent_driver = ovs - #----------------------------------------------------------------------------- # Sample Configurations. #----------------------------------------------------------------------------- diff --git a/neutron/agent/l2/agent_extension.py b/neutron/agent/l2/agent_extension.py index 125a9bc05..c80fb3fa4 100644 --- a/neutron/agent/l2/agent_extension.py +++ b/neutron/agent/l2/agent_extension.py @@ -25,9 +25,15 @@ class AgentCoreResourceExtension(object): An agent extension extends the agent core functionality. """ - def initialize(self): + def initialize(self, connection, driver_type): """Perform agent core resource extension initialization. + :param connection: RPC connection that can be reused by the extension + to define its RPC endpoints + :param driver_type: a string that defines the agent type to the + extension. Can be used to choose the right backend + implementation. + Called after all extensions have been loaded. No port handling will be called before this method. """ diff --git a/neutron/agent/l2/extensions/manager.py b/neutron/agent/l2/extensions/manager.py index 2c77adbf8..1fa71ebbf 100644 --- a/neutron/agent/l2/extensions/manager.py +++ b/neutron/agent/l2/extensions/manager.py @@ -43,11 +43,19 @@ class AgentExtensionsManager(stevedore.named.NamedExtensionManager): invoke_on_load=True, name_order=True) LOG.info(_LI("Loaded agent extensions: %s"), self.names()) - def initialize(self, connection): + def initialize(self, connection, driver_type): + """Initialize enabled L2 agent extensions. + + :param connection: RPC connection that can be reused by extensions to + define their RPC endpoints + :param driver_type: a string that defines the agent type to the + extension. Can be used by the extension to choose + the right backend implementation. + """ # Initialize each agent extension in the list. for extension in self: LOG.info(_LI("Initializing agent extension '%s'"), extension.name) - extension.obj.initialize(connection) + extension.obj.initialize(connection, driver_type) def handle_port(self, context, data): """Notify all agent extensions to handle port.""" diff --git a/neutron/agent/l2/extensions/qos.py b/neutron/agent/l2/extensions/qos.py index 891084bf7..2acf1efc9 100644 --- a/neutron/agent/l2/extensions/qos.py +++ b/neutron/agent/l2/extensions/qos.py @@ -17,7 +17,6 @@ import abc import collections from oslo_concurrency import lockutils -from oslo_config import cfg import six from neutron.agent.l2 import agent_extension @@ -30,7 +29,7 @@ from neutron import manager @six.add_metaclass(abc.ABCMeta) class QosAgentDriver(object): - """Define stable abstract interface for QoS Agent Driver. + """Defines stable abstract interface for QoS Agent Driver. QoS Agent driver defines the interface to be implemented by Agent for applying QoS Rules on a port. @@ -40,7 +39,6 @@ class QosAgentDriver(object): def initialize(self): """Perform QoS agent driver initialization. """ - pass @abc.abstractmethod def create(self, port, qos_policy): @@ -51,7 +49,6 @@ class QosAgentDriver(object): """ #TODO(QoS) we may want to provide default implementations of calling #delete and then update - pass @abc.abstractmethod def update(self, port, qos_policy): @@ -60,7 +57,6 @@ class QosAgentDriver(object): :param port: port object. :param qos_policy: the QoS policy to be applied on port. """ - pass @abc.abstractmethod def delete(self, port, qos_policy): @@ -69,21 +65,18 @@ class QosAgentDriver(object): :param port: port object. :param qos_policy: the QoS policy to be removed from port. """ - pass class QosAgentExtension(agent_extension.AgentCoreResourceExtension): SUPPORTED_RESOURCES = [resources.QOS_POLICY] - def initialize(self, connection): + def initialize(self, connection, driver_type): """Perform Agent Extension initialization. """ - super(QosAgentExtension, self).initialize() - self.resource_rpc = resources_rpc.ResourcesPullRpcApi() self.qos_driver = manager.NeutronManager.load_class_for_provider( - 'neutron.qos.agent_drivers', cfg.CONF.qos.agent_driver)() + 'neutron.qos.agent_drivers', driver_type)() self.qos_driver.initialize() # we cannot use a dict of sets here because port dicts are not hashable diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py b/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py index c9afccff6..98b6210f9 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/common/config.py @@ -100,12 +100,7 @@ agent_opts = [ "timeout won't be changed")) ] -qos_opts = [ - cfg.StrOpt('agent_driver', default='ovs', help=_('QoS agent driver.')), -] - cfg.CONF.register_opts(ovs_opts, "OVS") cfg.CONF.register_opts(agent_opts, "AGENT") -cfg.CONF.register_opts(qos_opts, "qos") config.register_agent_state_opts_helper(cfg.CONF) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py b/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py index 40fa8f0f0..ad6b897c2 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/common/constants.py @@ -88,3 +88,5 @@ ARP_RESPONDER_ACTIONS = ('move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[],' OVS_RESTARTED = 0 OVS_NORMAL = 1 OVS_DEAD = 2 + +EXTENSION_DRIVER_TYPE = 'ovs' diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index a5190f9a3..73b5cab39 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -371,7 +371,8 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, ext_manager.register_opts(self.conf) self.ext_manager = ( ext_manager.AgentExtensionsManager(self.conf)) - self.ext_manager.initialize(connection) + self.ext_manager.initialize( + connection, constants.EXTENSION_DRIVER_TYPE) def get_net_uuid(self, vif_id): for network_id, vlan_mapping in six.iteritems(self.local_vlan_map): diff --git a/neutron/tests/unit/agent/l2/extensions/test_manager.py b/neutron/tests/unit/agent/l2/extensions/test_manager.py index 3aa8ea58b..5768205d5 100644 --- a/neutron/tests/unit/agent/l2/extensions/test_manager.py +++ b/neutron/tests/unit/agent/l2/extensions/test_manager.py @@ -33,9 +33,9 @@ class TestAgentExtensionsManager(base.BaseTestCase): def test_initialize(self): connection = object() - self.manager.initialize(connection) + self.manager.initialize(connection, 'fake_driver_type') ext = self._get_extension() - ext.initialize.assert_called_once_with(connection) + ext.initialize.assert_called_once_with(connection, 'fake_driver_type') def test_handle_port(self): context = object() diff --git a/neutron/tests/unit/agent/l2/extensions/test_qos.py b/neutron/tests/unit/agent/l2/extensions/test_qos.py index d78fc3121..ef3d1095f 100755 --- a/neutron/tests/unit/agent/l2/extensions/test_qos.py +++ b/neutron/tests/unit/agent/l2/extensions/test_qos.py @@ -22,7 +22,7 @@ from neutron.api.rpc.callbacks import events from neutron.api.rpc.callbacks import resources from neutron.api.rpc.handlers import resources_rpc from neutron import context -from neutron.plugins.ml2.drivers.openvswitch.agent.common import config # noqa +from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants from neutron.tests import base @@ -48,7 +48,8 @@ class QosExtensionRpcTestCase(QosExtensionBaseTestCase): def setUp(self): super(QosExtensionRpcTestCase, self).setUp() - self.qos_ext.initialize(self.connection) + self.qos_ext.initialize( + self.connection, constants.EXTENSION_DRIVER_TYPE) self.pull_mock = mock.patch.object( self.qos_ext.resource_rpc, 'pull', @@ -158,7 +159,8 @@ class QosExtensionInitializeTestCase(QosExtensionBaseTestCase): @mock.patch.object(registry, 'subscribe') @mock.patch.object(resources_rpc, 'ResourcesPushRpcCallback') def test_initialize_subscribed_to_rpc(self, rpc_mock, subscribe_mock): - self.qos_ext.initialize(self.connection) + self.qos_ext.initialize( + self.connection, constants.EXTENSION_DRIVER_TYPE) self.connection.create_consumer.assert_has_calls( [mock.call( resources_rpc.resource_type_versioned_topic(resource_type),