Remove _get_endpoint_type() from RestClient

_get_endpoint_type() was used for getting endpoint_type from CONF for
each project, but most projects' sections contain a endpoint_type value
and it is easy to specify its value instead of _get_endpoint_type().
In addition, RestClient will become a tempest-lib class and it is needed
to separate CONF values from a RestClient class.
This patch removes _get_endpoint_type() and makes each client specify
its own CONF value.

Change-Id: I5609c56507bb5ad0ce249b020a8bea1fe11bee3e
This commit is contained in:
Ken'ichi Ohmichi 2015-01-02 07:03:51 +00:00
parent 0cd316bd60
commit 0690ea4d7f
13 changed files with 34 additions and 37 deletions

View File

@ -78,14 +78,14 @@ class RestClient(object):
LOG = logging.getLogger(__name__)
def __init__(self, auth_provider, service,
def __init__(self, auth_provider, service, endpoint_type='publicURL',
build_interval=1, build_timeout=60):
self.auth_provider = auth_provider
self.service = service
self.endpoint_type = endpoint_type
self.build_interval = build_interval
self.build_timeout = build_timeout
self.endpoint_url = None
# The version of the API this client implements
self.api_version = None
self._skip_path = False
@ -139,23 +139,6 @@ class RestClient(object):
service_region = CONF.identity.region
return service_region
def _get_endpoint_type(self, service):
"""
Returns the endpoint type for a specific service
"""
# If the client requests a specific endpoint type, then be it
if self.endpoint_url:
return self.endpoint_url
endpoint_type = None
for cfgname in dir(CONF._config):
# Find all config.FOO.catalog_type and assume FOO is a service.
cfg = getattr(CONF, cfgname)
catalog_type = getattr(cfg, 'catalog_type', None)
if catalog_type == service:
endpoint_type = getattr(cfg, 'endpoint_type', 'publicURL')
break
return endpoint_type
@property
def user(self):
return self.auth_provider.credentials.username
@ -188,7 +171,7 @@ class RestClient(object):
def filters(self):
_filters = dict(
service=self.service,
endpoint_type=self._get_endpoint_type(self.service),
endpoint_type=self.endpoint_type,
region=self._get_region(self.service)
)
if self.api_version is not None:

View File

@ -50,7 +50,8 @@ class BaremetalClient(rest_client.RestClient):
def __init__(self, auth_provider):
super(BaremetalClient, self).__init__(
auth_provider, CONF.baremetal.catalog_type)
auth_provider, CONF.baremetal.catalog_type,
endpoint_type=CONF.baremetal.endpoint_type)
self.uri_prefix = ''
def serialize(self, object_type, object_dict):

View File

@ -30,7 +30,9 @@ class ComputeClient(rest_client.RestClient):
if build_timeout is None:
build_timeout = CONF.compute.build_timeout
super(ComputeClient, self).__init__(auth_provider,
CONF.compute.catalog_type,
build_interval=build_interval,
build_timeout=build_timeout)
super(ComputeClient, self).__init__(
auth_provider,
CONF.compute.catalog_type,
endpoint_type=CONF.compute.endpoint_type,
build_interval=build_interval,
build_timeout=build_timeout)

View File

@ -24,7 +24,8 @@ class DataProcessingClient(rest_client.RestClient):
def __init__(self, auth_provider):
super(DataProcessingClient, self).__init__(
auth_provider, CONF.data_processing.catalog_type)
auth_provider, CONF.data_processing.catalog_type,
endpoint_type=CONF.data_processing.endpoint_type)
def _request_and_check_resp(self, request_func, uri, resp_status):
"""Make a request using specified request_func and check response

View File

@ -23,8 +23,8 @@ class IdentityClientJSON(rest_client.RestClient):
def __init__(self, auth_provider):
super(IdentityClientJSON, self).__init__(auth_provider,
CONF.identity.catalog_type)
self.endpoint_url = 'adminURL'
CONF.identity.catalog_type,
endpoint_type='adminURL')
def has_admin_extensions(self):
"""

View File

@ -25,6 +25,6 @@ class IdentityV3Client(rest_client.RestClient):
def __init__(self, auth_provider):
super(IdentityV3Client, self).__init__(auth_provider,
CONF.identity.catalog_type)
self.endpoint_url = 'adminURL'
CONF.identity.catalog_type,
endpoint_type='adminURL')
self.api_version = "v3"

View File

@ -35,8 +35,10 @@ LOG = logging.getLogger(__name__)
class ImageClientJSON(rest_client.RestClient):
def __init__(self, auth_provider):
super(ImageClientJSON, self).__init__(auth_provider,
CONF.image.catalog_type)
super(ImageClientJSON, self).__init__(
auth_provider,
CONF.image.catalog_type,
endpoint_type=CONF.image.endpoint_type)
self._http = None
def _image_meta_from_headers(self, headers):

View File

@ -29,8 +29,10 @@ CONF = config.CONF
class ImageClientV2JSON(rest_client.RestClient):
def __init__(self, auth_provider):
super(ImageClientV2JSON, self).__init__(auth_provider,
CONF.image.catalog_type)
super(ImageClientV2JSON, self).__init__(
auth_provider,
CONF.image.catalog_type,
endpoint_type=CONF.image.endpoint_type)
self._http = None
def _get_http(self):

View File

@ -40,6 +40,7 @@ class NetworkClientJSON(rest_client.RestClient):
def __init__(self, auth_provider):
super(NetworkClientJSON, self).__init__(
auth_provider, CONF.network.catalog_type,
endpoint_type=CONF.network.endpoint_type,
build_interval=CONF.network.build_interval,
build_timeout=CONF.network.build_timeout)
self.version = '2.0'

View File

@ -25,5 +25,6 @@ class ObjectStorageClient(rest_client.RestClient):
def __init__(self, auth_provider):
super(ObjectStorageClient, self).__init__(
auth_provider, CONF.object_storage.catalog_type)
auth_provider, CONF.object_storage.catalog_type,
endpoint_type=CONF.object_storage.endpoint_type)
self.format = 'json'

View File

@ -31,6 +31,7 @@ class OrchestrationClient(rest_client.RestClient):
super(OrchestrationClient, self).__init__(
auth_provider,
CONF.orchestration.catalog_type,
endpoint_type=CONF.orchestration.endpoint_type,
build_interval=CONF.orchestration.build_interval,
build_timeout=CONF.orchestration.build_timeout)

View File

@ -25,8 +25,10 @@ CONF = config.CONF
class TelemetryClientJSON(rest_client.RestClient):
def __init__(self, auth_provider):
super(TelemetryClientJSON, self).__init__(auth_provider,
CONF.telemetry.catalog_type)
super(TelemetryClientJSON, self).__init__(
auth_provider,
CONF.telemetry.catalog_type,
endpoint_type=CONF.telemetry.endpoint_type)
self.version = '2'
self.uri_prefix = "v%s" % self.version

View File

@ -27,5 +27,6 @@ class VolumeClient(rest_client.RestClient):
super(VolumeClient, self).__init__(
auth_provider,
CONF.volume.catalog_type,
endpoint_type=CONF.volume.endpoint_type,
build_interval=CONF.volume.build_interval,
build_timeout=CONF.volume.build_timeout)