FWaaS: L3 Agent restructure - observer hierarchy
This commit creates the basic observer hierarchy for advanced services, as part of a multi-step refactoring effort of the L3 agent. The change set has these modifications: - Focuses on FWaaS changes for this refactoring. - Creates a FirewallService instance. - Loads device driver using the service. - UT updated to test new methods and refactoring changes. The next steps (future commit) will be to define handlers for events of interest for FWaas (moving logic out of the L3 agent). Change-Id: I674c72e37b56aa1f729110310e6f697297c47c09 Partially-implements: blueprint restructure-l3-agent
This commit is contained in:
parent
3ebc15e1bb
commit
61aed2eeaf
|
@ -0,0 +1,43 @@
|
|||
# Copyright 2014 OpenStack Foundation.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.services import advanced_service
|
||||
from neutron.services import provider_configuration as provconf
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import importutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
FIREWALL_DRIVERS = 'firewall_drivers'
|
||||
|
||||
|
||||
class FirewallService(advanced_service.AdvancedService):
|
||||
"""Firewall Service observer."""
|
||||
|
||||
def load_device_drivers(self):
|
||||
"""Loads a single device driver for FWaaS."""
|
||||
device_driver = provconf.get_provider_driver_class(
|
||||
cfg.CONF.fwaas.driver, FIREWALL_DRIVERS)
|
||||
try:
|
||||
self.devices = importutils.import_object(device_driver)
|
||||
LOG.debug('Loaded FWaaS device driver: %s', device_driver)
|
||||
return self.devices
|
||||
except ImportError:
|
||||
msg = _('Error importing FWaaS device driver: %s')
|
||||
raise ImportError(msg % device_driver)
|
||||
except ValueError:
|
||||
msg = _('Configuration error - no FWaaS device_driver specified')
|
||||
raise ValueError(msg)
|
|
@ -14,7 +14,6 @@
|
|||
# under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import importutils
|
||||
|
||||
from neutron.agent.common import config
|
||||
from neutron.agent.linux import ip_lib
|
||||
|
@ -24,13 +23,11 @@ from neutron.extensions import firewall as fw_ext
|
|||
from neutron.i18n import _LE
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.services import provider_configuration as provconf
|
||||
from neutron_fwaas.services.firewall.agents import firewall_agent_api as api
|
||||
from neutron_fwaas.services.firewall.agents import firewall_service
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
FIREWALL_DRIVERS = 'firewall_drivers'
|
||||
|
||||
|
||||
class FWaaSL3PluginApi(api.FWaaSPluginApiMixin):
|
||||
"""Agent side of the FWaaS agent to FWaaS Plugin RPC API."""
|
||||
|
@ -58,8 +55,6 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin):
|
|||
def __init__(self, conf):
|
||||
LOG.debug("Initializing firewall agent")
|
||||
self.conf = conf
|
||||
fwaas_driver_class_path = provconf.get_provider_driver_class(
|
||||
cfg.CONF.fwaas.driver, FIREWALL_DRIVERS)
|
||||
self.fwaas_enabled = cfg.CONF.fwaas.enabled
|
||||
|
||||
# None means l3-agent has no information on the server
|
||||
|
@ -75,13 +70,10 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin):
|
|||
self.fwaas_enabled = self.fwaas_enabled and fwaas_plugin_configured
|
||||
|
||||
if self.fwaas_enabled:
|
||||
try:
|
||||
self.fwaas_driver = importutils.import_object(
|
||||
fwaas_driver_class_path)
|
||||
LOG.debug("FWaaS Driver Loaded: '%s'", fwaas_driver_class_path)
|
||||
except ImportError:
|
||||
msg = _('Error importing FWaaS device driver: %s')
|
||||
raise ImportError(msg % fwaas_driver_class_path)
|
||||
# NOTE: Temp location for creating service and loading driver
|
||||
self.fw_service = firewall_service.FirewallService.instance(self)
|
||||
self.event_observers.add(self.fw_service)
|
||||
self.fwaas_driver = self.fw_service.load_device_drivers()
|
||||
self.services_sync = False
|
||||
self.root_helper = config.get_root_helper(conf)
|
||||
# setup RPC to msg fwaas plugin
|
||||
|
|
|
@ -48,6 +48,12 @@ def _setup_test_agent_class(service_plugins):
|
|||
FWaasHelper):
|
||||
neutron_service_plugins = service_plugins
|
||||
|
||||
def __init__(self, conf):
|
||||
self.event_observers = mock.Mock()
|
||||
self.root_helper = mock.Mock()
|
||||
self.conf = conf
|
||||
super(FWaasTestAgent, self).__init__(conf)
|
||||
|
||||
return FWaasTestAgent
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
# Copyright 2014 OpenStack Foundation.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from neutron.tests import base
|
||||
from oslo.config import cfg
|
||||
|
||||
from neutron_fwaas.services.firewall.agents import firewall_service
|
||||
|
||||
FWAAS_NOP_DEVICE = ('neutron_fwaas.tests.unit.services.firewall.agents.'
|
||||
'test_firewall_agent_api.NoopFwaasDriver')
|
||||
|
||||
|
||||
class TestFirewallDeviceDriverLoading(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFirewallDeviceDriverLoading, self).setUp()
|
||||
self.service = firewall_service.FirewallService.instance(mock.Mock())
|
||||
|
||||
def test_loading_firewall_device_driver(self):
|
||||
"""Get the sole device driver for FWaaS."""
|
||||
cfg.CONF.set_override('driver',
|
||||
FWAAS_NOP_DEVICE,
|
||||
'fwaas')
|
||||
driver = self.service.load_device_drivers()
|
||||
self.assertIsNotNone(driver)
|
||||
self.assertIn(driver.__class__.__name__, FWAAS_NOP_DEVICE)
|
||||
|
||||
def test_fail_no_such_firewall_device_driver(self):
|
||||
"""Failure test of import error for FWaaS device driver."""
|
||||
cfg.CONF.set_override('driver',
|
||||
'no.such.class',
|
||||
'fwaas')
|
||||
self.assertRaises(ImportError,
|
||||
self.service.load_device_drivers)
|
||||
|
||||
def test_fail_firewall_no_device_driver_specified(self):
|
||||
"""Failure test when no FWaaS device driver is specified.
|
||||
|
||||
This is a configuration error, as the user must specify a device
|
||||
driver, when enabling the firewall service (and there is no default
|
||||
configuration set. We'll simulate that by using an empty string.
|
||||
"""
|
||||
cfg.CONF.set_override('driver',
|
||||
'',
|
||||
'fwaas')
|
||||
self.assertRaises(ValueError,
|
||||
self.service.load_device_drivers)
|
Loading…
Reference in New Issue