Skip to content

Commit 4a23e8b

Browse files
committed
qa/rgw: workunits use real dns name instead of localhost
for vhost-style access, the client needs to use the configured dns name instead of localhost. qa/tasks/rgw.py writes the fully-qualified http endpoint url to a file under $TESTDIR, so try that first before falling back to localhost endpoints Signed-off-by: Casey Bodley <cbodley@redhat.com>
1 parent 6a5d0d0 commit 4a23e8b

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

qa/workunits/rgw/common.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ def exec_cmd(cmd, wait = True, **kwargs):
3131
def create_user(uid, display_name, access_key, secret_key):
3232
_, ret = exec_cmd(f'radosgw-admin user create --uid {uid} --display-name "{display_name}" --access-key {access_key} --secret {secret_key}', check_retcode=False)
3333
assert(ret == 0 or errno.EEXIST)
34-
34+
35+
def read_local_endpoint():
36+
"""
37+
in teuthology, the rgw task writes the local rgw's endpoint url to this file
38+
"""
39+
return exec_cmd('cat ${TESTDIR}/url_file')
40+
3541
def boto_connect(access_key, secret_key, config=None):
36-
def try_connect(portnum, ssl, proto):
37-
endpoint = proto + '://localhost:' + portnum
42+
def try_connect(endpoint):
3843
conn = boto3.resource('s3',
3944
aws_access_key_id=access_key,
4045
aws_secret_access_key=secret_key,
41-
use_ssl=ssl,
46+
use_ssl=endpoint.startswith('https'),
4247
endpoint_url=endpoint,
4348
verify=False,
4449
config=config,
@@ -50,14 +55,22 @@ def try_connect(portnum, ssl, proto):
5055
raise
5156
print('connected to', endpoint)
5257
return conn
58+
59+
try:
60+
endpoint = read_local_endpoint()
61+
return try_connect(endpoint)
62+
except:
63+
# fall back to localhost
64+
pass
65+
5366
try:
54-
return try_connect('80', False, 'http')
67+
return try_connect('http://localhost:80')
5568
except botocore.exceptions.ConnectionError:
5669
try: # retry on non-privileged http port
57-
return try_connect('8000', False, 'http')
70+
return try_connect('http://localhost:8000')
5871
except botocore.exceptions.ConnectionError:
5972
# retry with ssl
60-
return try_connect('443', True, 'https')
73+
return try_connect('https://localhost:443')
6174

6275
def put_objects(bucket, key_list):
6376
objs = []

qa/workunits/rgw/test_rgw_admin_pagination.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import subprocess
1313
import unittest
1414
from urllib.parse import urljoin
15+
from common import read_local_endpoint
1516

1617
import typing as ty
1718

@@ -127,20 +128,27 @@ def get_boto3_session(self, user: ty.Dict) -> boto3.session.Session:
127128

128129
def get_boto3_client(self, session: boto3.session.Session):
129130
"""Get a boto3 s3 client from a session."""
130-
def _try_client(portnum: str, ssl: bool, proto: str):
131-
endpoint = proto + '://localhost:' + portnum
131+
def _try_client(endpoint):
132+
ssl = endpoint.startswith('https')
132133
client = session.client(
133134
's3', use_ssl=ssl, endpoint_url=endpoint, verify=False)
134135
list(client.list_buckets(MaxBuckets=1))
135136
return endpoint, client
136137

137138
try:
138-
return _try_client('80', False, 'http')
139+
endpoint = read_local_endpoint()
140+
return _try_client(endpoint)
141+
except:
142+
# fall back to localhost
143+
pass
144+
145+
try:
146+
return _try_client('http://localhost:80')
139147
except Exception:
140148
try:
141-
return _try_client('8000', False, 'http')
149+
return _try_client('http://localhost:8000')
142150
except Exception:
143-
return _try_client('443', True, 'https')
151+
return _try_client('https://localhost:443')
144152

145153

146154
class TestRGWAdminBucket(unittest.TestCase):

0 commit comments

Comments
 (0)