From 7f9610c591b209392bc4a169fc8321d834135255 Mon Sep 17 00:00:00 2001 From: Aradhana Singh Date: Tue, 31 May 2016 00:45:44 +0000 Subject: [PATCH] Refactoring config options for cmd Refactoring neutron configuration options for cmd to be in neutron/conf. This would allow centralization of all configuration options and provide an easy way to import. Change-Id: I0bb7c88050aa5e931a53406d29b5b10c69c518bb Partial-Bug: #1563069 --- neutron/cmd/ipset_cleanup.py | 20 ++----- neutron/cmd/netns_cleanup.py | 14 ++--- neutron/cmd/ovs_cleanup.py | 13 ++--- neutron/conf/agent/cmd.py | 52 +++++++++++++++++++ .../functional/cmd/test_ipset_cleanup.py | 31 +++++++++++ .../functional/cmd/test_netns_cleanup.py | 16 ++++++ .../tests/functional/cmd/test_ovs_cleanup.py | 28 ++++++++++ 7 files changed, 136 insertions(+), 38 deletions(-) create mode 100644 neutron/conf/agent/cmd.py create mode 100644 neutron/tests/functional/cmd/test_ipset_cleanup.py create mode 100644 neutron/tests/functional/cmd/test_ovs_cleanup.py diff --git a/neutron/cmd/ipset_cleanup.py b/neutron/cmd/ipset_cleanup.py index 9448b44eafe..053b1791417 100644 --- a/neutron/cmd/ipset_cleanup.py +++ b/neutron/cmd/ipset_cleanup.py @@ -16,10 +16,10 @@ from oslo_config import cfg from oslo_log import log as logging -from neutron._i18n import _, _LE, _LI -from neutron.agent.linux import ipset_manager +from neutron._i18n import _LE, _LI from neutron.agent.linux import utils from neutron.common import config +from neutron.conf.agent import cmd as command LOG = logging.getLogger(__name__) @@ -31,22 +31,8 @@ def setup_conf(): Use separate setup_conf for the utility because there are many options from the main config that do not apply during clean-up. """ - - cli_opts = [ - cfg.BoolOpt('allsets', - default=False, - help=_('Destroy all IPsets.')), - cfg.BoolOpt('force', - default=False, - help=_('Destroy IPsets even if there is an iptables ' - 'reference.')), - cfg.StrOpt('prefix', - default=ipset_manager.NET_PREFIX, - help=_('String prefix used to match IPset names.')), - ] - conf = cfg.CONF - conf.register_cli_opts(cli_opts) + command.register_cmd_opts(command.ip_opts, conf) return conf diff --git a/neutron/cmd/netns_cleanup.py b/neutron/cmd/netns_cleanup.py index 8ea8aa8bcea..2460138bbf2 100644 --- a/neutron/cmd/netns_cleanup.py +++ b/neutron/cmd/netns_cleanup.py @@ -22,7 +22,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils -from neutron._i18n import _, _LE +from neutron._i18n import _LE from neutron.agent.common import config as agent_config from neutron.agent.common import ovs_lib from neutron.agent.l3 import agent as l3_agent @@ -33,6 +33,7 @@ from neutron.agent.linux import external_process from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.common import config +from neutron.conf.agent import cmd from neutron.conf.agent import dhcp as dhcp_config @@ -60,17 +61,8 @@ def setup_conf(): from the main config that do not apply during clean-up. """ - cli_opts = [ - cfg.BoolOpt('force', - default=False, - help=_('Delete the namespace by removing all devices.')), - cfg.StrOpt('agent-type', - choices=['dhcp', 'l3', 'lbaas'], - help=_('Cleanup resources of a specific agent type only.')), - ] - conf = cfg.CONF - conf.register_cli_opts(cli_opts) + cmd.register_cmd_opts(cmd.netns_opts, conf) agent_config.register_interface_driver_opts_helper(conf) dhcp_config.register_agent_dhcp_opts(conf) conf.register_opts(interface.OPTS) diff --git a/neutron/cmd/ovs_cleanup.py b/neutron/cmd/ovs_cleanup.py index 16eb3c2f58e..feec533d2d9 100644 --- a/neutron/cmd/ovs_cleanup.py +++ b/neutron/cmd/ovs_cleanup.py @@ -16,12 +16,13 @@ from oslo_config import cfg from oslo_log import log as logging -from neutron._i18n import _, _LI +from neutron._i18n import _LI from neutron.agent.common import config as agent_config from neutron.agent.common import ovs_lib from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.common import config +from neutron.conf.agent import cmd from neutron.conf.agent.l3 import config as l3_config @@ -34,17 +35,9 @@ def setup_conf(): Use separate setup_conf for the utility because there are many options from the main config that do not apply during clean-up. """ - opts = [ - cfg.BoolOpt('ovs_all_ports', - default=False, - help=_('True to delete all ports on all the OpenvSwitch ' - 'bridges. False to delete ports created by ' - 'Neutron on integration and external network ' - 'bridges.')) - ] conf = cfg.CONF - conf.register_cli_opts(opts) + cmd.register_cmd_opts(cmd.ovs_opts, conf) l3_config.register_l3_agent_config_opts(l3_config.OPTS, conf) conf.register_opts(interface.OPTS) agent_config.register_interface_driver_opts_helper(conf) diff --git a/neutron/conf/agent/cmd.py b/neutron/conf/agent/cmd.py new file mode 100644 index 00000000000..4e7d4b95511 --- /dev/null +++ b/neutron/conf/agent/cmd.py @@ -0,0 +1,52 @@ +# 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 oslo_config import cfg + +from neutron._i18n import _ +from neutron.agent.linux import ipset_manager + + +ip_opts = [ + cfg.BoolOpt('allsets', + default=False, + help=_('Destroy all IPsets.')), + cfg.BoolOpt('force', + default=False, + help=_('Destroy IPsets even if there is an iptables ' + 'reference.')), + cfg.StrOpt('prefix', + default=ipset_manager.NET_PREFIX, + help=_('String prefix used to match IPset names.')), +] + +netns_opts = [ + cfg.BoolOpt('force', + default=False, + help=_('Delete the namespace by removing all devices.')), + cfg.StrOpt('agent-type', + choices=['dhcp', 'l3', 'lbaas'], + help=_('Cleanup resources of a specific agent type only.')), +] + +ovs_opts = [ + cfg.BoolOpt('ovs_all_ports', + default=False, + help=_('True to delete all ports on all the OpenvSwitch ' + 'bridges. False to delete ports created by ' + 'Neutron on integration and external network ' + 'bridges.')) +] + + +def register_cmd_opts(opts, cfg=cfg.CONF): + cfg.register_cli_opts(opts) diff --git a/neutron/tests/functional/cmd/test_ipset_cleanup.py b/neutron/tests/functional/cmd/test_ipset_cleanup.py new file mode 100644 index 00000000000..8a9cb2b0218 --- /dev/null +++ b/neutron/tests/functional/cmd/test_ipset_cleanup.py @@ -0,0 +1,31 @@ +# 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.agent.linux import ipset_manager +from neutron.cmd import ipset_cleanup +from neutron.conf.agent import cmd +from neutron.tests import base + + +class TestIPSetCLIConfig(base.BaseTestCase): + + def setup_config(self, args=None): + self.conf = ipset_cleanup.setup_conf() + super(TestIPSetCLIConfig, self).setup_config(args=args) + + def test_ipset_opts_registration(self): + self.assertFalse(self.conf.allsets) + self.assertFalse(self.conf.force) + self.assertEqual(ipset_manager.NET_PREFIX, self.conf.prefix) + # to unregister opts + self.conf.reset() + self.conf.unregister_opts(cmd.ip_opts) diff --git a/neutron/tests/functional/cmd/test_netns_cleanup.py b/neutron/tests/functional/cmd/test_netns_cleanup.py index 92ca83fa426..5b45e57b050 100644 --- a/neutron/tests/functional/cmd/test_netns_cleanup.py +++ b/neutron/tests/functional/cmd/test_netns_cleanup.py @@ -19,6 +19,8 @@ from neutron.agent.l3 import agent as l3_agent from neutron.agent.linux import dhcp from neutron.agent.linux import ip_lib from neutron.cmd import netns_cleanup +from neutron.conf.agent import cmd +from neutron.tests import base as basetest from neutron.tests.common import net_helpers from neutron.tests.functional import base @@ -64,3 +66,17 @@ class NetnsCleanupTest(base.BaseSudoTestCase): namespaces_now = ip_lib.IPWrapper.get_namespaces() self.assertNotIn(l3_namespace, namespaces_now) self.assertNotIn(dhcp_namespace, namespaces_now) + + +class TestNETNSCLIConfig(basetest.BaseTestCase): + + def setup_config(self, args=None): + self.conf = netns_cleanup.setup_conf() + super(TestNETNSCLIConfig, self).setup_config(args=args) + + def test_netns_opts_registration(self): + self.assertFalse(self.conf.force) + self.assertIsNone(self.conf.get('agent_type')) + # to unregister opts + self.conf.reset() + self.conf.unregister_opts(cmd.netns_opts) diff --git a/neutron/tests/functional/cmd/test_ovs_cleanup.py b/neutron/tests/functional/cmd/test_ovs_cleanup.py new file mode 100644 index 00000000000..8bf3ac4553f --- /dev/null +++ b/neutron/tests/functional/cmd/test_ovs_cleanup.py @@ -0,0 +1,28 @@ +# 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.cmd import ovs_cleanup +from neutron.conf.agent import cmd +from neutron.tests import base + + +class TestOVSCLIConfig(base.BaseTestCase): + + def setup_config(self, args=None): + self.conf = ovs_cleanup.setup_conf() + super(TestOVSCLIConfig, self).setup_config(args=args) + + def test_ovs_opts_registration(self): + self.assertFalse(self.conf.ovs_all_ports) + # to unregister opts + self.conf.reset() + self.conf.unregister_opts(cmd.ovs_opts)