Skip to content

Commit 027c24a

Browse files
committed
move s3 argparser to helpers
1 parent 2a032dd commit 027c24a

File tree

6 files changed

+246
-218
lines changed

6 files changed

+246
-218
lines changed

alter/stress/regression.py

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
from helpers.cluster import create_cluster
99
from helpers.common import check_clickhouse_version, experimental_analyzer
10-
from s3.regression import argparser as argparser_base, CaptureClusterArgs
10+
from helpers.argparser import (
11+
argparser_s3 as argparser_base,
12+
CaptureClusterArgs,
13+
CaptureS3Args,
14+
)
1115
from s3.tests.common import start_minio
1216

1317
xfails = {
@@ -246,22 +250,13 @@ def gcs(
246250
@XFails(xfails)
247251
@FFails(ffails)
248252
@CaptureClusterArgs
253+
@CaptureS3Args
249254
def regression(
250255
self,
251-
cluster_args,
252-
clickhouse_version,
253-
storages,
254-
minio_uri,
255-
gcs_uri,
256-
aws_s3_region,
257-
aws_s3_bucket,
258-
minio_root_user,
259-
minio_root_password,
260-
aws_s3_access_key,
261-
aws_s3_key_id,
262-
gcs_key_secret,
263-
gcs_key_id,
264-
stress,
256+
cluster_args: dict,
257+
s3_args: dict,
258+
clickhouse_version: str,
259+
stress: bool,
265260
with_analyzer=False,
266261
unsafe=False,
267262
):
@@ -272,6 +267,7 @@ def regression(
272267
self.context.stress = stress
273268
self.context.unsafe = unsafe
274269

270+
storages = s3_args.pop("storages", None)
275271
if storages is None:
276272
storages = ["minio"]
277273

@@ -280,30 +276,29 @@ def regression(
280276
with_analyzer=with_analyzer,
281277
)
282278

283-
if "aws_s3" in storages:
284-
Module(test=aws_s3)(
285-
bucket=aws_s3_bucket,
286-
region=aws_s3_region,
287-
key_id=aws_s3_key_id,
288-
access_key=aws_s3_access_key,
289-
**module_args,
290-
)
291-
292-
if "gcs" in storages:
293-
Module(test=gcs)(
294-
uri=gcs_uri,
295-
key_id=gcs_key_id,
296-
access_key=gcs_key_secret,
297-
**module_args,
298-
)
299-
300-
if "minio" in storages:
301-
Module(test=minio)(
302-
uri=minio_uri,
303-
root_user=minio_root_user,
304-
root_password=minio_root_password,
305-
**module_args,
306-
)
279+
for storage in storages:
280+
if storage == "aws_s3":
281+
Module(test=aws_s3)(
282+
bucket=s3_args["aws_s3_bucket"],
283+
region=s3_args["aws_s3_region"],
284+
key_id=s3_args["aws_s3_key_id"],
285+
access_key=s3_args["aws_s3_access_key"],
286+
**module_args,
287+
)
288+
elif storage == "gcs":
289+
Module(test=gcs)(
290+
uri=s3_args["gcs_uri"],
291+
key_id=s3_args["gcs_key_id"],
292+
access_key=s3_args["gcs_key_secret"],
293+
**module_args,
294+
)
295+
elif storage == "minio":
296+
Module(test=minio)(
297+
uri=s3_args["minio_uri"],
298+
root_user=s3_args["minio_root_user"],
299+
root_password=s3_args["minio_root_password"],
300+
**module_args,
301+
)
307302

308303
if "local" in storages:
309304
Module(test=local_storage)(

helpers/argparser.py

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22

3+
from testflows.core import Secret
4+
35

46
def argparser(parser):
5-
"""Default argument parser for regressions."""
7+
"""Default argument parser for regression."""
68
parser.add_argument(
79
"--local",
810
action="store_true",
@@ -169,3 +171,153 @@ def capture_cluster_args(
169171
return func(self, cluster_args=cluster_args, **kwargs)
170172

171173
return capture_cluster_args
174+
175+
176+
def argparser_s3(parser):
177+
"""Extended argument parser for suites with S3 storage."""
178+
argparser(parser)
179+
180+
parser.add_argument(
181+
"--storage",
182+
action="append",
183+
help="select which storage types to run tests with",
184+
choices=["minio", "aws_s3", "gcs", "local"],
185+
default=None,
186+
dest="storages",
187+
)
188+
189+
parser.add_argument(
190+
"--minio-uri",
191+
action="store",
192+
help="set url for the minio connection",
193+
type=Secret(name="minio_uri"),
194+
default="http://minio1:9001",
195+
)
196+
197+
parser.add_argument(
198+
"--minio-root-user",
199+
action="store",
200+
help="minio root user name (access key id)",
201+
type=Secret(name="minio_root_user"),
202+
default="minio_user",
203+
)
204+
205+
parser.add_argument(
206+
"--minio-root-password",
207+
action="store",
208+
help="minio root user password (secret access key)",
209+
type=Secret(name="minio_root_password"),
210+
default="minio123",
211+
)
212+
213+
parser.add_argument(
214+
"--aws-s3-bucket",
215+
action="store",
216+
help="set bucket for the aws connection",
217+
type=Secret(name="aws_s3_bucket"),
218+
default=os.getenv("S3_AMAZON_BUCKET"),
219+
)
220+
221+
parser.add_argument(
222+
"--aws-s3-region",
223+
action="store",
224+
help="set aws region for the aws connection",
225+
type=Secret(name="aws_s3_region"),
226+
default=os.getenv("AWS_DEFAULT_REGION"),
227+
)
228+
229+
parser.add_argument(
230+
"--aws-s3-key-id",
231+
action="store",
232+
help="aws s3 key id",
233+
type=Secret(name="aws_s3_key_id"),
234+
default=os.getenv("AWS_ACCESS_KEY_ID"),
235+
)
236+
237+
parser.add_argument(
238+
"--aws-s3-access-key",
239+
action="store",
240+
help="aws s3 access key",
241+
type=Secret(name="aws_s3_access_key"),
242+
default=os.getenv("AWS_SECRET_ACCESS_KEY"),
243+
)
244+
245+
parser.add_argument(
246+
"--gcs-uri",
247+
action="store",
248+
help="set url for the gcs connection",
249+
type=Secret(name="gcs_uri"),
250+
default=os.getenv("GCS_URI"),
251+
)
252+
253+
parser.add_argument(
254+
"--gcs-key-id",
255+
action="store",
256+
help="gcs key id",
257+
type=Secret(name="gcs_key_id"),
258+
default=os.getenv("GCS_KEY_ID"),
259+
)
260+
261+
parser.add_argument(
262+
"--gcs-key-secret",
263+
action="store",
264+
help="gcs key secret",
265+
type=Secret(name="gcs_key_secret"),
266+
default=os.getenv("GCS_KEY_SECRET"),
267+
)
268+
269+
270+
def CaptureS3Args(func):
271+
"""
272+
Collect S3 arguments from argparser into s3_args.
273+
274+
Usage:
275+
276+
@TestModule
277+
@ArgumentParser(argparser_s3)
278+
@... # other decorators
279+
@CaptureClusterArgs
280+
@CaptureS3Args
281+
def regression(
282+
self,
283+
cluster_args,
284+
s3_args,
285+
clickhouse_version,
286+
stress=None,
287+
with_analyzer=False,
288+
):
289+
...
290+
291+
"""
292+
293+
def capture_s3_args(
294+
self,
295+
storages,
296+
minio_uri,
297+
minio_root_user,
298+
minio_root_password,
299+
aws_s3_bucket,
300+
aws_s3_region,
301+
aws_s3_key_id,
302+
aws_s3_access_key,
303+
gcs_uri,
304+
gcs_key_id,
305+
gcs_key_secret,
306+
**kwargs
307+
):
308+
s3_args = {
309+
"storages": storages,
310+
"minio_uri": minio_uri,
311+
"minio_root_user": minio_root_user,
312+
"minio_root_password": minio_root_password,
313+
"aws_s3_bucket": aws_s3_bucket,
314+
"aws_s3_region": aws_s3_region,
315+
"aws_s3_key_id": aws_s3_key_id,
316+
"aws_s3_access_key": aws_s3_access_key,
317+
"gcs_uri": gcs_uri,
318+
"gcs_key_id": gcs_key_id,
319+
"gcs_key_secret": gcs_key_secret,
320+
}
321+
return func(self, s3_args=s3_args, **kwargs)
322+
323+
return capture_s3_args

ontime_benchmark/benchmark.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
from helpers.cluster import Cluster, create_cluster
1010
from helpers.common import check_clickhouse_version
11-
from s3.regression import argparser as argparser_base, CaptureClusterArgs
11+
from helpers.argparser import (
12+
argparser_s3 as argparser_base,
13+
CaptureClusterArgs,
14+
CaptureS3Args,
15+
)
1216

1317
from s3.tests.common import *
1418

@@ -25,7 +29,7 @@
2529
(
2630
Fail,
2731
"strange and rare error on 23.8",
28-
lambda test: check_clickhouse_version(">23.8")(test)
32+
lambda test: check_clickhouse_version(">=23.8")(test)
2933
and check_clickhouse_version("<24")(test),
3034
".*Cannot assign requested address.*",
3135
)
@@ -55,23 +59,14 @@ def argparser(parser):
5559
@XFails(xfails)
5660
@FFails(ffails)
5761
@CaptureClusterArgs
62+
@CaptureS3Args
5863
def regression(
5964
self,
60-
cluster_args,
61-
clickhouse_version,
62-
storages,
63-
stress,
64-
minio_uri,
65-
gcs_uri,
66-
aws_s3_region,
67-
aws_s3_bucket,
68-
minio_root_user,
69-
minio_root_password,
70-
aws_s3_access_key,
71-
aws_s3_key_id,
72-
gcs_key_secret,
73-
gcs_key_id,
74-
format,
65+
cluster_args: dict,
66+
s3_args: dict,
67+
clickhouse_version: str,
68+
stress: bool,
69+
format: str,
7570
with_analyzer=False,
7671
node="clickhouse1",
7772
):
@@ -87,9 +82,18 @@ def regression(
8782
self.context.clickhouse_version = clickhouse_version
8883
self.context.stress = stress
8984

85+
storages = s3_args.pop("storages", None)
9086
if storages is None:
9187
storages = ["minio"]
9288

89+
aws_s3_access_key = s3_args.get("aws_s3_access_key")
90+
aws_s3_key_id = s3_args.get("aws_s3_key_id")
91+
aws_s3_bucket = s3_args.get("aws_s3_bucket")
92+
aws_s3_region = s3_args.get("aws_s3_region")
93+
gcs_uri = s3_args.get("gcs_uri")
94+
gcs_key_id = s3_args.get("gcs_key_id")
95+
gcs_key_secret = s3_args.get("gcs_key_secret")
96+
9397
for storage in storages:
9498
environ = {}
9599
nodes = {"clickhouse": ("clickhouse1", "clickhouse2", "clickhouse3")}

0 commit comments

Comments
 (0)