From 83f311865101c83999e98ba73fb644eea2b2761e Mon Sep 17 00:00:00 2001 From: Sergey Reshetnyak Date: Mon, 27 Jul 2015 14:28:37 +0300 Subject: [PATCH] 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 --- sahara/swift/utils.py | 2 +- sahara/tests/unit/utils/openstack/test_base.py | 4 ++-- sahara/tests/unit/utils/test_cinder.py | 4 ++-- sahara/tests/unit/utils/test_neutron.py | 4 ++-- sahara/utils/openstack/base.py | 7 ++++--- sahara/utils/openstack/cinder.py | 16 ++++++++++++---- sahara/utils/openstack/heat.py | 8 ++++++-- sahara/utils/openstack/keystone.py | 10 +++++++--- sahara/utils/openstack/neutron.py | 8 ++++++-- sahara/utils/openstack/nova.py | 8 ++++++-- sahara/utils/openstack/swift.py | 8 ++++++-- 11 files changed, 54 insertions(+), 25 deletions(-) diff --git a/sahara/swift/utils.py b/sahara/swift/utils.py index 4486a35b..c1850873 100644 --- a/sahara/swift/utils.py +++ b/sahara/swift/utils.py @@ -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: diff --git a/sahara/tests/unit/utils/openstack/test_base.py b/sahara/tests/unit/utils/openstack/test_base.py index cc67162c..34dac670 100644 --- a/sahara/tests/unit/utils/openstack/test_base.py +++ b/sahara/tests/unit/utils/openstack/test_base.py @@ -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")) diff --git a/sahara/tests/unit/utils/test_cinder.py b/sahara/tests/unit/utils/test_cinder.py index 53929fed..f410dd3e 100644 --- a/sahara/tests/unit/utils/test_cinder.py +++ b/sahara/tests/unit/utils/test_cinder.py @@ -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, diff --git a/sahara/tests/unit/utils/test_neutron.py b/sahara/tests/unit/utils/test_neutron.py index c9e1dd0d..4bd60970 100644 --- a/sahara/tests/unit/utils/test_neutron.py +++ b/sahara/tests/unit/utils/test_neutron.py @@ -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): diff --git a/sahara/utils/openstack/base.py b/sahara/utils/openstack/base.py index 76889fb6..3f928bff 100644 --- a/sahara/utils/openstack/base.py +++ b/sahara/utils/openstack/base.py @@ -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,)) diff --git a/sahara/utils/openstack/cinder.py b/sahara/utils/openstack/cinder.py index 2bfeffd4..9d8ba97e 100644 --- a/sahara/utils/openstack/cinder.py +++ b/sahara/utils/openstack/cinder.py @@ -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 diff --git a/sahara/utils/openstack/heat.py b/sahara/utils/openstack/heat.py index ef993d3e..eed05fe5 100644 --- a/sahara/utils/openstack/heat.py +++ b/sahara/utils/openstack/heat.py @@ -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, diff --git a/sahara/utils/openstack/keystone.py b/sahara/utils/openstack/keystone.py index 636b92d3..4b3a74d2 100644 --- a/sahara/utils/openstack/keystone.py +++ b/sahara/utils/openstack/keystone.py @@ -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 ) diff --git a/sahara/utils/openstack/neutron.py b/sahara/utils/openstack/neutron.py index 0bbfc318..b5d34ea6 100644 --- a/sahara/utils/openstack/neutron.py +++ b/sahara/utils/openstack/neutron.py @@ -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 diff --git a/sahara/utils/openstack/nova.py b/sahara/utils/openstack/nova.py index acc6308b..cdc33cfa 100644 --- a/sahara/utils/openstack/nova.py +++ b/sahara/utils/openstack/nova.py @@ -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 diff --git a/sahara/utils/openstack/swift.py b/sahara/utils/openstack/swift.py index 5d820bc0..4dc94363 100644 --- a/sahara/utils/openstack/swift.py +++ b/sahara/utils/openstack/swift.py @@ -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,