From: armando-migliaccio Date: Fri, 9 Jan 2015 00:12:41 +0000 (-0800) Subject: Break out config and entry point out of l3/agent file X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2062a788d6da7a0760e826b477a316257fa33bd0;p=openstack-build%2Fneutron-build.git Break out config and entry point out of l3/agent file This is done in order to show the split between a main() and the agent's inner workings. At the same time the L3 agent for Neutron is also being restructured and to this aim, its config is also moved out of the agent file. Keep main() for the time being until we get dependent services updated. Partially-Implements: bp restructure-l3-agent Partially-Implements: bp core-vendor-decomposition Change-Id: I0d07d91ba301ee1aa51dabcf964a96edc0d6a3e0 --- diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 6579566d7..ee2dc56da 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -13,8 +13,6 @@ # under the License. # -import sys - import eventlet eventlet.monkey_patch() @@ -31,13 +29,10 @@ from neutron.agent.l3 import event_observers from neutron.agent.l3 import ha from neutron.agent.l3 import router_info from neutron.agent.l3 import router_processing_queue as queue -from neutron.agent.linux import external_process -from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.agent.linux import ra from neutron.agent.metadata import driver as metadata_driver from neutron.agent import rpc as agent_rpc -from neutron.common import config as common_config from neutron.common import constants as l3_constants from neutron.common import exceptions as n_exc from neutron.common import ipv6_utils @@ -50,8 +45,6 @@ from neutron import manager from neutron.openstack.common import log as logging from neutron.openstack.common import loopingcall from neutron.openstack.common import periodic_task -from neutron.openstack.common import service -from neutron import service as neutron_service from neutron.services import advanced_service as adv_svc try: from neutron_fwaas.services.firewall.agents.l3reference \ @@ -147,61 +140,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, """ target = messaging.Target(version='1.2') - OPTS = [ - cfg.StrOpt('agent_mode', default='legacy', - help=_("The working mode for the agent. Allowed modes are: " - "'legacy' - this preserves the existing behavior " - "where the L3 agent is deployed on a centralized " - "networking node to provide L3 services like DNAT, " - "and SNAT. Use this mode if you do not want to " - "adopt DVR. 'dvr' - this mode enables DVR " - "functionality and must be used for an L3 agent " - "that runs on a compute host. 'dvr_snat' - this " - "enables centralized SNAT support in conjunction " - "with DVR. This mode must be used for an L3 agent " - "running on a centralized node (or in single-host " - "deployments, e.g. devstack)")), - cfg.StrOpt('external_network_bridge', default='br-ex', - help=_("Name of bridge used for external network " - "traffic.")), - cfg.IntOpt('metadata_port', - default=9697, - help=_("TCP Port used by Neutron metadata namespace " - "proxy.")), - cfg.IntOpt('send_arp_for_ha', - default=3, - help=_("Send this many gratuitous ARPs for HA setup, if " - "less than or equal to 0, the feature is disabled")), - cfg.StrOpt('router_id', default='', - help=_("If namespaces is disabled, the l3 agent can only" - " configure a router that has the matching router " - "ID.")), - cfg.BoolOpt('handle_internal_only_routers', - default=True, - help=_("Agent should implement routers with no gateway")), - cfg.StrOpt('gateway_external_network_id', default='', - help=_("UUID of external network for routers implemented " - "by the agents.")), - cfg.BoolOpt('enable_metadata_proxy', default=True, - help=_("Allow running metadata proxy.")), - cfg.BoolOpt('router_delete_namespaces', default=False, - help=_("Delete namespace after removing a router.")), - cfg.StrOpt('metadata_proxy_socket', - default='$state_path/metadata_proxy', - help=_('Location of Metadata Proxy UNIX domain ' - 'socket')), - cfg.StrOpt('metadata_proxy_user', - default='', - help=_("User (uid or name) running metadata proxy after " - "its initialization (if empty: L3 agent effective " - "user)")), - cfg.StrOpt('metadata_proxy_group', - default='', - help=_("Group (gid or name) running metadata proxy after " - "its initialization (if empty: L3 agent effective " - "group)")) - ] - def __init__(self, host, conf=None): if conf: self.conf = conf @@ -1310,24 +1248,6 @@ class L3NATAgentWithStateReport(L3NATAgent): LOG.info(_LI("agent_updated by server side %s!"), payload) -def _register_opts(conf): - conf.register_opts(L3NATAgent.OPTS) - conf.register_opts(ha.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) - conf.register_opts(external_process.OPTS) - - -def main(manager='neutron.agent.l3.agent.L3NATAgentWithStateReport'): - _register_opts(cfg.CONF) - common_config.init(sys.argv[1:]) - config.setup_logging() - server = neutron_service.Service.create( - binary='neutron-l3-agent', - topic=topics.L3_AGENT, - report_interval=cfg.CONF.AGENT.report_interval, - manager=manager) - service.launch(server).wait() +# TODO(armax): drop as soon as dependent services are updated +from neutron.agent import l3_agent +main = l3_agent.main diff --git a/neutron/agent/l3/config.py b/neutron/agent/l3/config.py new file mode 100644 index 000000000..e094edbe2 --- /dev/null +++ b/neutron/agent/l3/config.py @@ -0,0 +1,73 @@ +# Copyright (c) 2015 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 oslo.config import cfg + + +OPTS = [ + cfg.StrOpt('agent_mode', default='legacy', + help=_("The working mode for the agent. Allowed modes are: " + "'legacy' - this preserves the existing behavior " + "where the L3 agent is deployed on a centralized " + "networking node to provide L3 services like DNAT, " + "and SNAT. Use this mode if you do not want to " + "adopt DVR. 'dvr' - this mode enables DVR " + "functionality and must be used for an L3 agent " + "that runs on a compute host. 'dvr_snat' - this " + "enables centralized SNAT support in conjunction " + "with DVR. This mode must be used for an L3 agent " + "running on a centralized node (or in single-host " + "deployments, e.g. devstack)")), + cfg.StrOpt('external_network_bridge', default='br-ex', + help=_("Name of bridge used for external network " + "traffic.")), + cfg.IntOpt('metadata_port', + default=9697, + help=_("TCP Port used by Neutron metadata namespace " + "proxy.")), + cfg.IntOpt('send_arp_for_ha', + default=3, + help=_("Send this many gratuitous ARPs for HA setup, if " + "less than or equal to 0, the feature is disabled")), + cfg.StrOpt('router_id', default='', + help=_("If namespaces is disabled, the l3 agent can only" + " configure a router that has the matching router " + "ID.")), + cfg.BoolOpt('handle_internal_only_routers', + default=True, + help=_("Agent should implement routers with no gateway")), + cfg.StrOpt('gateway_external_network_id', default='', + help=_("UUID of external network for routers implemented " + "by the agents.")), + cfg.BoolOpt('enable_metadata_proxy', default=True, + help=_("Allow running metadata proxy.")), + cfg.BoolOpt('router_delete_namespaces', default=False, + help=_("Delete namespace after removing a router.")), + cfg.StrOpt('metadata_proxy_socket', + default='$state_path/metadata_proxy', + help=_('Location of Metadata Proxy UNIX domain ' + 'socket')), + cfg.StrOpt('metadata_proxy_user', + default='', + help=_("User (uid or name) running metadata proxy after " + "its initialization (if empty: L3 agent effective " + "user)")), + cfg.StrOpt('metadata_proxy_group', + default='', + help=_("Group (gid or name) running metadata proxy after " + "its initialization (if empty: L3 agent effective " + "group)")) +] diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py new file mode 100644 index 000000000..836a3026f --- /dev/null +++ b/neutron/agent/l3_agent.py @@ -0,0 +1,52 @@ +# Copyright (c) 2015 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 sys + +from oslo.config import cfg + +from neutron.agent.common import config +from neutron.agent.l3 import config as l3_config +from neutron.agent.l3 import ha +from neutron.agent.linux import external_process +from neutron.agent.linux import interface +from neutron.common import config as common_config +from neutron.common import topics +from neutron.openstack.common import service +from neutron import service as neutron_service + + +def register_opts(conf): + conf.register_opts(l3_config.OPTS) + conf.register_opts(ha.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) + conf.register_opts(external_process.OPTS) + + +def main(manager='neutron.agent.l3.agent.L3NATAgentWithStateReport'): + register_opts(cfg.CONF) + common_config.init(sys.argv[1:]) + config.setup_logging() + server = neutron_service.Service.create( + binary='neutron-l3-agent', + topic=topics.L3_AGENT, + report_interval=cfg.CONF.AGENT.report_interval, + manager=manager) + service.launch(server).wait() diff --git a/neutron/agent/ovs_cleanup_util.py b/neutron/agent/ovs_cleanup_util.py index 2f9ca68ca..63e4e2949 100644 --- a/neutron/agent/ovs_cleanup_util.py +++ b/neutron/agent/ovs_cleanup_util.py @@ -16,7 +16,7 @@ from oslo.config import cfg from neutron.agent.common import config as agent_config -from neutron.agent.l3 import agent +from neutron.agent.l3 import config as l3_config from neutron.agent.linux import interface from neutron.agent.linux import ip_lib from neutron.agent.linux import ovs_lib @@ -45,7 +45,7 @@ def setup_conf(): conf = cfg.CONF conf.register_cli_opts(opts) - conf.register_opts(agent.L3NATAgent.OPTS) + conf.register_opts(l3_config.OPTS) conf.register_opts(interface.OPTS) agent_config.register_interface_driver_opts_helper(conf) agent_config.register_use_namespaces_opts_helper(conf) diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py index c8270d8d6..1300f6644 100644 --- a/neutron/tests/functional/agent/test_l3_agent.py +++ b/neutron/tests/functional/agent/test_l3_agent.py @@ -25,6 +25,7 @@ import webob.exc from neutron.agent.common import config as agent_config from neutron.agent.l3 import agent as l3_agent +from neutron.agent import l3_agent as l3_agent_main from neutron.agent.linux import dhcp from neutron.agent.linux import external_process from neutron.agent.linux import ip_lib @@ -64,7 +65,7 @@ class L3AgentTestFramework(base.BaseOVSLinuxTestCase): def _configure_agent(self, host): conf = self._get_config_opts() - l3_agent._register_opts(conf) + l3_agent_main.register_opts(conf) cfg.CONF.set_override('debug', False) agent_config.setup_logging() conf.set_override( diff --git a/neutron/tests/unit/agent/metadata/test_driver.py b/neutron/tests/unit/agent/metadata/test_driver.py index fda074c6b..e17ee59f8 100644 --- a/neutron/tests/unit/agent/metadata/test_driver.py +++ b/neutron/tests/unit/agent/metadata/test_driver.py @@ -20,7 +20,7 @@ import mock from oslo.config import cfg from neutron.agent.common import config as agent_config -from neutron.agent.l3 import agent as l3_agent +from neutron.agent.l3 import config as l3_config from neutron.agent.metadata import driver as metadata_driver from neutron.openstack.common import uuidutils from neutron.tests import base @@ -36,7 +36,7 @@ class TestMetadataDriver(base.BaseTestCase): def setUp(self): super(TestMetadataDriver, self).setUp() - cfg.CONF.register_opts(l3_agent.L3NATAgent.OPTS) + cfg.CONF.register_opts(l3_config.OPTS) agent_config.register_root_helper(cfg.CONF) def test_metadata_nat_rules(self): diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index c64a30391..3f4bf7aea 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -24,6 +24,7 @@ from testtools import matchers from neutron.agent.common import config as agent_config from neutron.agent.l3 import agent as l3_agent +from neutron.agent.l3 import config as l3_config from neutron.agent.l3 import dvr from neutron.agent.l3 import ha from neutron.agent.l3 import link_local_allocator as lla @@ -168,7 +169,7 @@ class TestBasicRouterOperations(base.BaseTestCase): self.conf.register_opts(base_config.core_opts) self.conf.register_cli_opts(log.common_cli_opts) self.conf.register_cli_opts(log.logging_cli_opts) - self.conf.register_opts(l3_agent.L3NATAgent.OPTS) + self.conf.register_opts(l3_config.OPTS) self.conf.register_opts(ha.OPTS) agent_config.register_interface_driver_opts_helper(self.conf) agent_config.register_use_namespaces_opts_helper(self.conf) diff --git a/setup.cfg b/setup.cfg index f9d65f289..e54f58cda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -103,7 +103,7 @@ console_scripts = neutron-dhcp-agent = neutron.agent.dhcp_agent:main neutron-hyperv-agent = neutron.plugins.hyperv.agent.hyperv_neutron_agent:main neutron-ibm-agent = neutron.plugins.ibm.agent.sdnve_neutron_agent:main - neutron-l3-agent = neutron.agent.l3.agent:main + neutron-l3-agent = neutron.agent.l3_agent:main neutron-linuxbridge-agent = neutron.plugins.linuxbridge.agent.linuxbridge_neutron_agent:main neutron-metadata-agent = neutron.agent.metadata.agent:main neutron-mlnx-agent = neutron.plugins.mlnx.agent.eswitch_neutron_agent:main