1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
"""
Test Swift API
"""
from io import BytesIO
from configobj import ConfigObj
import base64
import contextlib
import logging
import os
from distutils.version import LooseVersion
from teuthology import misc as teuthology
from teuthology import contextutil
from teuthology.config import config as teuth_config
from teuthology.orchestra import run
log = logging.getLogger(__name__)
@contextlib.contextmanager
def download(ctx, config):
"""
Download the Swift API.
"""
testdir = teuthology.get_testdir(ctx)
assert isinstance(config, dict)
log.info('Downloading swift...')
for (client, cconf) in config.items():
ctx.cluster.only(client).run(
args=[
'git', 'clone',
'-b', cconf.get('force-branch', 'ceph-nautilus'),
teuth_config.ceph_git_base_url + 'swift.git',
'{tdir}/swift'.format(tdir=testdir),
],
)
try:
yield
finally:
log.info('Removing swift...')
testdir = teuthology.get_testdir(ctx)
for (client, _) in config.items():
ctx.cluster.only(client).run(
args=[
'rm',
'-rf',
'{tdir}/swift'.format(tdir=testdir),
],
)
def _config_user(testswift_conf, account, user, suffix):
"""
Configure a swift user
:param account: Swift account
:param user: User name
:param suffix: user name and email suffixes.
"""
testswift_conf['func_test'].setdefault('account{s}'.format(s=suffix), account)
testswift_conf['func_test'].setdefault('username{s}'.format(s=suffix), user)
testswift_conf['func_test'].setdefault('email{s}'.format(s=suffix), '{account}+test@test.test'.format(account=account))
testswift_conf['func_test'].setdefault('display_name{s}'.format(s=suffix), 'Mr. {account} {user}'.format(account=account, user=user))
testswift_conf['func_test'].setdefault('password{s}'.format(s=suffix), base64.b64encode(os.urandom(40)).decode('ascii'))
@contextlib.contextmanager
def create_users(ctx, config):
"""
Create rgw users to interact with the swift interface.
"""
assert isinstance(config, dict)
log.info('Creating rgw users...')
testdir = teuthology.get_testdir(ctx)
users = {'': 'foo', '2': 'bar'}
for client, testswift_conf in config.items():
cluster_name, daemon_type, client_id = teuthology.split_role(client)
for suffix, user in users.items():
_config_user(testswift_conf, '{user}.{client}'.format(user=user, client=client), user, suffix)
ctx.cluster.only(client).run(
args=[
'adjust-ulimits',
'ceph-coverage',
'{tdir}/archive/coverage'.format(tdir=testdir),
'radosgw-admin',
'-n', client,
'--cluster', cluster_name,
'user', 'create',
'--subuser', '{account}:{user}'.format(account=testswift_conf['func_test']['account{s}'.format(s=suffix)],user=user),
'--display-name', testswift_conf['func_test']['display_name{s}'.format(s=suffix)],
'--secret', testswift_conf['func_test']['password{s}'.format(s=suffix)],
'--email', testswift_conf['func_test']['email{s}'.format(s=suffix)],
'--key-type', 'swift',
'--access', 'full',
],
)
try:
yield
finally:
for client in config.keys():
for user in users.values():
uid = '{user}.{client}'.format(user=user, client=client)
cluster_name, daemon_type, client_id = teuthology.split_role(client)
ctx.cluster.only(client).run(
args=[
'adjust-ulimits',
'ceph-coverage',
'{tdir}/archive/coverage'.format(tdir=testdir),
'radosgw-admin',
'-n', client,
'--cluster', cluster_name,
'user', 'rm',
'--uid', uid,
'--purge-data',
],
)
@contextlib.contextmanager
def configure(ctx, config):
"""
Configure rgw and Swift
"""
assert isinstance(config, dict)
log.info('Configuring testswift...')
testdir = teuthology.get_testdir(ctx)
for client, testswift_conf in config.items():
(remote,) = ctx.cluster.only(client).remotes.keys()
remote.run(
args=[
'cd',
'{tdir}/swift'.format(tdir=testdir),
run.Raw('&&'),
'./bootstrap',
],
)
conf_fp = BytesIO()
testswift_conf.write(conf_fp)
teuthology.write_file(
remote=remote,
path='{tdir}/archive/testswift.{client}.conf'.format(tdir=testdir, client=client),
data=conf_fp.getvalue(),
)
yield
@contextlib.contextmanager
def run_tests(ctx, config):
"""
Run an individual Swift test.
"""
assert isinstance(config, dict)
testdir = teuthology.get_testdir(ctx)
for client, client_config in config.items():
args = [
'SWIFT_TEST_CONFIG_FILE={tdir}/archive/testswift.{client}.conf'.format(tdir=testdir, client=client),
'{tdir}/swift/virtualenv/bin/nosetests'.format(tdir=testdir),
'-w',
'{tdir}/swift/test/functional'.format(tdir=testdir),
'-v',
'-a', '!fails_on_rgw',
]
if client_config is not None and 'extra_args' in client_config:
args.extend(client_config['extra_args'])
ctx.cluster.only(client).run(
args=args,
)
yield
@contextlib.contextmanager
def task(ctx, config):
"""
Run the testswift suite against rgw.
To run all tests on all clients::
tasks:
- ceph:
- rgw:
- testswift:
To restrict testing to particular clients::
tasks:
- ceph:
- rgw: [client.0]
- testswift: [client.0]
To run against a server on client.1::
tasks:
- ceph:
- rgw: [client.1]
- testswift:
client.0:
rgw_server: client.1
To pass extra arguments to nose (e.g. to run a certain test)::
tasks:
- ceph:
- rgw: [client.0]
- testswift:
client.0:
extra_args: ['test.functional.tests:TestFileUTF8', '-m', 'testCopy']
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"
all_clients = ['client.{id}'.format(id=id_)
for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
if config is None:
config = all_clients
if isinstance(config, list):
config = dict.fromkeys(config)
testswift_conf = {}
clients = []
for client, client_config in config.items():
# http://tracker.ceph.com/issues/40304 can't bootstrap on rhel 7.6+
(remote,) = ctx.cluster.only(client).remotes.keys()
if remote.os.name == 'rhel' and LooseVersion(remote.os.version) >= LooseVersion('7.6'):
log.warning('Swift tests cannot run on rhel 7.6+, skipping client {}'.format(client))
continue
clients.append(client)
server = client_config.get('rgw_server', client)
endpoint = ctx.rgw.role_endpoints.get(server)
assert endpoint, 'swift: no rgw endpoint for {}'.format(server)
testswift_conf[client] = ConfigObj(
indent_type='',
infile={
'func_test':
{
'auth_host' : endpoint.hostname,
'auth_port' : endpoint.port,
'auth_ssl' : 'yes' if endpoint.cert else 'no',
'auth_prefix' : '/auth/',
},
}
)
# only take config for valid clients
config = {c: config[c] for c in clients}
log.info('clients={c}'.format(c=config.keys()))
with contextutil.nested(
lambda: download(ctx=ctx, config=config),
lambda: create_users(ctx=ctx, config=testswift_conf),
lambda: configure(ctx=ctx, config=testswift_conf),
lambda: run_tests(ctx=ctx, config=config),
):
pass
yield
|