From d4c33f0177139b8b83d6115fbe6135830607b41e Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 21 Feb 2018 11:19:48 -0500 Subject: [PATCH] qa/rgw: add class for rgw endpoints Signed-off-by: Casey Bodley --- qa/tasks/radosgw_admin.py | 10 ++++----- qa/tasks/ragweed.py | 6 +++++- qa/tasks/rgw.py | 45 ++++++++++++++++++++++++--------------- qa/tasks/rgw_multisite.py | 5 +++-- qa/tasks/s3tests.py | 6 +++++- qa/tasks/swift.py | 6 +++++- 6 files changed, 51 insertions(+), 27 deletions(-) diff --git a/qa/tasks/radosgw_admin.py b/qa/tasks/radosgw_admin.py index f23a3b9ef40..8686f7ad21f 100644 --- a/qa/tasks/radosgw_admin.py +++ b/qa/tasks/radosgw_admin.py @@ -279,7 +279,7 @@ def task(ctx, config): # once the client is chosen, pull the host name and assigned port out of # the role_endpoints that were assigned by the rgw task - (remote_host, remote_port) = ctx.rgw.role_endpoints[client] + endpoint = ctx.rgw.role_endpoints[client] ## user1='foo' @@ -305,16 +305,16 @@ def task(ctx, config): aws_access_key_id=access_key, aws_secret_access_key=secret_key, is_secure=False, - port=remote_port, - host=remote_host, + port=endpoint.port, + host=endpoint.hostname, calling_format=boto.s3.connection.OrdinaryCallingFormat(), ) connection2 = boto.s3.connection.S3Connection( aws_access_key_id=access_key2, aws_secret_access_key=secret_key2, is_secure=False, - port=remote_port, - host=remote_host, + port=endpoint.port, + host=endpoint.hostname, calling_format=boto.s3.connection.OrdinaryCallingFormat(), ) diff --git a/qa/tasks/ragweed.py b/qa/tasks/ragweed.py index b1586914f02..2080ccbd9ac 100644 --- a/qa/tasks/ragweed.py +++ b/qa/tasks/ragweed.py @@ -308,6 +308,7 @@ def task(ctx, config): client.1: extra_args: ['--exclude', 'test_100_continue'] """ + assert hasattr(ctx, 'rgw'), 'ragweed must run after the rgw task' assert config is None or isinstance(config, list) \ or isinstance(config, dict), \ "task ragweed only supports a list or dictionary for configuration" @@ -330,12 +331,15 @@ def task(ctx, config): ragweed_conf = {} for client in clients: + endpoint = ctx.rgw.role_endpoints.get(client) + assert endpoint, 'ragweed: no rgw endpoint for {}'.format(client) + ragweed_conf[client] = ConfigObj( indent_type='', infile={ 'rgw': { - 'port' : 7280, + 'port' : endpoint.port, 'is_secure' : 'no', }, 'fixtures' : {}, diff --git a/qa/tasks/rgw.py b/qa/tasks/rgw.py index 54c281a5a46..4ba7bf93831 100644 --- a/qa/tasks/rgw.py +++ b/qa/tasks/rgw.py @@ -13,6 +13,7 @@ from teuthology.orchestra import run from teuthology import misc as teuthology from teuthology import contextutil from teuthology.orchestra.run import CommandFailedError +from util import get_remote_for_role from util.rgw import rgwadmin, wait_for_radosgw from util.rados import (rados, create_ec_pool, create_replicated_pool, @@ -20,6 +21,14 @@ from util.rados import (rados, create_ec_pool, log = logging.getLogger(__name__) +class RGWEndpoint: + def __init__(self, hostname=None, port=None): + self.hostname = hostname + self.port = port + + def url(self): + return 'http://{hostname}:{port}/'.format(hostname=self.hostname, port=self.port) + @contextlib.contextmanager def start_rgw(ctx, config, clients): """ @@ -50,10 +59,10 @@ def start_rgw(ctx, config, clients): log.info("Using %s as radosgw frontend", ctx.rgw.frontend) - host, port = ctx.rgw.role_endpoints[client] + endpoint = ctx.rgw.role_endpoints[client] frontends = \ '{frontend} port={port}'.format(frontend=ctx.rgw.frontend, - port=port) + port=endpoint.port) frontend_prefix = client_config.get('frontend_prefix', None) if frontend_prefix: frontends += ' prefix={pfx}'.format(pfx=frontend_prefix) @@ -73,8 +82,8 @@ def start_rgw(ctx, config, clients): if keystone_role is not None: if not ctx.keystone: raise ConfigError('rgw must run after the keystone task') - url = 'http://{host}:{port}/v1/KEY_$(tenant_id)s'.format(host=host, - port=port) + url = 'http://{host}:{port}/v1/KEY_$(tenant_id)s'.format(host=endpoint.hostname, + port=endpoint.port) ctx.keystone.create_endpoint(ctx, keystone_role, 'swift', url) keystone_host, keystone_port = \ @@ -117,10 +126,10 @@ def start_rgw(ctx, config, clients): # XXX: add_daemon() doesn't let us wait until radosgw finishes startup for client in config.keys(): - host, port = ctx.rgw.role_endpoints[client] - endpoint = 'http://{host}:{port}/'.format(host=host, port=port) - log.info('Polling {client} until it starts accepting connections on {endpoint}'.format(client=client, endpoint=endpoint)) - wait_for_radosgw(endpoint) + endpoint = ctx.rgw.role_endpoints[client] + url = endpoint.url() + log.info('Polling {client} until it starts accepting connections on {url}'.format(client=client, url=url)) + wait_for_radosgw(url) try: yield @@ -139,17 +148,18 @@ def start_rgw(ctx, config, clients): ], ) -def assign_ports(ctx, config): +def assign_endpoints(ctx, config): """ - Assign port numberst starting with port 7280. + Assign port numbers starting with port 7280. """ port = 7280 role_endpoints = {} - for remote, roles_for_host in ctx.cluster.remotes.iteritems(): - for role in roles_for_host: - if role in config: - role_endpoints[role] = (remote.name.split('@')[1], port) - port += 1 + + for role, client_config in config.iteritems(): + client_config = client_config or {} + remote = get_remote_for_role(ctx, role) + role_endpoints[role] = RGWEndpoint(remote.hostname, port) + port += 1 return role_endpoints @@ -236,9 +246,7 @@ def task(ctx, config): overrides = ctx.config.get('overrides', {}) teuthology.deep_merge(config, overrides.get('rgw', {})) - role_endpoints = assign_ports(ctx, config) ctx.rgw = argparse.Namespace() - ctx.rgw.role_endpoints = role_endpoints ctx.rgw.ec_data_pool = bool(config.pop('ec-data-pool', False)) ctx.rgw.erasure_code_profile = config.pop('erasure_code_profile', {}) @@ -249,6 +257,9 @@ def task(ctx, config): log.debug("config is {}".format(config)) log.debug("client list is {}".format(clients)) + + ctx.rgw.role_endpoints = assign_endpoints(ctx, config) + subtasks = [ lambda: create_pools(ctx=ctx, clients=clients), ] diff --git a/qa/tasks/rgw_multisite.py b/qa/tasks/rgw_multisite.py index 668696b63b4..a3697278ac2 100644 --- a/qa/tasks/rgw_multisite.py +++ b/qa/tasks/rgw_multisite.py @@ -236,7 +236,7 @@ def extract_clusters_and_gateways(ctx, role_endpoints): """ create cluster and gateway instances for all of the radosgw roles """ clusters = {} gateways = {} - for role, (host, port) in role_endpoints.iteritems(): + for role, endpoint in role_endpoints.iteritems(): cluster_name, daemon_type, client_id = misc.split_role(role) # find or create the cluster by name cluster = clusters.get(cluster_name) @@ -249,7 +249,8 @@ def extract_clusters_and_gateways(ctx, role_endpoints): raise ConfigError('no daemon for role=%s cluster=%s type=rgw id=%s' % \ (role, cluster_name, client_id)) (remote,) = ctx.cluster.only(role).remotes.keys() - gateways[role] = Gateway(role, remote, daemon, host, port, cluster) + gateways[role] = Gateway(role, remote, daemon, endpoint.hostname, + endpoint.port, cluster) return clusters, gateways def create_realm(cluster, config): diff --git a/qa/tasks/s3tests.py b/qa/tasks/s3tests.py index 00bc6b4e34a..2068711c682 100644 --- a/qa/tasks/s3tests.py +++ b/qa/tasks/s3tests.py @@ -335,6 +335,7 @@ def task(ctx, config): client.1: extra_args: ['--exclude', 'test_100_continue'] """ + assert hasattr(ctx, 'rgw'), 's3tests must run after the rgw task' assert config is None or isinstance(config, list) \ or isinstance(config, dict), \ "task s3tests only supports a list or dictionary for configuration" @@ -357,12 +358,15 @@ def task(ctx, config): s3tests_conf = {} for client in clients: + endpoint = ctx.rgw.role_endpoints.get(client) + assert endpoint, 's3tests: no rgw endpoint for {}'.format(client) + s3tests_conf[client] = ConfigObj( indent_type='', infile={ 'DEFAULT': { - 'port' : 7280, + 'port' : endpoint.port, 'is_secure' : 'no', }, 'fixtures' : {}, diff --git a/qa/tasks/swift.py b/qa/tasks/swift.py index 28f75dd0afd..81d686b0f0b 100644 --- a/qa/tasks/swift.py +++ b/qa/tasks/swift.py @@ -220,6 +220,7 @@ def task(ctx, config): client.1: extra_args: ['--exclude', 'TestFile'] """ + assert hasattr(ctx, 'rgw'), 'swift must run after the rgw task' assert config is None or isinstance(config, list) \ or isinstance(config, dict), \ "task testswift only supports a list or dictionary for configuration" @@ -235,12 +236,15 @@ def task(ctx, config): testswift_conf = {} for client in clients: + endpoint = ctx.rgw.role_endpoints.get(client) + assert endpoint, 'swift: no rgw endpoint for {}'.format(client) + testswift_conf[client] = ConfigObj( indent_type='', infile={ 'func_test': { - 'auth_port' : 7280, + 'auth_port' : endpoint.port, 'auth_ssl' : 'no', 'auth_prefix' : '/auth/', }, -- 2.39.5