From: Sridar Kandaswamy Date: Thu, 19 Dec 2013 08:04:25 +0000 (-0800) Subject: Remove FWaaS Noop driver as default and move to unit tests dir X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d7743bbdc3e992d9f9cceaeaa2919cd70b422364;p=openstack-build%2Fneutron-build.git Remove FWaaS Noop driver as default and move to unit tests dir Remove the FWaaS Noop driver as the default and raise an exception when the fwaas_driver.ini file has an enabled flag without any associated driver. This communicates a misconfiguration clearly. The Noop driver is moved to unit tests where it is used. Also some cleanups in related area. Closes-Bug: #1250841 Change-Id: Ib6345923df05994ceffc0b1cbf265b53c23e97f1 --- diff --git a/neutron/services/firewall/agents/firewall_agent_api.py b/neutron/services/firewall/agents/firewall_agent_api.py index 6d06a51dd..94e23cacf 100644 --- a/neutron/services/firewall/agents/firewall_agent_api.py +++ b/neutron/services/firewall/agents/firewall_agent_api.py @@ -29,8 +29,7 @@ LOG = logging.getLogger(__name__) FWaaSOpts = [ cfg.StrOpt( 'driver', - default=('neutron.services.firewall.drivers.fwaas_base.' - 'NoopFwaasDriver'), + default='', help=_("Name of the FWaaS Driver")), cfg.BoolOpt( 'enabled', diff --git a/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py b/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py index 9b849a5b3..75477e839 100644 --- a/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py +++ b/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py @@ -67,13 +67,15 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin): self.conf = conf fwaas_driver_class_path = cfg.CONF.fwaas.driver self.fwaas_enabled = cfg.CONF.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) + 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) self.services_sync = False self.root_helper = config.get_root_helper(conf) # setup RPC to msg fwaas plugin @@ -220,6 +222,9 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin): def process_services_sync(self, ctx): """On RPC issues sync with plugin and apply the sync data.""" + # avoid msg to plugin when fwaas is not configured + if not self.fwaas_enabled: + return try: # get all routers routers = self.plugin_rpc.get_routers(ctx) diff --git a/neutron/services/firewall/drivers/fwaas_base.py b/neutron/services/firewall/drivers/fwaas_base.py index 7128e251a..0e3fb25a3 100644 --- a/neutron/services/firewall/drivers/fwaas_base.py +++ b/neutron/services/firewall/drivers/fwaas_base.py @@ -98,23 +98,3 @@ class FwaasDriverBase(object): interfaces. """ pass - - -class NoopFwaasDriver(FwaasDriverBase): - """Noop Fwaas Driver. - - Firewall driver which does nothing. - This driver is for disabling Fwaas functionality. - """ - - def create_firewall(self, apply_list, firewall): - pass - - def delete_firewall(self, apply_list, firewall): - pass - - def update_firewall(self, apply_list, firewall): - pass - - def apply_default_policy(self, apply_list, firewall): - pass diff --git a/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py b/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py index 6b76c2ed0..d9c6a640c 100644 --- a/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py +++ b/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py @@ -32,6 +32,7 @@ from neutron import context from neutron.plugins.common import constants from neutron.services.firewall.agents.l3reference import firewall_l3_agent from neutron.tests import base +from neutron.tests.unit.services.firewall.agents import test_firewall_agent_api class FWaasHelper(object): @@ -55,6 +56,7 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase): agent_config.register_root_helper(self.conf) self.conf.root_helper = 'sudo' self.api = FWaasAgent(self.conf) + self.api.fwaas_driver = test_firewall_agent_api.NoopFwaasDriver() def test_create_firewall(self): fake_firewall = {'id': 0} diff --git a/neutron/tests/unit/services/firewall/agents/test_firewall_agent_api.py b/neutron/tests/unit/services/firewall/agents/test_firewall_agent_api.py index 6ce0215c4..de3a60a82 100644 --- a/neutron/tests/unit/services/firewall/agents/test_firewall_agent_api.py +++ b/neutron/tests/unit/services/firewall/agents/test_firewall_agent_api.py @@ -23,9 +23,30 @@ import contextlib import mock from neutron.services.firewall.agents import firewall_agent_api as api +from neutron.services.firewall.drivers import fwaas_base as base_driver from neutron.tests import base +class NoopFwaasDriver(base_driver.FwaasDriverBase): + """Noop Fwaas Driver. + + Firewall driver which does nothing. + This driver is for disabling Fwaas functionality. + """ + + def create_firewall(self, apply_list, firewall): + pass + + def delete_firewall(self, apply_list, firewall): + pass + + def update_firewall(self, apply_list, firewall): + pass + + def apply_default_policy(self, apply_list, firewall): + pass + + class TestFWaaSAgentApi(base.BaseTestCase): def setUp(self): super(TestFWaaSAgentApi, self).setUp()