forked from mongodb/mongo-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_config.py
1007 lines (868 loc) · 33.9 KB
/
generate_config.py
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "shrub.py>=3.2.0",
# "pyyaml>=6.0.2"
# ]
# ///
# Note: Run this file with `pipx run`, or `uv run`.
from __future__ import annotations
import sys
from dataclasses import dataclass
from inspect import getmembers, isfunction
from itertools import cycle, product, zip_longest
from pathlib import Path
from typing import Any
from shrub.v3.evg_build_variant import BuildVariant
from shrub.v3.evg_command import FunctionCall
from shrub.v3.evg_project import EvgProject
from shrub.v3.evg_task import EvgTask, EvgTaskRef
from shrub.v3.shrub_service import ShrubService
##############
# Globals
##############
ALL_VERSIONS = ["4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"]
CPYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
PYPYS = ["pypy3.10"]
ALL_PYTHONS = CPYTHONS + PYPYS
MIN_MAX_PYTHON = [CPYTHONS[0], CPYTHONS[-1]]
BATCHTIME_WEEK = 10080
AUTH_SSLS = [("auth", "ssl"), ("noauth", "ssl"), ("noauth", "nossl")]
TOPOLOGIES = ["standalone", "replica_set", "sharded_cluster"]
C_EXTS = ["with_ext", "without_ext"]
# By default test each of the topologies with a subset of auth/ssl.
SUB_TASKS = [
".sharded_cluster .auth .ssl",
".replica_set .noauth .ssl",
".standalone .noauth .nossl",
]
SYNCS = ["sync", "async", "sync_async"]
DISPLAY_LOOKUP = dict(
ssl=dict(ssl="SSL", nossl="NoSSL"),
auth=dict(auth="Auth", noauth="NoAuth"),
test_suites=dict(default="Sync", default_async="Async"),
coverage=dict(coverage="cov"),
no_ext={"1": "No C"},
)
HOSTS = dict()
@dataclass
class Host:
name: str
run_on: str
display_name: str
variables: dict[str, str] | None
# Hosts with toolchains.
HOSTS["rhel8"] = Host("rhel8", "rhel87-small", "RHEL8", dict())
HOSTS["win64"] = Host("win64", "windows-64-vsMulti-small", "Win64", dict())
HOSTS["win32"] = Host("win32", "windows-64-vsMulti-small", "Win32", dict())
HOSTS["macos"] = Host("macos", "macos-14", "macOS", dict())
HOSTS["macos-arm64"] = Host("macos-arm64", "macos-14-arm64", "macOS Arm64", dict())
HOSTS["ubuntu20"] = Host("ubuntu20", "ubuntu2004-small", "Ubuntu-20", dict())
HOSTS["ubuntu22"] = Host("ubuntu22", "ubuntu2204-small", "Ubuntu-22", dict())
HOSTS["rhel7"] = Host("rhel7", "rhel79-small", "RHEL7", dict())
DEFAULT_HOST = HOSTS["rhel8"]
# Other hosts
OTHER_HOSTS = ["RHEL9-FIPS", "RHEL8-zseries", "RHEL8-POWER8", "RHEL8-arm64"]
for name, run_on in zip(
OTHER_HOSTS, ["rhel92-fips", "rhel8-zseries-small", "rhel8-power-small", "rhel82-arm64-small"]
):
HOSTS[name] = Host(name, run_on, name, dict())
##############
# Helpers
##############
def create_variant_generic(
task_names: list[str],
display_name: str,
*,
host: Host | None = None,
default_run_on="rhel87-small",
expansions: dict | None = None,
**kwargs: Any,
) -> BuildVariant:
"""Create a build variant for the given inputs."""
task_refs = [EvgTaskRef(name=n) for n in task_names]
expansions = expansions and expansions.copy() or dict()
if "run_on" in kwargs:
run_on = kwargs.pop("run_on")
elif host:
run_on = [host.run_on]
if host.variables:
expansions.update(host.variables)
else:
run_on = [default_run_on]
if isinstance(run_on, str):
run_on = [run_on]
name = display_name.replace(" ", "-").replace("*-", "").lower()
return BuildVariant(
name=name,
display_name=display_name,
tasks=task_refs,
expansions=expansions or None,
run_on=run_on,
**kwargs,
)
def create_variant(
task_names: list[str],
display_name: str,
*,
version: str | None = None,
host: Host | None = None,
python: str | None = None,
expansions: dict | None = None,
**kwargs: Any,
) -> BuildVariant:
expansions = expansions and expansions.copy() or dict()
if version:
expansions["VERSION"] = version
if python:
expansions["PYTHON_BINARY"] = get_python_binary(python, host)
return create_variant_generic(
task_names, display_name, version=version, host=host, expansions=expansions, **kwargs
)
def get_python_binary(python: str, host: Host) -> str:
"""Get the appropriate python binary given a python version and host."""
name = host.name
if name in ["win64", "win32"]:
if name == "win32":
base = "C:/python/32"
else:
base = "C:/python"
python = python.replace(".", "")
if python == "313t":
return f"{base}/Python313/python3.13t.exe"
return f"{base}/Python{python}/python.exe"
if name in ["rhel8", "ubuntu22", "ubuntu20", "rhel7"]:
return f"/opt/python/{python}/bin/python3"
if name in ["macos", "macos-arm64"]:
if python == "3.13t":
return "/Library/Frameworks/PythonT.Framework/Versions/3.13/bin/python3t"
return f"/Library/Frameworks/Python.Framework/Versions/{python}/bin/python3"
raise ValueError(f"no match found for python {python} on {name}")
def get_versions_from(min_version: str) -> list[str]:
"""Get all server versions starting from a minimum version."""
min_version_float = float(min_version)
rapid_latest = ["rapid", "latest"]
versions = [v for v in ALL_VERSIONS if v not in rapid_latest]
return [v for v in versions if float(v) >= min_version_float] + rapid_latest
def get_versions_until(max_version: str) -> list[str]:
"""Get all server version up to a max version."""
max_version_float = float(max_version)
versions = [v for v in ALL_VERSIONS if v not in ["rapid", "latest"]]
versions = [v for v in versions if float(v) <= max_version_float]
if not len(versions):
raise ValueError(f"No server versions found less <= {max_version}")
return versions
def get_display_name(base: str, host: Host | None = None, **kwargs) -> str:
"""Get the display name of a variant."""
display_name = base
if host is not None:
display_name += f" {host.display_name}"
version = kwargs.pop("VERSION", None)
version = version or kwargs.pop("version", None)
if version:
if version not in ["rapid", "latest"]:
version = f"v{version}"
display_name = f"{display_name} {version}"
for key, value in kwargs.items():
name = value
if key.lower() == "python":
if not value.startswith("pypy"):
name = f"Python{value}"
else:
name = f"PyPy{value.replace('pypy', '')}"
elif key.lower() in DISPLAY_LOOKUP:
name = DISPLAY_LOOKUP[key.lower()][value]
else:
continue
display_name = f"{display_name} {name}"
return display_name
def zip_cycle(*iterables, empty_default=None):
"""Get all combinations of the inputs, cycling over the shorter list(s)."""
cycles = [cycle(i) for i in iterables]
for _ in zip_longest(*iterables):
yield tuple(next(i, empty_default) for i in cycles)
def handle_c_ext(c_ext, expansions):
"""Handle c extension option."""
if c_ext == C_EXTS[0]:
expansions["NO_EXT"] = "1"
def generate_yaml(tasks=None, variants=None):
"""Generate the yaml for a given set of tasks and variants."""
project = EvgProject(tasks=tasks, buildvariants=variants)
out = ShrubService.generate_yaml(project)
# Dedent by two spaces to match what we use in config.yml
lines = [line[2:] for line in out.splitlines()]
print("\n".join(lines)) # noqa: T201
##############
# Variants
##############
def create_ocsp_variants() -> list[BuildVariant]:
variants = []
batchtime = BATCHTIME_WEEK
expansions = dict(AUTH="noauth", SSL="ssl", TOPOLOGY="server")
base_display = "OCSP"
# OCSP tests on default host with all servers v4.4+ and all python versions.
versions = get_versions_from("4.4")
for version, python in zip_cycle(versions, ALL_PYTHONS):
host = DEFAULT_HOST
variant = create_variant(
[".ocsp"],
get_display_name(base_display, host, version=version, python=python),
python=python,
version=version,
host=host,
expansions=expansions,
batchtime=batchtime,
)
variants.append(variant)
# OCSP tests on Windows and MacOS.
# MongoDB servers on these hosts do not staple OCSP responses and only support RSA.
for host_name, version in product(["win64", "macos"], ["4.4", "8.0"]):
host = HOSTS[host_name]
python = CPYTHONS[0] if version == "4.4" else CPYTHONS[-1]
variant = create_variant(
[".ocsp-rsa !.ocsp-staple"],
get_display_name(base_display, host, version=version, python=python),
python=python,
version=version,
host=host,
expansions=expansions,
batchtime=batchtime,
)
variants.append(variant)
return variants
def create_server_variants() -> list[BuildVariant]:
variants = []
# Run the full matrix on linux with min and max CPython, and latest pypy.
host = DEFAULT_HOST
# Prefix the display name with an asterisk so it is sorted first.
base_display_name = "* Test"
for python, c_ext in product([*MIN_MAX_PYTHON, PYPYS[-1]], C_EXTS):
expansions = dict(COVERAGE="coverage")
handle_c_ext(c_ext, expansions)
display_name = get_display_name(base_display_name, host, python=python, **expansions)
variant = create_variant(
[f".{t} .sync_async" for t in TOPOLOGIES],
display_name,
python=python,
host=host,
tags=["coverage_tag"],
expansions=expansions,
)
variants.append(variant)
# Test the rest of the pythons.
for python in CPYTHONS[1:-1] + PYPYS[:-1]:
display_name = f"Test {host}"
display_name = get_display_name(base_display_name, host, python=python)
variant = create_variant(
[f"{t} .sync_async" for t in SUB_TASKS],
display_name,
python=python,
host=host,
expansions=expansions,
)
variants.append(variant)
# Test a subset on each of the other platforms.
for host_name in ("macos", "macos-arm64", "win64", "win32"):
for python in MIN_MAX_PYTHON:
tasks = [f"{t} !.sync_async" for t in SUB_TASKS]
# MacOS arm64 only works on server versions 6.0+
if host_name == "macos-arm64":
tasks = []
for version in get_versions_from("6.0"):
tasks.extend(f"{t} .{version} !.sync_async" for t in SUB_TASKS)
host = HOSTS[host_name]
display_name = get_display_name(base_display_name, host, python=python)
variant = create_variant(tasks, display_name, python=python, host=host)
variants.append(variant)
return variants
def create_free_threaded_variants() -> list[BuildVariant]:
variants = []
for host_name in ("rhel8", "macos", "macos-arm64", "win64"):
if host_name == "win64":
# TODO: PYTHON-5027
continue
tasks = [".free-threading"]
host = HOSTS[host_name]
python = "3.13t"
display_name = get_display_name("Free-threaded", host, python=python)
variant = create_variant(tasks, display_name, python=python, host=host)
variants.append(variant)
return variants
def create_encryption_variants() -> list[BuildVariant]:
variants = []
tags = ["encryption_tag"]
batchtime = BATCHTIME_WEEK
def get_encryption_expansions(encryption):
expansions = dict(TEST_NAME="encryption")
if "crypt_shared" in encryption:
expansions["TEST_CRYPT_SHARED"] = "true"
if "PyOpenSSL" in encryption:
expansions["SUB_TEST_NAME"] = "pyopenssl"
return expansions
host = DEFAULT_HOST
# Test against all server versions for the three main python versions.
encryptions = ["Encryption", "Encryption crypt_shared", "Encryption PyOpenSSL"]
for encryption, python in product(encryptions, [*MIN_MAX_PYTHON, PYPYS[-1]]):
expansions = get_encryption_expansions(encryption)
display_name = get_display_name(encryption, host, python=python, **expansions)
variant = create_variant(
[f"{t} .sync_async" for t in SUB_TASKS],
display_name,
python=python,
host=host,
expansions=expansions,
batchtime=batchtime,
tags=tags,
)
variants.append(variant)
# Test the rest of the pythons on linux for all server versions.
for encryption, python, task in zip_cycle(encryptions, CPYTHONS[1:-1] + PYPYS[:-1], SUB_TASKS):
expansions = get_encryption_expansions(encryption)
display_name = get_display_name(encryption, host, python=python, **expansions)
variant = create_variant(
[f"{task} .sync_async"],
display_name,
python=python,
host=host,
expansions=expansions,
)
variants.append(variant)
# Test on macos and linux on one server version and topology for min and max python.
encryptions = ["Encryption", "Encryption crypt_shared"]
task_names = [".latest .replica_set .sync_async"]
for host_name, encryption, python in product(["macos", "win64"], encryptions, MIN_MAX_PYTHON):
host = HOSTS[host_name]
expansions = get_encryption_expansions(encryption)
display_name = get_display_name(encryption, host, python=python, **expansions)
variant = create_variant(
task_names,
display_name,
python=python,
host=host,
expansions=expansions,
batchtime=batchtime,
tags=tags,
)
variants.append(variant)
return variants
def create_load_balancer_variants():
# Load balancer tests - run all supported server versions using the lowest supported python.
host = DEFAULT_HOST
batchtime = BATCHTIME_WEEK
versions = get_versions_from("6.0")
variants = []
for version in versions:
python = CPYTHONS[0]
display_name = get_display_name("Load Balancer", host, python=python, version=version)
variant = create_variant(
[".load-balancer"],
display_name,
python=python,
host=host,
version=version,
batchtime=batchtime,
)
variants.append(variant)
return variants
def create_compression_variants():
# Compression tests - standalone versions of each server, across python versions, with and without c extensions.
# PyPy interpreters are always tested without extensions.
host = DEFAULT_HOST
base_task = ".standalone .noauth .nossl .sync_async"
task_names = dict(snappy=[base_task], zlib=[base_task], zstd=[f"{base_task} !.4.0"])
variants = []
for ind, (compressor, c_ext) in enumerate(product(["snappy", "zlib", "zstd"], C_EXTS)):
expansions = dict(COMPRESSORS=compressor)
handle_c_ext(c_ext, expansions)
base_name = f"Compression {compressor}"
python = CPYTHONS[ind % len(CPYTHONS)]
display_name = get_display_name(base_name, host, python=python, **expansions)
variant = create_variant(
task_names[compressor],
display_name,
python=python,
host=host,
expansions=expansions,
)
variants.append(variant)
other_pythons = PYPYS + CPYTHONS[ind:]
for compressor, python in zip_cycle(["snappy", "zlib", "zstd"], other_pythons):
expansions = dict(COMPRESSORS=compressor)
handle_c_ext(c_ext, expansions)
base_name = f"Compression {compressor}"
display_name = get_display_name(base_name, host, python=python, **expansions)
variant = create_variant(
task_names[compressor],
display_name,
python=python,
host=host,
expansions=expansions,
)
variants.append(variant)
return variants
def create_enterprise_auth_variants():
expansions = dict(AUTH="auth")
variants = []
# All python versions across platforms.
for python in ALL_PYTHONS:
if python == CPYTHONS[0]:
host = HOSTS["macos"]
elif python == CPYTHONS[-1]:
host = HOSTS["win64"]
else:
host = DEFAULT_HOST
display_name = get_display_name("Auth Enterprise", host, python=python, **expansions)
variant = create_variant(
["test-enterprise-auth"], display_name, host=host, python=python, expansions=expansions
)
variants.append(variant)
return variants
def create_pyopenssl_variants():
base_name = "PyOpenSSL"
batchtime = BATCHTIME_WEEK
expansions = dict(TEST_NAME="pyopenssl")
variants = []
for python in ALL_PYTHONS:
# Only test "noauth" with min python.
auth = "noauth" if python == CPYTHONS[0] else "auth"
ssl = "nossl" if auth == "noauth" else "ssl"
if python == CPYTHONS[0]:
host = HOSTS["macos"]
elif python == CPYTHONS[-1]:
host = HOSTS["win64"]
else:
host = DEFAULT_HOST
display_name = get_display_name(base_name, host, python=python)
variant = create_variant(
[f".replica_set .{auth} .{ssl} .sync_async", f".7.0 .{auth} .{ssl} .sync_async"],
display_name,
python=python,
host=host,
expansions=expansions,
batchtime=batchtime,
)
variants.append(variant)
return variants
def create_storage_engine_variants():
host = DEFAULT_HOST
engines = ["InMemory", "MMAPv1"]
variants = []
for engine in engines:
python = CPYTHONS[0]
expansions = dict(STORAGE_ENGINE=engine.lower())
if engine == engines[0]:
tasks = [f".standalone .noauth .nossl .{v} .sync_async" for v in ALL_VERSIONS]
else:
# MongoDB 4.2 drops support for MMAPv1
versions = get_versions_until("4.0")
tasks = [f".standalone .{v} .noauth .nossl .sync_async" for v in versions] + [
f".replica_set .{v} .noauth .nossl .sync_async" for v in versions
]
display_name = get_display_name(f"Storage {engine}", host, python=python)
variant = create_variant(
tasks, display_name, host=host, python=python, expansions=expansions
)
variants.append(variant)
return variants
def create_stable_api_variants():
host = DEFAULT_HOST
tags = ["versionedApi_tag"]
tasks = [f".standalone .{v} .noauth .nossl .sync_async" for v in get_versions_from("5.0")]
variants = []
types = ["require v1", "accept v2"]
# All python versions across platforms.
for python, test_type in product(MIN_MAX_PYTHON, types):
expansions = dict(AUTH="auth")
# Test against a cluster with requireApiVersion=1.
if test_type == types[0]:
# REQUIRE_API_VERSION is set to make drivers-evergreen-tools
# start a cluster with the requireApiVersion parameter.
expansions["REQUIRE_API_VERSION"] = "1"
# MONGODB_API_VERSION is the apiVersion to use in the test suite.
expansions["MONGODB_API_VERSION"] = "1"
else:
# Test against a cluster with acceptApiVersion2 but without
# requireApiVersion, and don't automatically add apiVersion to
# clients created in the test suite.
expansions["ORCHESTRATION_FILE"] = "versioned-api-testing.json"
base_display_name = f"Stable API {test_type}"
display_name = get_display_name(base_display_name, host, python=python, **expansions)
variant = create_variant(
tasks, display_name, host=host, python=python, tags=tags, expansions=expansions
)
variants.append(variant)
return variants
def create_green_framework_variants():
variants = []
tasks = [".standalone .noauth .nossl .sync_async"]
host = DEFAULT_HOST
for python, framework in product([CPYTHONS[0], CPYTHONS[-1]], ["eventlet", "gevent"]):
expansions = dict(GREEN_FRAMEWORK=framework, AUTH="auth", SSL="ssl")
display_name = get_display_name(f"Green {framework.capitalize()}", host, python=python)
variant = create_variant(
tasks, display_name, host=host, python=python, expansions=expansions
)
variants.append(variant)
return variants
def create_no_c_ext_variants():
variants = []
host = DEFAULT_HOST
for python, topology in zip_cycle(CPYTHONS, TOPOLOGIES):
tasks = [f".{topology} .noauth .nossl !.sync_async"]
expansions = dict()
handle_c_ext(C_EXTS[0], expansions)
display_name = get_display_name("No C Ext", host, python=python)
variant = create_variant(
tasks, display_name, host=host, python=python, expansions=expansions
)
variants.append(variant)
return variants
def create_atlas_data_lake_variants():
variants = []
host = HOSTS["ubuntu22"]
for python, c_ext in product(MIN_MAX_PYTHON, C_EXTS):
tasks = ["atlas-data-lake-tests"]
expansions = dict(AUTH="auth")
handle_c_ext(c_ext, expansions)
display_name = get_display_name("Atlas Data Lake", host, python=python, **expansions)
variant = create_variant(
tasks, display_name, host=host, python=python, expansions=expansions
)
variants.append(variant)
return variants
def create_mod_wsgi_variants():
variants = []
host = HOSTS["ubuntu22"]
tasks = [
"mod-wsgi-standalone",
"mod-wsgi-replica-set",
"mod-wsgi-embedded-mode-standalone",
"mod-wsgi-embedded-mode-replica-set",
]
expansions = dict(MOD_WSGI_VERSION="4")
for python in MIN_MAX_PYTHON:
display_name = get_display_name("mod_wsgi", host, python=python)
variant = create_variant(
tasks, display_name, host=host, python=python, expansions=expansions
)
variants.append(variant)
return variants
def create_disable_test_commands_variants():
host = DEFAULT_HOST
expansions = dict(AUTH="auth", SSL="ssl", DISABLE_TEST_COMMANDS="1")
python = CPYTHONS[0]
display_name = get_display_name("Disable test commands", host, python=python)
tasks = [".latest .sync_async"]
return [create_variant(tasks, display_name, host=host, python=python, expansions=expansions)]
def create_serverless_variants():
host = DEFAULT_HOST
batchtime = BATCHTIME_WEEK
expansions = dict(TEST_NAME="serverless", AUTH="auth", SSL="ssl")
tasks = ["serverless_task_group"]
base_name = "Serverless"
return [
create_variant(
tasks,
get_display_name(base_name, host, python=python),
host=host,
python=python,
expansions=expansions,
batchtime=batchtime,
)
for python in MIN_MAX_PYTHON
]
def create_oidc_auth_variants():
variants = []
other_tasks = ["testazureoidc_task_group", "testgcpoidc_task_group", "testk8soidc_task_group"]
for host_name in ["ubuntu22", "macos", "win64"]:
tasks = ["testoidc_task_group"]
if host_name == "ubuntu22":
tasks += other_tasks
host = HOSTS[host_name]
variants.append(
create_variant(
tasks,
get_display_name("Auth OIDC", host),
host=host,
batchtime=BATCHTIME_WEEK,
)
)
return variants
def create_search_index_variants():
host = DEFAULT_HOST
python = CPYTHONS[0]
return [
create_variant(
["test_atlas_task_group_search_indexes"],
get_display_name("Search Index Helpers", host, python=python),
python=python,
host=host,
)
]
def create_mockupdb_variants():
host = DEFAULT_HOST
python = CPYTHONS[0]
return [
create_variant(
["mockupdb"],
get_display_name("MockupDB", host, python=python),
python=python,
host=host,
)
]
def create_doctests_variants():
host = DEFAULT_HOST
python = CPYTHONS[0]
return [
create_variant(
["doctests"],
get_display_name("Doctests", host, python=python),
python=python,
host=host,
)
]
def create_atlas_connect_variants():
host = DEFAULT_HOST
return [
create_variant(
["atlas-connect"],
get_display_name("Atlas connect", host, python=python),
python=python,
host=host,
)
for python in MIN_MAX_PYTHON
]
def create_aws_auth_variants():
variants = []
for host_name, python in product(["ubuntu20", "win64", "macos"], MIN_MAX_PYTHON):
expansions = dict()
tasks = [".auth-aws"]
if host_name == "macos":
tasks = [".auth-aws !.auth-aws-web-identity !.auth-aws-ecs !.auth-aws-ec2"]
elif host_name == "win64":
tasks = [".auth-aws !.auth-aws-ecs"]
host = HOSTS[host_name]
variant = create_variant(
tasks,
get_display_name("Auth AWS", host, python=python),
host=host,
python=python,
expansions=expansions,
)
variants.append(variant)
return variants
def create_alternative_hosts_variants():
batchtime = BATCHTIME_WEEK
variants = []
host = HOSTS["rhel7"]
variants.append(
create_variant(
[".5.0 .standalone !.sync_async"],
get_display_name("OpenSSL 1.0.2", host, python=CPYTHONS[0]),
host=host,
python=CPYTHONS[0],
batchtime=batchtime,
)
)
expansions = dict()
handle_c_ext(C_EXTS[0], expansions)
for host_name in OTHER_HOSTS:
host = HOSTS[host_name]
variants.append(
create_variant(
[".6.0 .standalone !.sync_async"],
display_name=get_display_name("Other hosts", host),
batchtime=batchtime,
host=host,
expansions=expansions,
)
)
return variants
##############
# Tasks
##############
def create_server_tasks():
tasks = []
for topo, version, (auth, ssl), sync in product(TOPOLOGIES, ALL_VERSIONS, AUTH_SSLS, SYNCS):
name = f"test-{version}-{topo}-{auth}-{ssl}-{sync}".lower()
tags = [version, topo, auth, ssl, sync]
server_vars = dict(
VERSION=version,
TOPOLOGY=topo if topo != "standalone" else "server",
AUTH=auth,
SSL=ssl,
)
server_func = FunctionCall(func="run server", vars=server_vars)
test_vars = dict(AUTH=auth, SSL=ssl, SYNC=sync)
if sync == "sync":
test_vars["TEST_NAME"] = "default_sync"
elif sync == "async":
test_vars["TEST_NAME"] = "default_async"
test_func = FunctionCall(func="run tests", vars=test_vars)
tasks.append(EvgTask(name=name, tags=tags, commands=[server_func, test_func]))
return tasks
def create_load_balancer_tasks():
tasks = []
for auth, ssl in AUTH_SSLS:
name = f"test-load-balancer-{auth}-{ssl}".lower()
tags = ["load-balancer", auth, ssl]
server_vars = dict(
TOPOLOGY="sharded_cluster", AUTH=auth, SSL=ssl, TEST_NAME="load_balancer"
)
server_func = FunctionCall(func="run server", vars=server_vars)
test_vars = dict(AUTH=auth, SSL=ssl, TEST_NAME="load_balancer")
test_func = FunctionCall(func="run tests", vars=test_vars)
tasks.append(EvgTask(name=name, tags=tags, commands=[server_func, test_func]))
return tasks
def create_kms_tasks():
tasks = []
for kms_type in ["gcp", "azure"]:
for success in [True, False]:
name = f"test-{kms_type}kms"
sub_test_name = kms_type
if not success:
name += "-fail"
sub_test_name += "-fail"
commands = []
if not success:
commands.append(FunctionCall(func="run server"))
test_vars = dict(TEST_NAME="kms", SUB_TEST_NAME=sub_test_name)
test_func = FunctionCall(func="run tests", vars=test_vars)
commands.append(test_func)
tasks.append(EvgTask(name=name, commands=commands))
return tasks
def create_aws_tasks():
tasks = []
aws_test_types = [
"regular",
"assume-role",
"ec2",
"env-creds",
"session-creds",
"web-identity",
"ecs",
]
for version in get_versions_from("4.4"):
base_name = f"test-auth-aws-{version}"
base_tags = ["auth-aws"]
server_vars = dict(AUTH_AWS="1", VERSION=version)
server_func = FunctionCall(func="run server", vars=server_vars)
assume_func = FunctionCall(func="assume ec2 role")
for test_type in aws_test_types:
tags = [*base_tags, f"auth-aws-{test_type}"]
name = f"{base_name}-{test_type}"
test_vars = dict(TEST_NAME="auth_aws", SUB_TEST_NAME=test_type)
test_func = FunctionCall(func="run tests", vars=test_vars)
funcs = [server_func, assume_func, test_func]
tasks.append(EvgTask(name=name, tags=tags, commands=funcs))
tags = [*base_tags, "auth-aws-web-identity"]
name = f"{base_name}-web-identity-session-name"
test_vars = dict(
TEST_NAME="auth_aws", SUB_TEST_NAME="web-identity", AWS_ROLE_SESSION_NAME="test"
)
test_func = FunctionCall(func="run tests", vars=test_vars)
funcs = [server_func, assume_func, test_func]
tasks.append(EvgTask(name=name, tags=tags, commands=funcs))
return tasks
def _create_ocsp_task(algo, variant, server_type, base_task_name):
file_name = f"{algo}-basic-tls-ocsp-{variant}.json"
vars = dict(TEST_NAME="ocsp", ORCHESTRATION_FILE=file_name)
server_func = FunctionCall(func="run server", vars=vars)
vars = dict(ORCHESTRATION_FILE=file_name, OCSP_SERVER_TYPE=server_type, TEST_NAME="ocsp")
test_func = FunctionCall(func="run tests", vars=vars)
tags = ["ocsp", f"ocsp-{algo}"]
if "disableStapling" not in variant:
tags.append("ocsp-staple")
task_name = f"test-ocsp-{algo}-{base_task_name}"
commands = [server_func, test_func]
return EvgTask(name=task_name, tags=tags, commands=commands)
def create_ocsp_tasks():
tasks = []
tests = [
("disableStapling", "valid", "valid-cert-server-does-not-staple"),
("disableStapling", "revoked", "invalid-cert-server-does-not-staple"),
("disableStapling", "valid-delegate", "delegate-valid-cert-server-does-not-staple"),
("disableStapling", "revoked-delegate", "delegate-invalid-cert-server-does-not-staple"),
("disableStapling", "no-responder", "soft-fail"),
("mustStaple", "valid", "valid-cert-server-staples"),
("mustStaple", "revoked", "invalid-cert-server-staples"),
("mustStaple", "valid-delegate", "delegate-valid-cert-server-staples"),
("mustStaple", "revoked-delegate", "delegate-invalid-cert-server-staples"),
(
"mustStaple-disableStapling",
"revoked",
"malicious-invalid-cert-mustStaple-server-does-not-staple",
),
(
"mustStaple-disableStapling",
"revoked-delegate",
"delegate-malicious-invalid-cert-mustStaple-server-does-not-staple",
),
(
"mustStaple-disableStapling",
"no-responder",
"malicious-no-responder-mustStaple-server-does-not-staple",
),
]
for algo in ["ecdsa", "rsa"]:
for variant, server_type, base_task_name in tests:
task = _create_ocsp_task(algo, variant, server_type, base_task_name)
tasks.append(task)
return tasks
##################
# Generate Config
##################
def write_variants_to_file():
mod = sys.modules[__name__]
here = Path(__file__).absolute().parent
target = here.parent / "generated_configs" / "variants.yml"
if target.exists():
target.unlink()
with target.open("w") as fid:
fid.write("buildvariants:\n")
for name, func in getmembers(mod, isfunction):
if not name.endswith("_variants"):
continue
if not name.startswith("create_"):
raise ValueError("Variant creators must start with create_")
title = name.replace("create_", "").replace("_variants", "").replace("_", " ").capitalize()
project = EvgProject(tasks=None, buildvariants=func())
out = ShrubService.generate_yaml(project).splitlines()
with target.open("a") as fid:
fid.write(f" # {title} tests\n")
for line in out[1:]:
fid.write(f"{line}\n")
fid.write("\n")
# Remove extra trailing newline:
data = target.read_text().splitlines()
with target.open("w") as fid:
for line in data[:-1]:
fid.write(f"{line}\n")
def write_tasks_to_file():
mod = sys.modules[__name__]
here = Path(__file__).absolute().parent
target = here.parent / "generated_configs" / "tasks.yml"
if target.exists():
target.unlink()
with target.open("w") as fid:
fid.write("tasks:\n")
for name, func in getmembers(mod, isfunction):
if not name.endswith("_tasks"):
continue
if not name.startswith("create_"):
raise ValueError("Task creators must start with create_")
title = name.replace("create_", "").replace("_tasks", "").replace("_", " ").capitalize()
project = EvgProject(tasks=func(), buildvariants=None)
out = ShrubService.generate_yaml(project).splitlines()
with target.open("a") as fid:
fid.write(f" # {title} tests\n")
for line in out[1:]:
fid.write(f"{line}\n")
fid.write("\n")
# Remove extra trailing newline:
data = target.read_text().splitlines()