]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow overriding of the neutron endpoint URL in metadata agent
authorSam Morrison <sorrison@gmail.com>
Thu, 18 Jun 2015 01:13:33 +0000 (11:13 +1000)
committerCarl Baldwin <carl.baldwin@hp.com>
Fri, 17 Jul 2015 01:28:51 +0000 (01:28 +0000)
Allow operators to set the endpoint url for neutron in the config
overriding the url that comes from the keystone catalog.

Change-Id: I93f81ef1be2de1038d9a899b0c4becdb5a8e8775
DocImpact
Closes-Bug: #1466258

neutron/agent/metadata/agent.py
neutron/agent/metadata/config.py
neutron/tests/unit/agent/metadata/test_agent.py

index 769d8039bc043229eb2b730fb79a222f4071af08..b4dd33de27d15442852aefe474991a06a5f7bed2 100644 (file)
@@ -87,20 +87,24 @@ class MetadataProxyHandler(object):
         self.use_rpc = True
 
     def _get_neutron_client(self):
-        qclient = client.Client(
-            username=self.conf.admin_user,
-            password=self.conf.admin_password,
-            tenant_name=self.conf.admin_tenant_name,
-            auth_url=self.conf.auth_url,
-            auth_strategy=self.conf.auth_strategy,
-            region_name=self.conf.auth_region,
-            token=self.auth_info.get('auth_token'),
-            insecure=self.conf.auth_insecure,
-            ca_cert=self.conf.auth_ca_cert,
-            endpoint_url=self.auth_info.get('endpoint_url'),
-            endpoint_type=self.conf.endpoint_type
-        )
-        return qclient
+        params = {
+            'username': self.conf.admin_user,
+            'password': self.conf.admin_password,
+            'tenant_name': self.conf.admin_tenant_name,
+            'auth_url': self.conf.auth_url,
+            'auth_strategy': self.conf.auth_strategy,
+            'region_name': self.conf.auth_region,
+            'token': self.auth_info.get('auth_token'),
+            'insecure': self.conf.auth_insecure,
+            'ca_cert': self.conf.auth_ca_cert,
+        }
+        if self.conf.endpoint_url:
+            params['endpoint_url'] = self.conf.endpoint_url
+        else:
+            params['endpoint_url'] = self.auth_info.get('endpoint_url')
+            params['endpoint_type'] = self.conf.endpoint_type
+
+        return client.Client(**params)
 
     @webob.dec.wsgify(RequestClass=webob.Request)
     def __call__(self, req):
index 2a5706e8e4f137e58b24137aac266e95d1f12898..e325903725ed8556bfe3f022c4c645edeb17e599 100644 (file)
@@ -74,6 +74,10 @@ METADATA_PROXY_HANDLER_OPTS = [
                 default='adminURL',
                 help=_("Network service endpoint type to pull from "
                        "the keystone catalog")),
+     cfg.StrOpt('endpoint_url',
+                default=None,
+                help=_("Neutron endpoint URL, if not set will use endpoint "
+                       "from the keystone catalog along with endpoint_type")),
      cfg.StrOpt('nova_metadata_ip', default='127.0.0.1',
                 help=_("IP address used by Nova metadata server.")),
      cfg.IntOpt('nova_metadata_port',
index eaa5a773fe843ea2af1f26c05d3e705ff5ec1d7c..874b801737b695adee4f55c676a151b0dcb58816 100644 (file)
@@ -23,6 +23,7 @@ from neutron.agent import metadata_agent
 from neutron.common import constants
 from neutron.common import utils
 from neutron.tests import base
+from neutronclient.v2_0 import client
 
 
 class FakeConf(object):
@@ -43,12 +44,55 @@ class FakeConf(object):
     nova_client_cert = 'nova_cert'
     nova_client_priv_key = 'nova_priv_key'
     cache_url = ''
+    endpoint_url = None
 
 
 class FakeConfCache(FakeConf):
     cache_url = 'memory://?default_ttl=5'
 
 
+class FakeConfEndpoint(FakeConf):
+    endpoint_url = 'http://127.0.0.0:8776'
+
+
+class TestNeutronClient(base.BaseTestCase):
+    fake_conf = FakeConf
+    expected_params = {
+        'username': 'neutron',
+        'region_name': 'region',
+        'ca_cert': None,
+        'tenant_name': 'tenant',
+        'insecure': False,
+        'token': None,
+        'endpoint_type': 'adminURL',
+        'auth_url': 'http://127.0.0.1',
+        'password': 'password',
+        'endpoint_url': None,
+        'auth_strategy': 'keystone',
+    }
+
+    def test_client_params(self):
+        handler = agent.MetadataProxyHandler(self.fake_conf)
+
+        with mock.patch.object(
+            client.Client, "__init__", return_value=None) as mock_init:
+            handler._get_neutron_client()
+            mock_init.assert_called_once_with(**self.expected_params)
+
+    def test_client_with_endpoint_url(self):
+        fake_conf = FakeConfEndpoint
+        handler = agent.MetadataProxyHandler(fake_conf)
+
+        expected_params = self.expected_params.copy()
+        del expected_params['endpoint_type']
+        expected_params['endpoint_url'] = 'http://127.0.0.0:8776'
+
+        with mock.patch.object(
+            client.Client, "__init__", return_value=None) as mock_init:
+            handler._get_neutron_client()
+            mock_init.assert_called_once_with(**expected_params)
+
+
 class TestMetadataProxyHandlerBase(base.BaseTestCase):
     fake_conf = FakeConf