]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move metadata agent entry to its own file
authorarmando-migliaccio <armamig@gmail.com>
Fri, 9 Jan 2015 18:35:59 +0000 (10:35 -0800)
committerarmando-migliaccio <armamig@gmail.com>
Sat, 10 Jan 2015 03:49:45 +0000 (19:49 -0800)
Break main() and configs out of agent logic. This makes metadata
consistent with the L3 and DHCP agents [1, 2].

Along with [3], this is done to better delineate what the agent module
inner boundaries are about. More to follow to finish off the cleanup.

[1] https://review.openstack.org/#/c/145979/
[2] https://review.openstack.org/#/c/146024/
[3] https://review.openstack.org/#/c/146151/

Change-Id: I2842f7c21db6f6dabdd2549f91a9001220454c22

neutron/agent/metadata/agent.py
neutron/agent/metadata/config.py [new file with mode: 0644]
neutron/agent/metadata_agent.py [new file with mode: 0644]
neutron/tests/unit/test_metadata_agent.py
setup.cfg

index fef96e92ddf9e9accf046813ade4de1e81f52dba..ebfbcbce41db915b1cfc5829b4b1339544ae9f62 100644 (file)
@@ -16,7 +16,6 @@ import hashlib
 import hmac
 import os
 import socket
-import sys
 
 import eventlet
 eventlet.monkey_patch()
@@ -29,9 +28,7 @@ from oslo.utils import excutils
 import six.moves.urllib.parse as urlparse
 import webob
 
-from neutron.agent.common import config as agent_conf
 from neutron.agent import rpc as agent_rpc
-from neutron.common import config
 from neutron.common import constants as n_const
 from neutron.common import rpc as n_rpc
 from neutron.common import topics
@@ -63,54 +60,6 @@ class MetadataPluginAPI(object):
 
 
 class MetadataProxyHandler(object):
-    OPTS = [
-        cfg.StrOpt('admin_user',
-                   help=_("Admin user")),
-        cfg.StrOpt('admin_password',
-                   help=_("Admin password"),
-                   secret=True),
-        cfg.StrOpt('admin_tenant_name',
-                   help=_("Admin tenant name")),
-        cfg.StrOpt('auth_url',
-                   help=_("Authentication URL")),
-        cfg.StrOpt('auth_strategy', default='keystone',
-                   help=_("The type of authentication to use")),
-        cfg.StrOpt('auth_region',
-                   help=_("Authentication region")),
-        cfg.BoolOpt('auth_insecure',
-                    default=False,
-                    help=_("Turn off verification of the certificate for"
-                           " ssl")),
-        cfg.StrOpt('auth_ca_cert',
-                   help=_("Certificate Authority public key (CA cert) "
-                          "file for ssl")),
-        cfg.StrOpt('endpoint_type',
-                   default='adminURL',
-                   help=_("Network service endpoint type to pull from "
-                          "the keystone catalog")),
-        cfg.StrOpt('nova_metadata_ip', default='127.0.0.1',
-                   help=_("IP address used by Nova metadata server.")),
-        cfg.IntOpt('nova_metadata_port',
-                   default=8775,
-                   help=_("TCP Port used by Nova metadata server.")),
-        cfg.StrOpt('metadata_proxy_shared_secret',
-                   default='',
-                   help=_('Shared secret to sign instance-id request'),
-                   secret=True),
-        cfg.StrOpt('nova_metadata_protocol',
-                   default='http',
-                   choices=['http', 'https'],
-                   help=_("Protocol to access nova metadata, http or https")),
-        cfg.BoolOpt('nova_metadata_insecure', default=False,
-                    help=_("Allow to perform insecure SSL (https) requests to "
-                           "nova metadata")),
-        cfg.StrOpt('nova_client_cert',
-                   default='',
-                   help=_("Client certificate for nova metadata api server.")),
-        cfg.StrOpt('nova_client_priv_key',
-                   default='',
-                   help=_("Private key of client certificate."))
-    ]
 
     def __init__(self, conf):
         self.conf = conf
@@ -348,19 +297,6 @@ class UnixDomainWSGIServer(wsgi.Server):
 
 
 class UnixDomainMetadataProxy(object):
-    OPTS = [
-        cfg.StrOpt('metadata_proxy_socket',
-                   default='$state_path/metadata_proxy',
-                   help=_('Location for Metadata Proxy UNIX domain socket')),
-        cfg.IntOpt('metadata_workers',
-                   default=utils.cpu_count() // 2,
-                   help=_('Number of separate worker processes for metadata '
-                          'server')),
-        cfg.IntOpt('metadata_backlog',
-                   default=4096,
-                   help=_('Number of backlog requests to configure the '
-                          'metadata server socket with'))
-    ]
 
     def __init__(self, conf):
         self.conf = conf
@@ -422,16 +358,3 @@ class UnixDomainMetadataProxy(object):
                      workers=self.conf.metadata_workers,
                      backlog=self.conf.metadata_backlog)
         server.wait()
-
-
-def main():
-    cfg.CONF.register_opts(UnixDomainMetadataProxy.OPTS)
-    cfg.CONF.register_opts(MetadataProxyHandler.OPTS)
-    cache.register_oslo_configs(cfg.CONF)
-    cfg.CONF.set_default(name='cache_url', default='memory://?default_ttl=5')
-    agent_conf.register_agent_state_opts_helper(cfg.CONF)
-    config.init(sys.argv[1:])
-    config.setup_logging()
-    utils.log_opt_values(LOG)
-    proxy = UnixDomainMetadataProxy(cfg.CONF)
-    proxy.run()
diff --git a/neutron/agent/metadata/config.py b/neutron/agent/metadata/config.py
new file mode 100644 (file)
index 0000000..88b9bcc
--- /dev/null
@@ -0,0 +1,82 @@
+# Copyright 2015 OpenStack Foundation.
+#
+#    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.common import utils
+
+
+METADATA_PROXY_HANDLER_OPTS = [
+     cfg.StrOpt('admin_user',
+                help=_("Admin user")),
+     cfg.StrOpt('admin_password',
+                help=_("Admin password"),
+                secret=True),
+     cfg.StrOpt('admin_tenant_name',
+                help=_("Admin tenant name")),
+     cfg.StrOpt('auth_url',
+                help=_("Authentication URL")),
+     cfg.StrOpt('auth_strategy', default='keystone',
+                help=_("The type of authentication to use")),
+     cfg.StrOpt('auth_region',
+                help=_("Authentication region")),
+     cfg.BoolOpt('auth_insecure',
+                 default=False,
+                 help=_("Turn off verification of the certificate for"
+                        " ssl")),
+     cfg.StrOpt('auth_ca_cert',
+                help=_("Certificate Authority public key (CA cert) "
+                       "file for ssl")),
+     cfg.StrOpt('endpoint_type',
+                default='adminURL',
+                help=_("Network service endpoint type to pull from "
+                       "the keystone catalog")),
+     cfg.StrOpt('nova_metadata_ip', default='127.0.0.1',
+                help=_("IP address used by Nova metadata server.")),
+     cfg.IntOpt('nova_metadata_port',
+                default=8775,
+                help=_("TCP Port used by Nova metadata server.")),
+     cfg.StrOpt('metadata_proxy_shared_secret',
+                default='',
+                help=_('Shared secret to sign instance-id request'),
+                secret=True),
+     cfg.StrOpt('nova_metadata_protocol',
+                default='http',
+                choices=['http', 'https'],
+                help=_("Protocol to access nova metadata, http or https")),
+     cfg.BoolOpt('nova_metadata_insecure', default=False,
+                 help=_("Allow to perform insecure SSL (https) requests to "
+                        "nova metadata")),
+     cfg.StrOpt('nova_client_cert',
+                default='',
+                help=_("Client certificate for nova metadata api server.")),
+     cfg.StrOpt('nova_client_priv_key',
+                default='',
+                help=_("Private key of client certificate."))
+]
+
+
+UNIX_DOMAIN_METADATA_PROXY_OPTS = [
+    cfg.StrOpt('metadata_proxy_socket',
+               default='$state_path/metadata_proxy',
+               help=_('Location for Metadata Proxy UNIX domain socket')),
+    cfg.IntOpt('metadata_workers',
+               default=utils.cpu_count() // 2,
+               help=_('Number of separate worker processes for metadata '
+                      'server')),
+    cfg.IntOpt('metadata_backlog',
+               default=4096,
+               help=_('Number of backlog requests to configure the '
+                      'metadata server socket with'))
+]
diff --git a/neutron/agent/metadata_agent.py b/neutron/agent/metadata_agent.py
new file mode 100644 (file)
index 0000000..2d4ae63
--- /dev/null
@@ -0,0 +1,40 @@
+# Copyright 2015 OpenStack Foundation.
+#
+#    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 as agent_conf
+from neutron.agent.metadata import agent
+from neutron.agent.metadata import config as metadata_conf
+from neutron.common import config
+from neutron.common import utils
+from neutron.openstack.common.cache import cache
+from neutron.openstack.common import log as logging
+
+LOG = logging.getLogger(__name__)
+
+
+def main():
+    cfg.CONF.register_opts(metadata_conf.UNIX_DOMAIN_METADATA_PROXY_OPTS)
+    cfg.CONF.register_opts(metadata_conf.METADATA_PROXY_HANDLER_OPTS)
+    cache.register_oslo_configs(cfg.CONF)
+    cfg.CONF.set_default(name='cache_url', default='memory://?default_ttl=5')
+    agent_conf.register_agent_state_opts_helper(cfg.CONF)
+    config.init(sys.argv[1:])
+    config.setup_logging()
+    utils.log_opt_values(LOG)
+    proxy = agent.UnixDomainMetadataProxy(cfg.CONF)
+    proxy.run()
index 1d7f4beaaec50a31da5d968f4d1f937da17cd672..916988485bad2419baa85049992df4834d3a8090 100644 (file)
@@ -20,6 +20,7 @@ import testtools
 import webob
 
 from neutron.agent.metadata import agent
+from neutron.agent import metadata_agent
 from neutron.common import constants
 from neutron.common import utils
 from neutron.tests import base
@@ -634,10 +635,10 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
 
     def test_main(self):
         with mock.patch.object(agent, 'UnixDomainMetadataProxy') as proxy:
-            with mock.patch.object(agent, 'config') as config:
-                with mock.patch.object(agent, 'cfg') as cfg:
+            with mock.patch.object(metadata_agent, 'config') as config:
+                with mock.patch.object(metadata_agent, 'cfg') as cfg:
                     with mock.patch.object(utils, 'cfg'):
-                        agent.main()
+                        metadata_agent.main()
 
                         self.assertTrue(config.setup_logging.called)
                         proxy.assert_has_calls([
index f9d65f289e7f8d5141f72e2fd9b93218211bd5e5..ba6537a018dc46558afb124fdf0d1cf2cd0f0934 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -105,7 +105,7 @@ console_scripts =
     neutron-ibm-agent = neutron.plugins.ibm.agent.sdnve_neutron_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-metadata-agent = neutron.agent.metadata_agent:main
     neutron-mlnx-agent = neutron.plugins.mlnx.agent.eswitch_neutron_agent:main
     neutron-nec-agent = neutron.plugins.nec.agent.nec_neutron_agent:main
     neutron-netns-cleanup = neutron.agent.netns_cleanup_util:main