Merge "Allow overriding of the neutron endpoint URL in metadata agent"

This commit is contained in:
Jenkins 2015-07-29 14:16:00 +00:00 committed by Gerrit Code Review
commit 0b81bee62b
3 changed files with 66 additions and 14 deletions

View 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):

View 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',

View 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