Use internalURL endpoint by default in Sahara
Changes: * use internalURL endpoint for connect to OS clients * getting neutron url in neutron module instead ssh_remote module Closes-bug: #1478059 Change-Id: I560c9aebe67ba2e69ae521052483801fd12b17fc
This commit is contained in:
parent
5b4028c9ac
commit
83f3118651
@ -33,7 +33,7 @@ def retrieve_auth_url():
|
||||
|
||||
Hadoop Swift library doesn't support keystone v3 api.
|
||||
"""
|
||||
auth_url = clients_base.retrieve_auth_url()
|
||||
auth_url = clients_base.retrieve_auth_url(endpoint_type="publicURL")
|
||||
info = urlparse.urlparse(auth_url)
|
||||
|
||||
if CONF.use_domain_for_proxy_users:
|
||||
|
@ -46,11 +46,11 @@ class TestBase(testbase.SaharaTestCase):
|
||||
' "name": "nova"}]')
|
||||
|
||||
self.override_config("os_region_name", "RegionOne")
|
||||
self.assertEqual("http://172.18.184.5:8774/v2",
|
||||
self.assertEqual("http://192.168.0.5:8774/v2",
|
||||
base.url_for(service_catalog, "compute"))
|
||||
|
||||
self.override_config("os_region_name", "RegionTwo")
|
||||
self.assertEqual("http://172.18.184.6:8774/v2",
|
||||
self.assertEqual("http://192.168.0.6:8774/v2",
|
||||
base.url_for(service_catalog, "compute"))
|
||||
|
||||
|
||||
|
@ -36,10 +36,10 @@ class TestCinder(test_base.SaharaTestCase):
|
||||
service_catalog = '''[
|
||||
{ "type": "volume",
|
||||
"endpoints": [ { "region": "RegionOne",
|
||||
"publicURL": "http://localhost/" } ] },
|
||||
"internalURL": "http://localhost/" } ] },
|
||||
{ "type": "volumev2",
|
||||
"endpoints": [ { "region": "RegionOne",
|
||||
"publicURL": "http://localhost/" } ] } ]'''
|
||||
"internalURL": "http://localhost/" } ] } ]'''
|
||||
|
||||
super(TestCinder, self).setup_context(
|
||||
username=username, tenant_id=tenant_id, token=token,
|
||||
|
@ -14,12 +14,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from sahara.tests.unit import base
|
||||
from sahara.utils.openstack import neutron as neutron_client
|
||||
|
||||
|
||||
class NeutronClientTest(testtools.TestCase):
|
||||
class NeutronClientTest(base.SaharaTestCase):
|
||||
@mock.patch("sahara.utils.openstack.keystone.token_auth")
|
||||
@mock.patch("neutronclient.neutron.client.Client")
|
||||
def test_get_router(self, patched, token_auth):
|
||||
|
@ -48,7 +48,7 @@ CONF.register_opts(opts, group=retries)
|
||||
|
||||
|
||||
def url_for(service_catalog=None, service_type='identity',
|
||||
endpoint_type='publicURL'):
|
||||
endpoint_type="internalURL"):
|
||||
if not service_catalog:
|
||||
service_catalog = context.current().service_catalog
|
||||
try:
|
||||
@ -65,11 +65,12 @@ def url_for(service_catalog=None, service_type='identity',
|
||||
region_name=CONF.os_region_name)
|
||||
|
||||
|
||||
def retrieve_auth_url():
|
||||
def retrieve_auth_url(endpoint_type="internalURL"):
|
||||
version = 'v3' if CONF.use_identity_api_v3 else 'v2.0'
|
||||
ctx = context.current()
|
||||
if ctx.service_catalog:
|
||||
info = urlparse.urlparse(url_for(ctx.service_catalog, 'identity'))
|
||||
info = urlparse.urlparse(url_for(ctx.service_catalog, 'identity',
|
||||
endpoint_type))
|
||||
else:
|
||||
info = urlparse.urlparse(CONF.keystone_authtoken.auth_uri)
|
||||
return "%s://%s/%s" % (info[:2] + (version,))
|
||||
|
@ -40,7 +40,10 @@ opts = [
|
||||
help='Allow to perform insecure SSL requests to cinder.'),
|
||||
cfg.StrOpt('ca_file',
|
||||
help='Location of ca certificates file to use for cinder '
|
||||
'client requests.')
|
||||
'client requests.'),
|
||||
cfg.StrOpt("endpoint_type",
|
||||
default="internalURL",
|
||||
help="Endpoint type for cinder client requests")
|
||||
]
|
||||
|
||||
cinder_group = cfg.OptGroup(name='cinder',
|
||||
@ -71,9 +74,13 @@ def client():
|
||||
auth = keystone.auth()
|
||||
|
||||
if CONF.cinder.api_version == 1:
|
||||
cinder = cinder_client_v1.Client(session=session, auth=auth)
|
||||
cinder = cinder_client_v1.Client(
|
||||
session=session, auth=auth,
|
||||
endpoint_type=CONF.cinder.endpoint_type)
|
||||
else:
|
||||
cinder = cinder_client_v2.Client(session=session, auth=auth)
|
||||
cinder = cinder_client_v2.Client(
|
||||
session=session, auth=auth,
|
||||
endpoint_type=CONF.cinder.endpoint_type)
|
||||
return cinder
|
||||
|
||||
|
||||
@ -83,7 +90,8 @@ def check_cinder_exists():
|
||||
else:
|
||||
service_type = 'volumev2'
|
||||
try:
|
||||
base.url_for(context.current().service_catalog, service_type)
|
||||
base.url_for(context.current().service_catalog, service_type,
|
||||
endpoint_type=CONF.cinder.endpoint_type)
|
||||
return True
|
||||
except ex.SystemError:
|
||||
return False
|
||||
|
@ -28,7 +28,10 @@ opts = [
|
||||
help='Allow to perform insecure SSL requests to heat.'),
|
||||
cfg.StrOpt('ca_file',
|
||||
help='Location of ca certificates file to use for heat '
|
||||
'client requests.')
|
||||
'client requests.'),
|
||||
cfg.StrOpt("endpoint_type",
|
||||
default="internalURL",
|
||||
help="Endpoint type for heat client requests")
|
||||
]
|
||||
|
||||
heat_group = cfg.OptGroup(name='heat',
|
||||
@ -41,7 +44,8 @@ CONF.register_opts(opts, group=heat_group)
|
||||
|
||||
def client():
|
||||
ctx = context.current()
|
||||
heat_url = base.url_for(ctx.service_catalog, 'orchestration')
|
||||
heat_url = base.url_for(ctx.service_catalog, 'orchestration',
|
||||
endpoint_type=CONF.heat.endpoint_type)
|
||||
return heat_client.Client('1', heat_url, token=ctx.auth_token,
|
||||
cert_file=CONF.heat.ca_file,
|
||||
insecure=CONF.heat.api_insecure,
|
||||
|
@ -62,7 +62,10 @@ ssl_opts = [
|
||||
help='Allow to perform insecure SSL requests to keystone.'),
|
||||
cfg.StrOpt('ca_file',
|
||||
help='Location of ca certificates file to use for keystone '
|
||||
'client requests.')
|
||||
'client requests.'),
|
||||
cfg.StrOpt("endpoint_type",
|
||||
default="internalURL",
|
||||
help="Endpoint type for keystone client requests")
|
||||
]
|
||||
|
||||
keystone_group = cfg.OptGroup(name='keystone',
|
||||
@ -248,7 +251,8 @@ def _client(username, password=None, token=None, tenant_name=None,
|
||||
raise Exception("Trusts aren't implemented in keystone api"
|
||||
" less than v3")
|
||||
|
||||
auth_url = base.retrieve_auth_url()
|
||||
auth_url = base.retrieve_auth_url(
|
||||
endpoint_type=CONF.keystone.endpoint_type)
|
||||
|
||||
client_kwargs = {'username': username,
|
||||
'password': password,
|
||||
@ -290,7 +294,7 @@ def _password_auth(username, password, project_name, user_domain_name=None,
|
||||
:returns: a password auth plugin object.
|
||||
'''
|
||||
passwd_kwargs = dict(
|
||||
auth_url=base.retrieve_auth_url(),
|
||||
auth_url=base.retrieve_auth_url(CONF.keystone.endpoint_type),
|
||||
username=username,
|
||||
password=password
|
||||
)
|
||||
|
@ -31,7 +31,10 @@ opts = [
|
||||
help='Allow to perform insecure SSL requests to neutron.'),
|
||||
cfg.StrOpt('ca_file',
|
||||
help='Location of ca certificates file to use for neutron '
|
||||
'client requests.')
|
||||
'client requests.'),
|
||||
cfg.StrOpt("endpoint_type",
|
||||
default="internalURL",
|
||||
help="Endpoint type for neutron client requests")
|
||||
]
|
||||
|
||||
neutron_group = cfg.OptGroup(name='neutron',
|
||||
@ -46,7 +49,8 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
def client():
|
||||
session = sessions.cache().get_session(sessions.SESSION_TYPE_NEUTRON)
|
||||
neutron = neutron_cli.Client('2.0', session=session, auth=keystone.auth())
|
||||
neutron = neutron_cli.Client('2.0', session=session, auth=keystone.auth(),
|
||||
endpoint_type=CONF.neutron.endpoint_type)
|
||||
return neutron
|
||||
|
||||
|
||||
|
@ -29,7 +29,10 @@ opts = [
|
||||
help='Allow to perform insecure SSL requests to nova.'),
|
||||
cfg.StrOpt('ca_file',
|
||||
help='Location of ca certificates file to use for nova '
|
||||
'client requests.')
|
||||
'client requests.'),
|
||||
cfg.StrOpt("endpoint_type",
|
||||
default="internalURL",
|
||||
help="Endpoint type for nova client requests")
|
||||
]
|
||||
|
||||
nova_group = cfg.OptGroup(name='nova',
|
||||
@ -42,7 +45,8 @@ CONF.register_opts(opts, group=nova_group)
|
||||
|
||||
def client():
|
||||
session = sessions.cache().get_session(sessions.SESSION_TYPE_NOVA)
|
||||
nova = nova_client.Client(session=session, auth=keystone.auth())
|
||||
nova = nova_client.Client(session=session, auth=keystone.auth(),
|
||||
endpoint_type=CONF.nova.endpoint_type)
|
||||
nova.images = images.SaharaImageManager(nova)
|
||||
return nova
|
||||
|
||||
|
@ -27,7 +27,10 @@ opts = [
|
||||
help='Allow to perform insecure SSL requests to swift.'),
|
||||
cfg.StrOpt('ca_file',
|
||||
help='Location of ca certificates file to use for swift '
|
||||
'client requests.')
|
||||
'client requests.'),
|
||||
cfg.StrOpt("endpoint_type",
|
||||
default="internalURL",
|
||||
help="Endpoint type for swift client requests")
|
||||
]
|
||||
|
||||
swift_group = cfg.OptGroup(name='swift',
|
||||
@ -78,7 +81,8 @@ def client_from_token(token):
|
||||
cacert=CONF.swift.ca_file,
|
||||
insecure=CONF.swift.api_insecure,
|
||||
preauthurl=base.url_for(
|
||||
service_type="object-store"),
|
||||
service_type="object-store",
|
||||
endpoint_type=CONF.swift.endpoint_type),
|
||||
preauthtoken=token,
|
||||
retries=CONF.retries.retries_number,
|
||||
retry_on_ratelimit=True,
|
||||
|
Loading…
Reference in New Issue
Block a user