Move _get_region() to NegativeRestClient
_get_region() was used for getting a region from CONF for each project, but most projects' sections contain a region value and it is easy to specify its value instead of _get_region(). In addition, RestClient will become a tempest-lib class and it is needed to separate CONF values from a RestClient class. This patch moves _get_region() to NegativeRestClient and makes each client specify its own CONF value. Change-Id: Ib26badf64e7cddf4158e4720e193b3129e8fdb12
This commit is contained in:
parent
179ea57f7a
commit
e9f50413ad
|
@ -78,10 +78,12 @@ class RestClient(object):
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
def __init__(self, auth_provider, service, endpoint_type='publicURL',
|
def __init__(self, auth_provider, service, region,
|
||||||
|
endpoint_type='publicURL',
|
||||||
build_interval=1, build_timeout=60):
|
build_interval=1, build_timeout=60):
|
||||||
self.auth_provider = auth_provider
|
self.auth_provider = auth_provider
|
||||||
self.service = service
|
self.service = service
|
||||||
|
self.region = region
|
||||||
self.endpoint_type = endpoint_type
|
self.endpoint_type = endpoint_type
|
||||||
self.build_interval = build_interval
|
self.build_interval = build_interval
|
||||||
self.build_timeout = build_timeout
|
self.build_timeout = build_timeout
|
||||||
|
@ -124,21 +126,6 @@ class RestClient(object):
|
||||||
str(self.token)[0:STRING_LIMIT],
|
str(self.token)[0:STRING_LIMIT],
|
||||||
str(self.get_headers())[0:STRING_LIMIT])
|
str(self.get_headers())[0:STRING_LIMIT])
|
||||||
|
|
||||||
def _get_region(self, service):
|
|
||||||
"""
|
|
||||||
Returns the region for a specific service
|
|
||||||
"""
|
|
||||||
service_region = 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:
|
|
||||||
service_region = getattr(cfg, 'region', None)
|
|
||||||
if not service_region:
|
|
||||||
service_region = CONF.identity.region
|
|
||||||
return service_region
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user(self):
|
def user(self):
|
||||||
return self.auth_provider.credentials.username
|
return self.auth_provider.credentials.username
|
||||||
|
@ -172,7 +159,7 @@ class RestClient(object):
|
||||||
_filters = dict(
|
_filters = dict(
|
||||||
service=self.service,
|
service=self.service,
|
||||||
endpoint_type=self.endpoint_type,
|
endpoint_type=self.endpoint_type,
|
||||||
region=self._get_region(self.service)
|
region=self.region
|
||||||
)
|
)
|
||||||
if self.api_version is not None:
|
if self.api_version is not None:
|
||||||
_filters['api_version'] = self.api_version
|
_filters['api_version'] = self.api_version
|
||||||
|
@ -609,6 +596,27 @@ class NegativeRestClient(RestClient):
|
||||||
"""
|
"""
|
||||||
Version of RestClient that does not raise exceptions.
|
Version of RestClient that does not raise exceptions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __init__(self, auth_provider, service):
|
||||||
|
region = self._get_region(service)
|
||||||
|
super(NegativeRestClient, self).__init__(auth_provider,
|
||||||
|
service, region)
|
||||||
|
|
||||||
|
def _get_region(self, service):
|
||||||
|
"""
|
||||||
|
Returns the region for a specific service
|
||||||
|
"""
|
||||||
|
service_region = 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:
|
||||||
|
service_region = getattr(cfg, 'region', None)
|
||||||
|
if not service_region:
|
||||||
|
service_region = CONF.identity.region
|
||||||
|
return service_region
|
||||||
|
|
||||||
def _error_checker(self, method, url,
|
def _error_checker(self, method, url,
|
||||||
headers, body, resp, resp_body):
|
headers, body, resp, resp_body):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -50,7 +50,9 @@ class BaremetalClient(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(BaremetalClient, self).__init__(
|
super(BaremetalClient, self).__init__(
|
||||||
auth_provider, CONF.baremetal.catalog_type,
|
auth_provider,
|
||||||
|
CONF.baremetal.catalog_type,
|
||||||
|
CONF.identity.region,
|
||||||
endpoint_type=CONF.baremetal.endpoint_type)
|
endpoint_type=CONF.baremetal.endpoint_type)
|
||||||
self.uri_prefix = ''
|
self.uri_prefix = ''
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ class ComputeClient(rest_client.RestClient):
|
||||||
super(ComputeClient, self).__init__(
|
super(ComputeClient, self).__init__(
|
||||||
auth_provider,
|
auth_provider,
|
||||||
CONF.compute.catalog_type,
|
CONF.compute.catalog_type,
|
||||||
|
CONF.compute.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.compute.endpoint_type,
|
endpoint_type=CONF.compute.endpoint_type,
|
||||||
build_interval=build_interval,
|
build_interval=build_interval,
|
||||||
build_timeout=build_timeout)
|
build_timeout=build_timeout)
|
||||||
|
|
|
@ -24,7 +24,9 @@ class DataProcessingClient(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(DataProcessingClient, self).__init__(
|
super(DataProcessingClient, self).__init__(
|
||||||
auth_provider, CONF.data_processing.catalog_type,
|
auth_provider,
|
||||||
|
CONF.data_processing.catalog_type,
|
||||||
|
CONF.identity.region,
|
||||||
endpoint_type=CONF.data_processing.endpoint_type)
|
endpoint_type=CONF.data_processing.endpoint_type)
|
||||||
|
|
||||||
def _request_and_check_resp(self, request_func, uri, resp_status):
|
def _request_and_check_resp(self, request_func, uri, resp_status):
|
||||||
|
|
|
@ -25,7 +25,9 @@ class DatabaseFlavorsClientJSON(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(DatabaseFlavorsClientJSON, self).__init__(
|
super(DatabaseFlavorsClientJSON, self).__init__(
|
||||||
auth_provider, CONF.database.catalog_type)
|
auth_provider,
|
||||||
|
CONF.database.catalog_type,
|
||||||
|
CONF.identity.region)
|
||||||
|
|
||||||
def list_db_flavors(self, params=None):
|
def list_db_flavors(self, params=None):
|
||||||
url = 'flavors'
|
url = 'flavors'
|
||||||
|
|
|
@ -25,7 +25,9 @@ class DatabaseVersionsClientJSON(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(DatabaseVersionsClientJSON, self).__init__(
|
super(DatabaseVersionsClientJSON, self).__init__(
|
||||||
auth_provider, CONF.database.catalog_type)
|
auth_provider,
|
||||||
|
CONF.database.catalog_type,
|
||||||
|
CONF.identity.region)
|
||||||
self.skip_path()
|
self.skip_path()
|
||||||
|
|
||||||
def list_db_versions(self, params=None):
|
def list_db_versions(self, params=None):
|
||||||
|
|
|
@ -22,9 +22,11 @@ CONF = config.CONF
|
||||||
class IdentityClientJSON(rest_client.RestClient):
|
class IdentityClientJSON(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(IdentityClientJSON, self).__init__(auth_provider,
|
super(IdentityClientJSON, self).__init__(
|
||||||
CONF.identity.catalog_type,
|
auth_provider,
|
||||||
endpoint_type='adminURL')
|
CONF.identity.catalog_type,
|
||||||
|
CONF.identity.region,
|
||||||
|
endpoint_type='adminURL')
|
||||||
|
|
||||||
def has_admin_extensions(self):
|
def has_admin_extensions(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -24,7 +24,9 @@ class IdentityV3Client(rest_client.RestClient):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(IdentityV3Client, self).__init__(auth_provider,
|
super(IdentityV3Client, self).__init__(
|
||||||
CONF.identity.catalog_type,
|
auth_provider,
|
||||||
endpoint_type='adminURL')
|
CONF.identity.catalog_type,
|
||||||
|
CONF.identity.region,
|
||||||
|
endpoint_type='adminURL')
|
||||||
self.api_version = "v3"
|
self.api_version = "v3"
|
||||||
|
|
|
@ -523,7 +523,7 @@ class IdentityV3ClientJSON(base.IdentityV3Client):
|
||||||
class V3TokenClientJSON(rest_client.RestClient):
|
class V3TokenClientJSON(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(V3TokenClientJSON, self).__init__(None, None)
|
super(V3TokenClientJSON, self).__init__(None, None, None)
|
||||||
auth_url = CONF.identity.uri_v3
|
auth_url = CONF.identity.uri_v3
|
||||||
if not auth_url:
|
if not auth_url:
|
||||||
raise exceptions.InvalidConfiguration('you must specify a v3 uri '
|
raise exceptions.InvalidConfiguration('you must specify a v3 uri '
|
||||||
|
|
|
@ -38,6 +38,7 @@ class ImageClientJSON(rest_client.RestClient):
|
||||||
super(ImageClientJSON, self).__init__(
|
super(ImageClientJSON, self).__init__(
|
||||||
auth_provider,
|
auth_provider,
|
||||||
CONF.image.catalog_type,
|
CONF.image.catalog_type,
|
||||||
|
CONF.image.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.image.endpoint_type)
|
endpoint_type=CONF.image.endpoint_type)
|
||||||
self._http = None
|
self._http = None
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ class ImageClientV2JSON(rest_client.RestClient):
|
||||||
super(ImageClientV2JSON, self).__init__(
|
super(ImageClientV2JSON, self).__init__(
|
||||||
auth_provider,
|
auth_provider,
|
||||||
CONF.image.catalog_type,
|
CONF.image.catalog_type,
|
||||||
|
CONF.image.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.image.endpoint_type)
|
endpoint_type=CONF.image.endpoint_type)
|
||||||
self._http = None
|
self._http = None
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,10 @@ CONF = config.CONF
|
||||||
class MessagingClientJSON(rest_client.RestClient):
|
class MessagingClientJSON(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(MessagingClientJSON, self).__init__(auth_provider,
|
super(MessagingClientJSON, self).__init__(
|
||||||
CONF.messaging.catalog_type)
|
auth_provider,
|
||||||
|
CONF.messaging.catalog_type,
|
||||||
|
CONF.identity.region)
|
||||||
self.version = '1'
|
self.version = '1'
|
||||||
self.uri_prefix = 'v{0}'.format(self.version)
|
self.uri_prefix = 'v{0}'.format(self.version)
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,9 @@ class NetworkClientJSON(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(NetworkClientJSON, self).__init__(
|
super(NetworkClientJSON, self).__init__(
|
||||||
auth_provider, CONF.network.catalog_type,
|
auth_provider,
|
||||||
|
CONF.network.catalog_type,
|
||||||
|
CONF.network.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.network.endpoint_type,
|
endpoint_type=CONF.network.endpoint_type,
|
||||||
build_interval=CONF.network.build_interval,
|
build_interval=CONF.network.build_interval,
|
||||||
build_timeout=CONF.network.build_timeout)
|
build_timeout=CONF.network.build_timeout)
|
||||||
|
|
|
@ -25,6 +25,8 @@ class ObjectStorageClient(rest_client.RestClient):
|
||||||
|
|
||||||
def __init__(self, auth_provider):
|
def __init__(self, auth_provider):
|
||||||
super(ObjectStorageClient, self).__init__(
|
super(ObjectStorageClient, self).__init__(
|
||||||
auth_provider, CONF.object_storage.catalog_type,
|
auth_provider,
|
||||||
|
CONF.object_storage.catalog_type,
|
||||||
|
CONF.object_storage.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.object_storage.endpoint_type)
|
endpoint_type=CONF.object_storage.endpoint_type)
|
||||||
self.format = 'json'
|
self.format = 'json'
|
||||||
|
|
|
@ -31,6 +31,7 @@ class OrchestrationClient(rest_client.RestClient):
|
||||||
super(OrchestrationClient, self).__init__(
|
super(OrchestrationClient, self).__init__(
|
||||||
auth_provider,
|
auth_provider,
|
||||||
CONF.orchestration.catalog_type,
|
CONF.orchestration.catalog_type,
|
||||||
|
CONF.orchestration.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.orchestration.endpoint_type,
|
endpoint_type=CONF.orchestration.endpoint_type,
|
||||||
build_interval=CONF.orchestration.build_interval,
|
build_interval=CONF.orchestration.build_interval,
|
||||||
build_timeout=CONF.orchestration.build_timeout)
|
build_timeout=CONF.orchestration.build_timeout)
|
||||||
|
|
|
@ -28,6 +28,7 @@ class TelemetryClientJSON(rest_client.RestClient):
|
||||||
super(TelemetryClientJSON, self).__init__(
|
super(TelemetryClientJSON, self).__init__(
|
||||||
auth_provider,
|
auth_provider,
|
||||||
CONF.telemetry.catalog_type,
|
CONF.telemetry.catalog_type,
|
||||||
|
CONF.identity.region,
|
||||||
endpoint_type=CONF.telemetry.endpoint_type)
|
endpoint_type=CONF.telemetry.endpoint_type)
|
||||||
self.version = '2'
|
self.version = '2'
|
||||||
self.uri_prefix = "v%s" % self.version
|
self.uri_prefix = "v%s" % self.version
|
||||||
|
|
|
@ -27,6 +27,7 @@ class VolumeClient(rest_client.RestClient):
|
||||||
super(VolumeClient, self).__init__(
|
super(VolumeClient, self).__init__(
|
||||||
auth_provider,
|
auth_provider,
|
||||||
CONF.volume.catalog_type,
|
CONF.volume.catalog_type,
|
||||||
|
CONF.volume.region or CONF.identity.region,
|
||||||
endpoint_type=CONF.volume.endpoint_type,
|
endpoint_type=CONF.volume.endpoint_type,
|
||||||
build_interval=CONF.volume.build_interval,
|
build_interval=CONF.volume.build_interval,
|
||||||
build_timeout=CONF.volume.build_timeout)
|
build_timeout=CONF.volume.build_timeout)
|
||||||
|
|
|
@ -30,18 +30,13 @@ class BaseRestClientTestClass(base.TestCase):
|
||||||
|
|
||||||
url = 'fake_endpoint'
|
url = 'fake_endpoint'
|
||||||
|
|
||||||
def _get_region(self):
|
|
||||||
return 'fake region'
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseRestClientTestClass, self).setUp()
|
super(BaseRestClientTestClass, self).setUp()
|
||||||
self.useFixture(fake_config.ConfigFixture())
|
self.useFixture(fake_config.ConfigFixture())
|
||||||
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
|
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
|
||||||
self.rest_client = rest_client.RestClient(
|
self.rest_client = rest_client.RestClient(
|
||||||
fake_auth_provider.FakeAuthProvider(), None)
|
fake_auth_provider.FakeAuthProvider(), None, None)
|
||||||
self.stubs.Set(httplib2.Http, 'request', self.fake_http.request)
|
self.stubs.Set(httplib2.Http, 'request', self.fake_http.request)
|
||||||
self.useFixture(mockpatch.PatchObject(self.rest_client, '_get_region',
|
|
||||||
side_effect=self._get_region()))
|
|
||||||
self.useFixture(mockpatch.PatchObject(self.rest_client,
|
self.useFixture(mockpatch.PatchObject(self.rest_client,
|
||||||
'_log_request'))
|
'_log_request'))
|
||||||
|
|
||||||
|
@ -304,7 +299,7 @@ class TestRestClientErrorCheckerJSON(base.TestCase):
|
||||||
self.useFixture(fake_config.ConfigFixture())
|
self.useFixture(fake_config.ConfigFixture())
|
||||||
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
|
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
|
||||||
self.rest_client = rest_client.RestClient(
|
self.rest_client = rest_client.RestClient(
|
||||||
fake_auth_provider.FakeAuthProvider(), None)
|
fake_auth_provider.FakeAuthProvider(), None, None)
|
||||||
|
|
||||||
def test_response_less_than_400(self):
|
def test_response_less_than_400(self):
|
||||||
self.rest_client._error_checker(**self.set_data("399"))
|
self.rest_client._error_checker(**self.set_data("399"))
|
||||||
|
|
Loading…
Reference in New Issue