Allow endpoint type to be specified.
Fixes bug 1037690. Change-Id: I36b3807b2f3234c778316f1e743d27304755aed8
This commit is contained in:
		| @@ -1025,6 +1025,7 @@ def parse_args(parser, args, enforce_requires=True): | |||||||
|         'tenant_id': options.os_tenant_id, |         'tenant_id': options.os_tenant_id, | ||||||
|         'tenant_name': options.os_tenant_name, |         'tenant_name': options.os_tenant_name, | ||||||
|         'service_type': options.os_service_type, |         'service_type': options.os_service_type, | ||||||
|  |         'endpoint_type': options.os_endpoint_type, | ||||||
|         'auth_token': options.os_auth_token, |         'auth_token': options.os_auth_token, | ||||||
|         'object_storage_url': options.os_storage_url, |         'object_storage_url': options.os_storage_url, | ||||||
|     } |     } | ||||||
| @@ -1133,6 +1134,11 @@ Example: | |||||||
|                            'Defaults to env[OS_SERVICE_TYPE]') |                            'Defaults to env[OS_SERVICE_TYPE]') | ||||||
|     parser.add_option('--os_service_type', |     parser.add_option('--os_service_type', | ||||||
|                       help=SUPPRESS_HELP) |                       help=SUPPRESS_HELP) | ||||||
|  |     parser.add_option('--os-endpoint-type', | ||||||
|  |                       metavar='<endpoint-type>', | ||||||
|  |                       default=environ.get('OS_ENDPOINT_TYPE'), | ||||||
|  |                       help='Openstack Endpoint type. (publicURL, e.g.)' \ | ||||||
|  |                            'Defaults to env[OS_ENDPOINT_TYPE]') | ||||||
|     parser.disable_interspersed_args() |     parser.disable_interspersed_args() | ||||||
|     (options, args) = parse_args(parser, argv[1:], enforce_requires=False) |     (options, args) = parse_args(parser, argv[1:], enforce_requires=False) | ||||||
|     parser.enable_interspersed_args() |     parser.enable_interspersed_args() | ||||||
|   | |||||||
| @@ -242,9 +242,10 @@ def get_keystoneclient_2_0(auth_url, user, key, os_options): | |||||||
|                                 tenant_id=os_options.get('tenant_id'), |                                 tenant_id=os_options.get('tenant_id'), | ||||||
|                                 auth_url=auth_url) |                                 auth_url=auth_url) | ||||||
|     service_type = os_options.get('service_type') or 'object-store' |     service_type = os_options.get('service_type') or 'object-store' | ||||||
|  |     endpoint_type = os_options.get('endpoint_type') or 'publicURL' | ||||||
|     endpoint = _ksclient.service_catalog.url_for( |     endpoint = _ksclient.service_catalog.url_for( | ||||||
|         service_type=service_type, |         service_type=service_type, | ||||||
|         endpoint_type='publicURL') |         endpoint_type=endpoint_type) | ||||||
|     return (endpoint, _ksclient.auth_token) |     return (endpoint, _ksclient.auth_token) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -922,8 +923,8 @@ class Connection(object): | |||||||
|         :param tenant_name: The tenant/account name, required when connecting |         :param tenant_name: The tenant/account name, required when connecting | ||||||
|                             to a auth 2.0 system. |                             to a auth 2.0 system. | ||||||
|         :param os_options: The OpenStack options which can have tenant_id, |         :param os_options: The OpenStack options which can have tenant_id, | ||||||
|                            auth_token, service_type, tenant_name, |                            auth_token, service_type, endpoint_type, | ||||||
|                            object_storage_url |                            tenant_name, object_storage_url | ||||||
|         """ |         """ | ||||||
|         self.authurl = authurl |         self.authurl = authurl | ||||||
|         self.user = user |         self.user = user | ||||||
|   | |||||||
| @@ -175,22 +175,24 @@ class TestGetAuth(MockHttpTest): | |||||||
|         self.assertEquals(token, None) |         self.assertEquals(token, None) | ||||||
|  |  | ||||||
|     def test_auth_v2(self): |     def test_auth_v2(self): | ||||||
|         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0 |         os_options={'tenant_name': 'asdf'} | ||||||
|  |         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) | ||||||
|         url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', |         url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', | ||||||
|                                 os_options={'tenant_name': 'asdf'}, |                                 os_options=os_options, | ||||||
|                                 auth_version="2.0") |                                 auth_version="2.0") | ||||||
|         self.assertTrue(url.startswith("http")) |         self.assertTrue(url.startswith("http")) | ||||||
|         self.assertTrue(token) |         self.assertTrue(token) | ||||||
|  |  | ||||||
|     def test_auth_v2_no_tenant_name(self): |     def test_auth_v2_no_tenant_name(self): | ||||||
|         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0 |         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0({}) | ||||||
|         self.assertRaises(c.ClientException, c.get_auth, |         self.assertRaises(c.ClientException, c.get_auth, | ||||||
|                           'http://www.tests.com', 'asdf', 'asdf', |                           'http://www.tests.com', 'asdf', 'asdf', | ||||||
|                           os_options={}, |                           os_options={}, | ||||||
|                           auth_version='2.0') |                           auth_version='2.0') | ||||||
|  |  | ||||||
|     def test_auth_v2_with_tenant_user_in_user(self): |     def test_auth_v2_with_tenant_user_in_user(self): | ||||||
|         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0 |         tenant_option = {'tenant_name': 'foo'} | ||||||
|  |         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option) | ||||||
|         url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf', |         url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf', | ||||||
|                                 os_options={}, |                                 os_options={}, | ||||||
|                                 auth_version="2.0") |                                 auth_version="2.0") | ||||||
| @@ -198,7 +200,8 @@ class TestGetAuth(MockHttpTest): | |||||||
|         self.assertTrue(token) |         self.assertTrue(token) | ||||||
|  |  | ||||||
|     def test_auth_v2_tenant_name_no_os_options(self): |     def test_auth_v2_tenant_name_no_os_options(self): | ||||||
|         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0 |         tenant_option = {'tenant_name': 'asdf'} | ||||||
|  |         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option) | ||||||
|         url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', |         url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', | ||||||
|                                 tenant_name='asdf', |                                 tenant_name='asdf', | ||||||
|                                 os_options={}, |                                 os_options={}, | ||||||
| @@ -206,6 +209,17 @@ class TestGetAuth(MockHttpTest): | |||||||
|         self.assertTrue(url.startswith("http")) |         self.assertTrue(url.startswith("http")) | ||||||
|         self.assertTrue(token) |         self.assertTrue(token) | ||||||
|  |  | ||||||
|  |     def test_auth_v2_with_os_options(self): | ||||||
|  |         os_options={'service_type': 'object-store', | ||||||
|  |                     'endpoint_type': 'internalURL', | ||||||
|  |                     'tenant_name': 'asdf'} | ||||||
|  |         c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) | ||||||
|  |         url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', | ||||||
|  |                                 os_options=os_options, | ||||||
|  |                                 auth_version="2.0") | ||||||
|  |         self.assertTrue(url.startswith("http")) | ||||||
|  |         self.assertTrue(token) | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestGetAccount(MockHttpTest): | class TestGetAccount(MockHttpTest): | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,13 +16,15 @@ from httplib import HTTPException | |||||||
|  |  | ||||||
| from eventlet import Timeout, sleep | from eventlet import Timeout, sleep | ||||||
|  |  | ||||||
|  | def fake_get_keystoneclient_2_0(os_options): | ||||||
| def fake_get_keystoneclient_2_0(auth_url, |     def fake_get_keystoneclient_2_0(auth_url, | ||||||
|                                 username, |                                     user, | ||||||
|                                 tenant_name, |                                     key, | ||||||
|                                 password, |                                     actual_os_options): | ||||||
|                                 service_type='object-store'): |         if actual_os_options != os_options: | ||||||
|     return ("http://url/", "token") |             return "", None | ||||||
|  |         return ("http://url/", "token") | ||||||
|  |     return fake_get_keystoneclient_2_0 | ||||||
|  |  | ||||||
|  |  | ||||||
| def fake_http_connect(*code_iter, **kwargs): | def fake_http_connect(*code_iter, **kwargs): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 David Kranz
					David Kranz