L2 agent extension manager: read extensions list from config file

This effectively disables qos extension in the OVS agent, but we don't
rely on it in any functional or fullstack tests so far.

To enable the extension, a user should add:

[agent]
extensions = qos

to their openvswitch_agent.ini file.

DocImpact
Partially-Implements: blueprint quantum-qos-api
Change-Id: Icfbf32c36f98cc6e203841b152c7f6fc4f48c20a
This commit is contained in:
Ihar Hrachyshka 2015-08-02 19:17:27 +02:00
parent 403662fd3a
commit 336a547aad
5 changed files with 29 additions and 20 deletions

View File

@ -133,6 +133,11 @@
#
# quitting_rpc_timeout = 10
# (ListOpt) Extensions list to use
# Example: extensions = qos
#
# extensions =
[securitygroup]
# Firewall driver for realizing neutron security group function.
# firewall_driver = neutron.agent.firewall.NoopFirewallDriver

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_log import log
import stevedore
@ -21,23 +22,26 @@ from neutron.i18n import _LE, _LI
LOG = log.getLogger(__name__)
L2_AGENT_EXT_MANAGER_NAMESPACE = 'neutron.agent.l2.extensions'
L2_AGENT_EXT_MANAGER_OPTS = [
cfg.ListOpt('extensions',
default=[],
help=_('Extensions list to use')),
]
def register_opts(conf):
conf.register_opts(L2_AGENT_EXT_MANAGER_OPTS, 'agent')
class AgentExtensionsManager(stevedore.named.NamedExtensionManager):
"""Manage agent extensions."""
def __init__(self):
# Ordered list of agent extensions, defining
# the order in which the agent extensions are called.
#TODO(QoS): get extensions from config
agent_extensions = ('qos', )
LOG.info(_LI("Configured agent extensions names: %s"),
agent_extensions)
def __init__(self, conf):
super(AgentExtensionsManager, self).__init__(
'neutron.agent.l2.extensions', agent_extensions,
L2_AGENT_EXT_MANAGER_NAMESPACE, conf.agent.extensions,
invoke_on_load=True, name_order=True)
LOG.info(_LI("Loaded agent extensions names: %s"), self.names())
LOG.info(_LI("Loaded agent extensions: %s"), self.names())
def _call_on_agent_extensions(self, method_name, context, data):
"""Helper method for calling a method across all agent extensions."""

View File

@ -367,8 +367,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
start_listening=False)
def init_agent_extensions_mgr(self):
agent_extensions_manager.register_opts(self.conf)
self.agent_extensions_mgr = (
agent_extensions_manager.AgentExtensionsManager())
agent_extensions_manager.AgentExtensionsManager(self.conf))
self.agent_extensions_mgr.initialize()
def get_net_uuid(self, vif_id):

View File

@ -11,6 +11,7 @@
# under the License.
import mock
from oslo_config import cfg
from neutron.agent.l2 import agent_extensions_manager
from neutron.tests import base
@ -22,7 +23,10 @@ class TestAgentExtensionsManager(base.BaseTestCase):
super(TestAgentExtensionsManager, self).setUp()
mock.patch('neutron.agent.l2.extensions.qos_agent.QosAgentExtension',
autospec=True).start()
self.manager = agent_extensions_manager.AgentExtensionsManager()
conf = cfg.CONF
agent_extensions_manager.register_opts(conf)
cfg.CONF.set_override('extensions', ['qos'], 'agent')
self.manager = agent_extensions_manager.AgentExtensionsManager(conf)
def _get_extension(self):
return self.manager.extensions[0].obj

View File

@ -374,12 +374,7 @@ class TestOvsNeutronAgent(object):
return_value=None):
self.assertFalse(get_dev_fn.called)
#TODO(QoS) that this mock should go away once we don't hardcode
#qos extension.
@mock.patch('neutron.api.rpc.handlers.resources_rpc.'
'ResourcesServerRpcApi.get_info', return_value=[])
def test_treat_devices_added_updated_updates_known_port(
self, *args):
def test_treat_devices_added_updated_updates_known_port(self):
details = mock.MagicMock()
details.__contains__.side_effect = lambda x: True
self.assertTrue(self._mock_treat_devices_added_updated(