From 07c758fd5da89fc2360634bd72e2b920cb7d452e Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 13 Feb 2014 20:19:25 +0900 Subject: [PATCH] options: consolidate options definitions Some config options(interface_driver, use_namespaces) are defined multiple times in ad-hoc way. It causes DuplicateOptError exception when using those module at the same time. Right now the exception is avoided in ad-hoc way by each executable. Those duplicated definitions should be consolidated and treated in uniformed way. This is the blocker for blueprint: l3-agent-consolidation neutron.services.loadbalancer.drivers.haproxy.agent periodic_interval conflicts with neutron.service one. Since there is no way to fix it without changing existing behavior/default value, it is untouched for now. Closes-bug: #1279769 Change-Id: Ifed79b7ee0033644854499416f8a2b22a20416fe --- neutron/agent/common/config.py | 18 ++++++++++++++++++ neutron/agent/dhcp_agent.py | 4 ++-- neutron/agent/l3_agent.py | 7 ++----- neutron/agent/linux/dhcp.py | 2 -- neutron/agent/netns_cleanup_util.py | 1 + neutron/agent/ovs_cleanup_util.py | 2 ++ neutron/debug/debug_agent.py | 5 ----- neutron/debug/shell.py | 2 ++ .../firewall/agents/varmour/varmour_router.py | 2 ++ neutron/services/loadbalancer/agent/agent.py | 1 + .../loadbalancer/agent/agent_manager.py | 4 ---- .../drivers/iptables/iptables_driver.py | 10 ++-------- .../tests/unit/midonet/test_midonet_driver.py | 1 + .../l3reference/test_firewall_l3_agent.py | 1 + .../agents/varmour/test_varmour_router.py | 2 ++ .../drivers/varmour/test_varmour_fwaas.py | 2 ++ .../tests/unit/services/vpn/test_vpn_agent.py | 2 ++ neutron/tests/unit/test_debug_commands.py | 4 +++- neutron/tests/unit/test_dhcp_agent.py | 4 ++++ neutron/tests/unit/test_l3_agent.py | 2 ++ neutron/tests/unit/test_linux_dhcp.py | 1 + neutron/tests/unit/test_linux_interface.py | 1 + 22 files changed, 51 insertions(+), 27 deletions(-) diff --git a/neutron/agent/common/config.py b/neutron/agent/common/config.py index 4bf3710ee..33e23945b 100644 --- a/neutron/agent/common/config.py +++ b/neutron/agent/common/config.py @@ -38,6 +38,16 @@ AGENT_STATE_OPTS = [ 'is half or less than agent_down_time.')), ] +INTERFACE_DRIVER_OPTS = [ + cfg.StrOpt('interface_driver', + help=_("The driver used to manage the virtual interface.")), +] + +USE_NAMESPACES_OPTS = [ + cfg.BoolOpt('use_namespaces', default=True, + help=_("Allow overlapping IP.")), +] + def get_log_args(conf, log_file_name): cmd_args = [] @@ -76,6 +86,14 @@ def register_agent_state_opts_helper(conf): conf.register_opts(AGENT_STATE_OPTS, 'AGENT') +def register_interface_driver_opts_helper(conf): + conf.register_opts(INTERFACE_DRIVER_OPTS) + + +def register_use_namespaces_opts_helper(conf): + conf.register_opts(USE_NAMESPACES_OPTS) + + def get_root_helper(conf): root_helper = conf.AGENT.root_helper if root_helper != 'sudo': diff --git a/neutron/agent/dhcp_agent.py b/neutron/agent/dhcp_agent.py index 5cdacab57..ae597cd42 100644 --- a/neutron/agent/dhcp_agent.py +++ b/neutron/agent/dhcp_agent.py @@ -52,8 +52,6 @@ class DhcpAgent(manager.Manager): cfg.StrOpt('dhcp_driver', default='neutron.agent.linux.dhcp.Dnsmasq', help=_("The driver used to manage the DHCP server.")), - cfg.BoolOpt('use_namespaces', default=True, - help=_("Allow overlapping IP.")), cfg.BoolOpt('enable_isolated_metadata', default=False, help=_("Support Metadata requests on isolated networks.")), cfg.BoolOpt('enable_metadata_network', default=False, @@ -589,6 +587,8 @@ class DhcpAgentWithStateReport(DhcpAgent): def register_options(): cfg.CONF.register_opts(DhcpAgent.OPTS) + config.register_interface_driver_opts_helper(cfg.CONF) + config.register_use_namespaces_opts_helper(cfg.CONF) config.register_agent_state_opts_helper(cfg.CONF) config.register_root_helper(cfg.CONF) cfg.CONF.register_opts(dhcp.OPTS) diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py index c9a01c2f4..21d095773 100644 --- a/neutron/agent/l3_agent.py +++ b/neutron/agent/l3_agent.py @@ -157,9 +157,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager): cfg.StrOpt('external_network_bridge', default='br-ex', help=_("Name of bridge used for external network " "traffic.")), - cfg.StrOpt('interface_driver', - help=_("The driver used to manage the virtual " - "interface.")), cfg.IntOpt('metadata_port', default=9697, help=_("TCP Port used by Neutron metadata namespace " @@ -168,8 +165,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager): default=0, help=_("Send this many gratuitous ARPs for HA setup, if " "less than or equal to 0, the feature is disabled")), - cfg.BoolOpt('use_namespaces', default=True, - help=_("Allow overlapping IP.")), cfg.StrOpt('router_id', default='', help=_("If namespaces is disabled, the l3 agent can only" " configure a router that has the matching router " @@ -916,6 +911,8 @@ def main(manager='neutron.agent.l3_agent.L3NATAgentWithStateReport'): eventlet.monkey_patch() conf = cfg.CONF conf.register_opts(L3NATAgent.OPTS) + config.register_interface_driver_opts_helper(conf) + config.register_use_namespaces_opts_helper(conf) config.register_agent_state_opts_helper(conf) config.register_root_helper(conf) conf.register_opts(interface.OPTS) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index e1682d8ac..08cedfdcf 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -59,8 +59,6 @@ OPTS = [ 'dnsmasq_lease_max', default=(2 ** 24), help=_('Limit number of leases to prevent a denial-of-service.')), - cfg.StrOpt('interface_driver', - help=_("The driver used to manage the virtual interface.")), ] IPV4 = 4 diff --git a/neutron/agent/netns_cleanup_util.py b/neutron/agent/netns_cleanup_util.py index 9c17f715f..2551299cd 100644 --- a/neutron/agent/netns_cleanup_util.py +++ b/neutron/agent/netns_cleanup_util.py @@ -63,6 +63,7 @@ def setup_conf(): conf = cfg.CONF conf.register_cli_opts(cli_opts) conf.register_opts(opts) + agent_config.register_interface_driver_opts_helper(conf) agent_config.register_root_helper(conf) conf.register_opts(dhcp.OPTS) return conf diff --git a/neutron/agent/ovs_cleanup_util.py b/neutron/agent/ovs_cleanup_util.py index 51bf1d459..f7a388b3d 100644 --- a/neutron/agent/ovs_cleanup_util.py +++ b/neutron/agent/ovs_cleanup_util.py @@ -48,6 +48,8 @@ def setup_conf(): conf.register_cli_opts(opts) conf.register_opts(l3_agent.L3NATAgent.OPTS) conf.register_opts(interface.OPTS) + agent_config.register_interface_driver_opts_helper(conf) + agent_config.register_use_namespaces_opts_helper(conf) agent_config.register_root_helper(conf) return conf diff --git a/neutron/debug/debug_agent.py b/neutron/debug/debug_agent.py index 718475572..15bbf3d4a 100644 --- a/neutron/debug/debug_agent.py +++ b/neutron/debug/debug_agent.py @@ -39,11 +39,6 @@ class NeutronDebugAgent(): OPTS = [ # Needed for drivers - cfg.BoolOpt('use_namespaces', default=True, - help=_("Use Linux network namespaces")), - cfg.StrOpt('interface_driver', - help=_("The driver used to manage the virtual " - "interface.")), cfg.StrOpt('external_network_bridge', default='br-ex', help=_("Name of bridge used for external network " "traffic.")), diff --git a/neutron/debug/shell.py b/neutron/debug/shell.py index 103c43014..42793f721 100644 --- a/neutron/debug/shell.py +++ b/neutron/debug/shell.py @@ -74,6 +74,8 @@ class NeutronDebugShell(NeutronShell): client = self.client_manager.neutron cfg.CONF.register_opts(interface.OPTS) cfg.CONF.register_opts(NeutronDebugAgent.OPTS) + config.register_interface_driver_opts_helper(cfg.CONF) + config.register_use_namespaces_opts_helper(cfg.CONF) config.register_root_helper(cfg.CONF) cfg.CONF(['--config-file', self.options.config_file]) config.setup_logging(cfg.CONF) diff --git a/neutron/services/firewall/agents/varmour/varmour_router.py b/neutron/services/firewall/agents/varmour/varmour_router.py index b359ae180..25cf02ffa 100755 --- a/neutron/services/firewall/agents/varmour/varmour_router.py +++ b/neutron/services/firewall/agents/varmour/varmour_router.py @@ -331,6 +331,8 @@ def main(): eventlet.monkey_patch() conf = cfg.CONF conf.register_opts(vArmourL3NATAgent.OPTS) + config.register_interface_driver_opts_helper(conf) + config.register_use_namespaces_opts_helper(conf) config.register_agent_state_opts_helper(conf) config.register_root_helper(conf) conf.register_opts(interface.OPTS) diff --git a/neutron/services/loadbalancer/agent/agent.py b/neutron/services/loadbalancer/agent/agent.py index 64f661c91..3a7116c2b 100644 --- a/neutron/services/loadbalancer/agent/agent.py +++ b/neutron/services/loadbalancer/agent/agent.py @@ -53,6 +53,7 @@ def main(): cfg.CONF.register_opts(manager.OPTS) # import interface options just in case the driver uses namespaces cfg.CONF.register_opts(interface.OPTS) + config.register_interface_driver_opts_helper(cfg.CONF) config.register_agent_state_opts_helper(cfg.CONF) config.register_root_helper(cfg.CONF) diff --git a/neutron/services/loadbalancer/agent/agent_manager.py b/neutron/services/loadbalancer/agent/agent_manager.py index 9517fae9b..91b453071 100644 --- a/neutron/services/loadbalancer/agent/agent_manager.py +++ b/neutron/services/loadbalancer/agent/agent_manager.py @@ -39,10 +39,6 @@ OPTS = [ '.haproxy.namespace_driver.HaproxyNSDriver'], help=_('Drivers used to manage loadbalancing devices'), ), - cfg.StrOpt( - 'interface_driver', - help=_('The driver used to manage the virtual interface') - ), ] diff --git a/neutron/services/metering/drivers/iptables/iptables_driver.py b/neutron/services/metering/drivers/iptables/iptables_driver.py index cd5e41c0f..33a4d27b6 100644 --- a/neutron/services/metering/drivers/iptables/iptables_driver.py +++ b/neutron/services/metering/drivers/iptables/iptables_driver.py @@ -34,16 +34,10 @@ TOP_CHAIN = WRAP_NAME + "-FORWARD" RULE = '-r-' LABEL = '-l-' -IptablesDriverOpts = [ - cfg.StrOpt('interface_driver', - help=_("The driver used to manage the virtual " - "interface.")), - cfg.BoolOpt('use_namespaces', default=True, - help=_("Allow overlapping IP.")) -] +config.register_interface_driver_opts_helper(cfg.CONF) +config.register_use_namespaces_opts_helper(cfg.CONF) config.register_root_helper(cfg.CONF) cfg.CONF.register_opts(interface.OPTS) -cfg.CONF.register_opts(IptablesDriverOpts) class IptablesManagerTransaction(object): diff --git a/neutron/tests/unit/midonet/test_midonet_driver.py b/neutron/tests/unit/midonet/test_midonet_driver.py index cc550cfbe..dc33bcef1 100644 --- a/neutron/tests/unit/midonet/test_midonet_driver.py +++ b/neutron/tests/unit/midonet/test_midonet_driver.py @@ -38,6 +38,7 @@ class TestDhcpNoOpDriver(base.BaseTestCase): def setUp(self): super(TestDhcpNoOpDriver, self).setUp() self.conf = config.setup_conf() + config.register_interface_driver_opts_helper(self.conf) self.conf.register_opts(base_config.core_opts) self.conf.register_opts(dhcp.OPTS) self.conf.enable_isolated_metadata = True 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 d9c6a640c..7933a3497 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 @@ -53,6 +53,7 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase): self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(l3_agent.L3NATAgent.OPTS) + agent_config.register_use_namespaces_opts_helper(self.conf) agent_config.register_root_helper(self.conf) self.conf.root_helper = 'sudo' self.api = FWaasAgent(self.conf) diff --git a/neutron/tests/unit/services/firewall/agents/varmour/test_varmour_router.py b/neutron/tests/unit/services/firewall/agents/varmour/test_varmour_router.py index b56114380..3a7ddd8b9 100644 --- a/neutron/tests/unit/services/firewall/agents/varmour/test_varmour_router.py +++ b/neutron/tests/unit/services/firewall/agents/varmour/test_varmour_router.py @@ -44,6 +44,8 @@ class TestVarmourRouter(base.BaseTestCase): self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(varmour_router.vArmourL3NATAgent.OPTS) + agent_config.register_interface_driver_opts_helper(self.conf) + agent_config.register_use_namespaces_opts_helper(self.conf) agent_config.register_root_helper(self.conf) self.conf.register_opts(interface.OPTS) self.conf.set_override('interface_driver', diff --git a/neutron/tests/unit/services/firewall/drivers/varmour/test_varmour_fwaas.py b/neutron/tests/unit/services/firewall/drivers/varmour/test_varmour_fwaas.py index 79dfbfbb9..7c6bd6673 100644 --- a/neutron/tests/unit/services/firewall/drivers/varmour/test_varmour_fwaas.py +++ b/neutron/tests/unit/services/firewall/drivers/varmour/test_varmour_fwaas.py @@ -45,6 +45,8 @@ class TestBasicRouterOperations(base.BaseTestCase): self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(varmour_router.vArmourL3NATAgent.OPTS) + agent_config.register_interface_driver_opts_helper(self.conf) + agent_config.register_use_namespaces_opts_helper(self.conf) agent_config.register_root_helper(self.conf) self.conf.register_opts(interface.OPTS) self.conf.set_override('interface_driver', diff --git a/neutron/tests/unit/services/vpn/test_vpn_agent.py b/neutron/tests/unit/services/vpn/test_vpn_agent.py index f22c18c0b..4e6043517 100644 --- a/neutron/tests/unit/services/vpn/test_vpn_agent.py +++ b/neutron/tests/unit/services/vpn/test_vpn_agent.py @@ -52,6 +52,8 @@ class TestVPNAgent(base.BaseTestCase): self.conf.register_opts(base_config.core_opts) self.conf.register_opts(l3_agent.L3NATAgent.OPTS) self.conf.register_opts(interface.OPTS) + agent_config.register_interface_driver_opts_helper(self.conf) + agent_config.register_use_namespaces_opts_helper(self.conf) agent_config.register_agent_state_opts_helper(self.conf) agent_config.register_root_helper(self.conf) diff --git a/neutron/tests/unit/test_debug_commands.py b/neutron/tests/unit/test_debug_commands.py index de60b0adc..15b62f0e6 100644 --- a/neutron/tests/unit/test_debug_commands.py +++ b/neutron/tests/unit/test_debug_commands.py @@ -40,8 +40,10 @@ class TestDebugCommands(base.BaseTestCase): cfg.CONF.register_opts(interface.OPTS) cfg.CONF.register_opts(NeutronDebugAgent.OPTS) cfg.CONF(args=[], project='neutron') - cfg.CONF.set_override('use_namespaces', True) + config.register_interface_driver_opts_helper(cfg.CONF) + config.register_use_namespaces_opts_helper(cfg.CONF) config.register_root_helper(cfg.CONF) + cfg.CONF.set_override('use_namespaces', True) self.addCleanup(mock.patch.stopall) device_exists_p = mock.patch( diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index f9f2002f3..e544118fe 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -156,6 +156,7 @@ class TestDhcpAgent(base.BaseTestCase): 'dhcp', '--config-file', etcdir('neutron.conf.test')] cfg.CONF.register_opts(dhcp_agent.DhcpAgent.OPTS) + config.register_interface_driver_opts_helper(cfg.CONF) config.register_agent_state_opts_helper(cfg.CONF) config.register_root_helper(cfg.CONF) cfg.CONF.register_opts(dhcp.OPTS) @@ -449,6 +450,7 @@ class TestLogArgs(base.BaseTestCase): class TestDhcpAgentEventHandler(base.BaseTestCase): def setUp(self): super(TestDhcpAgentEventHandler, self).setUp() + config.register_interface_driver_opts_helper(cfg.CONF) cfg.CONF.register_opts(dhcp.OPTS) cfg.CONF.set_override('interface_driver', 'neutron.agent.linux.interface.NullDriver') @@ -1087,6 +1089,8 @@ class FakeV4NetworkNoGateway: class TestDeviceManager(base.BaseTestCase): def setUp(self): super(TestDeviceManager, self).setUp() + config.register_interface_driver_opts_helper(cfg.CONF) + config.register_use_namespaces_opts_helper(cfg.CONF) cfg.CONF.register_opts(dhcp_agent.DhcpAgent.OPTS) cfg.CONF.register_opts(dhcp.OPTS) cfg.CONF.set_override('interface_driver', diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index 03625dbc7..4d199dbad 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -43,6 +43,8 @@ class TestBasicRouterOperations(base.BaseTestCase): self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(l3_agent.L3NATAgent.OPTS) + agent_config.register_interface_driver_opts_helper(self.conf) + agent_config.register_use_namespaces_opts_helper(self.conf) agent_config.register_root_helper(self.conf) self.conf.register_opts(interface.OPTS) self.conf.set_override('router_id', 'fake_id') diff --git a/neutron/tests/unit/test_linux_dhcp.py b/neutron/tests/unit/test_linux_dhcp.py index 7086a7b7f..1baa17c59 100644 --- a/neutron/tests/unit/test_linux_dhcp.py +++ b/neutron/tests/unit/test_linux_dhcp.py @@ -394,6 +394,7 @@ class TestBase(base.BaseTestCase): self.conf = config.setup_conf() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(dhcp.OPTS) + config.register_interface_driver_opts_helper(self.conf) instance = mock.patch("neutron.agent.linux.dhcp.DeviceManager") self.mock_mgr = instance.start() self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata', diff --git a/neutron/tests/unit/test_linux_interface.py b/neutron/tests/unit/test_linux_interface.py index 43ebd093a..09bf8df27 100644 --- a/neutron/tests/unit/test_linux_interface.py +++ b/neutron/tests/unit/test_linux_interface.py @@ -373,6 +373,7 @@ class TestBridgeInterfaceDriver(TestBase): class TestMetaInterfaceDriver(TestBase): def setUp(self): super(TestMetaInterfaceDriver, self).setUp() + config.register_interface_driver_opts_helper(self.conf) self.conf.register_opts(dhcp.OPTS) self.client_cls_p = mock.patch('neutronclient.v2_0.client.Client') client_cls = self.client_cls_p.start() -- 2.45.2