Functional tests: Use a configurable url pattern

This removes the append_version_to_url config option in favor of
a pattern that will build the request url by interpolating arguments.

Change-Id: I0b1152d518a5f4ddfcfc5d5a7b28606932a86c4b
This commit is contained in:
Paul Glass 2015-10-01 19:07:23 +00:00
parent d0d2816e8c
commit 9bdcb63904
12 changed files with 62 additions and 70 deletions

View File

@ -76,8 +76,14 @@ The config file should look like the following:
nameservers = 127.0.0.1:53,127.0.0.2:53 nameservers = 127.0.0.1:53,127.0.0.2:53
[testconfig] [testconfig]
# if true, make requests to {url}/v2/zones instead of {url}/zones # Specify how build the path for the request. This will be appended
append_version_to_url = True # directly to the url from the service catalog (or the override url).
# {tenant_id} - the tenant id
# {tenant_name} - the tenant name
# {user} - the username of the tenant
# {user_id} - the user_id of the tenant
# {path} - the versionless resource path, e.g. /zones/ID"),
v2_path_pattern = '/v2/{path}'
# if true, skip doing admin actions like increasing quotas in test setups # if true, skip doing admin actions like increasing quotas in test setups
no_admin_setup = False no_admin_setup = False

View File

@ -21,13 +21,11 @@ from functionaltests.common.client import ClientMixin
class BlacklistClient(ClientMixin): class BlacklistClient(ClientMixin):
@classmethod def blacklists_uri(self, filters=None):
def blacklists_uri(cls, filters=None): return self.create_uri("/blacklists", filters=filters)
return cls.create_uri("/blacklists", filters=filters)
@classmethod def blacklist_uri(self, blacklist_id):
def blacklist_uri(cls, blacklist_id): return "{0}/{1}".format(self.blacklists_uri(), blacklist_id)
return "{0}/{1}".format(cls.blacklists_uri(), blacklist_id)
def list_blacklists(self, filters=None, **kwargs): def list_blacklists(self, filters=None, **kwargs):
resp, body = self.client.get(self.blacklists_uri(filters), **kwargs) resp, body = self.client.get(self.blacklists_uri(filters), **kwargs)

View File

@ -21,13 +21,11 @@ from functionaltests.common.client import ClientMixin
class PoolClient(ClientMixin): class PoolClient(ClientMixin):
@classmethod def pools_uri(self, filters=None):
def pools_uri(cls, filters=None): return self.create_uri("/pools", filters=filters)
return cls.create_uri("/pools", filters=filters)
@classmethod def pool_uri(self, pool_id):
def pool_uri(cls, pool_id): return "{0}/{1}".format(self.pools_uri(), pool_id)
return "{0}/{1}".format(cls.pools_uri(), pool_id)
def list_pools(self, filters=None, **kwargs): def list_pools(self, filters=None, **kwargs):
resp, body = self.client.get(self.pools_uri(filters), **kwargs) resp, body = self.client.get(self.pools_uri(filters), **kwargs)

View File

@ -20,11 +20,10 @@ from functionaltests.common.client import ClientMixin
class QuotasClient(ClientMixin): class QuotasClient(ClientMixin):
@classmethod def quotas_uri(self, tenant_id, filters=None):
def quotas_uri(cls, tenant_id, filters=None):
url = "/admin/quotas/{0}".format(tenant_id) url = "/admin/quotas/{0}".format(tenant_id)
if filters: if filters:
url = cls.add_filters(url, filters) url = self.add_filters(url, filters)
return url return url
def get_quotas(self, tenant_id, filters=None, **kwargs): def get_quotas(self, tenant_id, filters=None, **kwargs):

View File

@ -24,14 +24,12 @@ from functionaltests.common import utils
class RecordsetClient(ClientMixin): class RecordsetClient(ClientMixin):
@classmethod def recordsets_uri(self, zone_id, filters=None):
def recordsets_uri(cls, zone_id, filters=None): return self.create_uri("/zones/{0}/recordsets".format(zone_id),
return cls.create_uri("/zones/{0}/recordsets".format(zone_id),
filters=filters) filters=filters)
@classmethod def recordset_uri(self, zone_id, recordset_id):
def recordset_uri(cls, zone_id, recordset_id): return "{0}/{1}".format(self.recordsets_uri(zone_id), recordset_id)
return "{0}/{1}".format(cls.recordsets_uri(zone_id), recordset_id)
def list_recordsets(self, zone_id, filters=None, **kwargs): def list_recordsets(self, zone_id, filters=None, **kwargs):
resp, body = self.client.get( resp, body = self.client.get(

View File

@ -23,14 +23,12 @@ from functionaltests.common.client import ClientMixin
class TransferAcceptClient(ClientMixin): class TransferAcceptClient(ClientMixin):
@classmethod def transfer_accepts_uri(self, filters=None):
def transfer_accepts_uri(cls, filters=None): return self.create_uri("/zones/tasks/transfer_accepts",
return cls.create_uri("/zones/tasks/transfer_accepts",
filters=filters) filters=filters)
@classmethod def transfer_accept_uri(self, transfer_request_id):
def transfer_accept_uri(cls, transfer_request_id): return "{0}/{1}".format(self.transfer_accepts_uri(),
return "{0}/{1}".format(cls.transfer_accepts_uri(),
transfer_request_id) transfer_request_id)
def list_transfer_accepts(self, zone_id, filters=None, **kwargs): def list_transfer_accepts(self, zone_id, filters=None, **kwargs):

View File

@ -23,23 +23,20 @@ from functionaltests.common.client import ClientMixin
class TransferRequestClient(ClientMixin): class TransferRequestClient(ClientMixin):
@classmethod def create_transfer_requests_uri(self, zone_id, filters=None):
def create_transfer_requests_uri(cls, zone_id, filters=None): return self.create_uri(
return cls.create_uri(
"/zones/{0}/tasks/transfer_requests".format(zone_id), "/zones/{0}/tasks/transfer_requests".format(zone_id),
filters=filters, filters=filters,
) )
@classmethod def transfer_requests_uri(self, filters=None):
def transfer_requests_uri(cls, filters=None): return self.create_uri(
return cls.create_uri(
"/zones/tasks/transfer_requests", "/zones/tasks/transfer_requests",
filters=filters, filters=filters,
) )
@classmethod def transfer_request_uri(self, transfer_request_id):
def transfer_request_uri(cls, transfer_request_id): return self.create_uri(
return cls.create_uri(
"/zones/tasks/transfer_requests/{0}".format(transfer_request_id) "/zones/tasks/transfer_requests/{0}".format(transfer_request_id)
) )

View File

@ -24,13 +24,11 @@ from functionaltests.common import utils
class ZoneClient(ClientMixin): class ZoneClient(ClientMixin):
@classmethod def zones_uri(self, filters=None):
def zones_uri(cls, filters=None): return self.create_uri("/zones", filters=filters)
return cls.create_uri("/zones", filters=filters)
@classmethod def zone_uri(self, id):
def zone_uri(cls, id): return "{0}/{1}".format(self.zones_uri(), id)
return "{0}/{1}".format(cls.zones_uri(), id)
def list_zones(self, filters=None, **kwargs): def list_zones(self, filters=None, **kwargs):
resp, body = self.client.get(self.zones_uri(filters), **kwargs) resp, body = self.client.get(self.zones_uri(filters), **kwargs)

View File

@ -22,20 +22,17 @@ from functionaltests.common.models import ZoneFile
class ZoneExportClient(ClientMixin): class ZoneExportClient(ClientMixin):
@classmethod def zone_exports_uri(self, filters=None):
def zone_exports_uri(cls, filters=None): return self.create_uri("/zones/tasks/exports", filters=filters)
return cls.create_uri("/zones/tasks/exports", filters=filters)
@classmethod def create_zone_export_uri(self, zone_id, filters=None):
def create_zone_export_uri(cls, zone_id, filters=None): return self.create_uri(
return cls.create_uri(
"/zones/{0}/tasks/export".format(zone_id), "/zones/{0}/tasks/export".format(zone_id),
filters=filters, filters=filters,
) )
@classmethod def zone_export_uri(self, id):
def zone_export_uri(cls, id): return "{0}/{1}".format(self.zone_exports_uri(), id)
return "{0}/{1}".format(cls.zone_exports_uri(), id)
def list_zone_exports(self, filters=None, **kwargs): def list_zone_exports(self, filters=None, **kwargs):
resp, body = self.client.get( resp, body = self.client.get(

View File

@ -21,13 +21,11 @@ from functionaltests.common import utils
class ZoneImportClient(ClientMixin): class ZoneImportClient(ClientMixin):
@classmethod def zone_imports_uri(self, filters=None):
def zone_imports_uri(cls, filters=None): return self.create_uri("/zones/tasks/imports", filters=filters)
return cls.create_uri("/zones/tasks/imports", filters=filters)
@classmethod def zone_import_uri(self, id):
def zone_import_uri(cls, id): return "{0}/{1}".format(self.zone_imports_uri(), id)
return "{0}/{1}".format(cls.zone_imports_uri(), id)
def list_zone_imports(self, filters=None, **kwargs): def list_zone_imports(self, filters=None, **kwargs):
resp, body = self.client.get( resp, body = self.client.get(

View File

@ -185,12 +185,17 @@ class ClientMixin(object):
first = False first = False
return url return url
@classmethod def create_uri(self, path, filters=None):
def create_uri(cls, path, filters=None): url_pattern = cfg.CONF.testconfig.v2_path_pattern
if cfg.CONF.testconfig.append_version_to_url: params = {
uri = "/v2/{0}".format(path) 'path': path,
else: 'tenant_id': self.client.tenant_id,
uri = path 'tenant_name': self.client.tenant_name,
'user': self.client.user,
'user_id': self.client.user_id,
}
uri = url_pattern.format(**params)
uri.replace('//', '/')
if filters: if filters:
uri = cls.add_filters(uri, filters) uri = self.add_filters(uri, filters)
return uri return uri

View File

@ -69,8 +69,8 @@ cfg.CONF.register_opts([
cfg.CONF.register_opts([ cfg.CONF.register_opts([
cfg.BoolOpt('append_version_to_url', default=True, cfg.StrOpt('v2_path_pattern', default='/v2/{path}',
help="Post to url + /v2/zones instead of url + /zones"), help="Specifies how to build the path for the request"),
cfg.BoolOpt('no_admin_setup', default=False, cfg.BoolOpt('no_admin_setup', default=False,
help="Skip admin actions (like increasing quotas) in setUp()") help="Skip admin actions (like increasing quotas) in setUp()")
], group='testconfig') ], group='testconfig')