]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Break out config and entry point out of l3/agent file
authorarmando-migliaccio <armamig@gmail.com>
Fri, 9 Jan 2015 00:12:41 +0000 (16:12 -0800)
committerarmando-migliaccio <armamig@gmail.com>
Fri, 9 Jan 2015 03:19:14 +0000 (19:19 -0800)
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

neutron/agent/l3/agent.py
neutron/agent/l3/config.py [new file with mode: 0644]
neutron/agent/l3_agent.py [new file with mode: 0644]
neutron/agent/ovs_cleanup_util.py
neutron/tests/functional/agent/test_l3_agent.py
neutron/tests/unit/agent/metadata/test_driver.py
neutron/tests/unit/test_l3_agent.py
setup.cfg

index 6579566d7b242bb3f6ee92f0fd5d017b82ec244b..ee2dc56daa74e468c7ea17209007edb012467774 100644 (file)
@@ -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 (file)
index 0000000..e094edb
--- /dev/null
@@ -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 (file)
index 0000000..836a302
--- /dev/null
@@ -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()
index 2f9ca68ca479e608f22feb608b9047cc2b270837..63e4e29491d8a78c55faf12e09d95ed42f696f14 100644 (file)
@@ -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)
index c8270d8d6c53a1d453911498ee5c1a5bedc23a79..1300f6644d97b0003e3571b32bca91da18cf1a76 100644 (file)
@@ -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(
index fda074c6b60c912c0358d83b88c57e5575d9a9fb..e17ee59f83d3521b0934ee01a3d5016c30042b77 100644 (file)
@@ -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):
index c64a303912385d5d2a9c8ef1b68039e3d1fca6b4..3f4bf7aeabebd60cbf63d05daeef9b4bbac61691 100644 (file)
@@ -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)
index f9d65f289e7f8d5141f72e2fd9b93218211bd5e5..e54f58cda0ec82e401b1d75bca0e4a7967c50774 100644 (file)
--- 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