@@ -98,7 +98,7 @@ async def no_auth_consul_proxy(launch_consul):
98
98
99
99
100
100
@pytest .fixture
101
- async def auth_consul_proxy (launch_consul_acl ):
101
+ async def auth_consul_proxy (launch_consul_auth ):
102
102
"""
103
103
Fixture returning a configured TraefikConsulProxy.
104
104
Consul acl enabled.
@@ -130,7 +130,7 @@ async def no_auth_etcd_proxy(launch_etcd):
130
130
131
131
132
132
@pytest .fixture
133
- async def auth_etcd_proxy (enable_auth_in_etcd ):
133
+ async def auth_etcd_proxy (launch_etcd_auth ):
134
134
"""
135
135
Fixture returning a configured TraefikEtcdProxy
136
136
Etcd has credentials set up
@@ -142,10 +142,6 @@ async def auth_etcd_proxy(enable_auth_in_etcd):
142
142
143
143
144
144
def _make_etcd_proxy (auth = False , ** extra_kwargs ):
145
- grpc_options = [
146
- ("grpc.ssl_target_name_override" , "localhost" ),
147
- ("grpc.default_authority" , "localhost" ),
148
- ]
149
145
kwargs = dict (
150
146
public_url = Config .public_url ,
151
147
traefik_api_password = Config .traefik_api_pass ,
@@ -155,7 +151,10 @@ def _make_etcd_proxy(auth=False, **extra_kwargs):
155
151
if auth :
156
152
kwargs .update (
157
153
dict (
158
- grpc_options = grpc_options ,
154
+ grpc_options = [
155
+ ("grpc.ssl_target_name_override" , "localhost" ),
156
+ ("grpc.default_authority" , "localhost" ),
157
+ ],
159
158
etcd_url = "https://localhost:2379" ,
160
159
etcd_client_ca_cert = f"{ config_files } /fake-ca-cert.crt" ,
161
160
etcd_insecure_skip_verify = True ,
@@ -234,7 +233,7 @@ async def external_file_proxy_toml(launch_traefik_file):
234
233
235
234
236
235
@pytest .fixture
237
- async def external_consul_proxy (launch_consul , configure_consul , launch_traefik_consul ):
236
+ async def external_consul_proxy (launch_traefik_consul ):
238
237
proxy = TraefikConsulProxy (
239
238
public_url = Config .public_url ,
240
239
consul_url = f"http://127.0.0.1:{ Config .consul_port } " ,
@@ -248,9 +247,7 @@ async def external_consul_proxy(launch_consul, configure_consul, launch_traefik_
248
247
249
248
250
249
@pytest .fixture
251
- async def auth_external_consul_proxy (
252
- launch_consul_acl , configure_consul_auth , launch_traefik_consul_auth
253
- ):
250
+ async def auth_external_consul_proxy (launch_traefik_consul_auth ):
254
251
proxy = TraefikConsulProxy (
255
252
public_url = Config .public_url ,
256
253
consul_url = f"http://127.0.0.1:{ Config .consul_auth_port } " ,
@@ -298,15 +295,15 @@ def launch_traefik_file():
298
295
299
296
300
297
@pytest .fixture
301
- def launch_traefik_etcd (launch_etcd , configure_etcd ):
298
+ def launch_traefik_etcd (launch_etcd ):
302
299
env = Config .etcdctl_env
303
300
proc = _launch_traefik_cli ("--providers.etcd" , env = env )
304
301
yield proc
305
302
shutdown_traefik (proc )
306
303
307
304
308
305
@pytest .fixture
309
- def launch_traefik_etcd_auth (launch_etcd_auth , configure_etcd_auth ):
306
+ def launch_traefik_etcd_auth (launch_etcd_auth ):
310
307
extra_args = (
311
308
"--providers.etcd.tls.insecureSkipVerify=true" ,
312
309
"--providers.etcd.tls.ca=" + f"{ config_files } /fake-ca-cert.crt" ,
@@ -319,14 +316,14 @@ def launch_traefik_etcd_auth(launch_etcd_auth, configure_etcd_auth):
319
316
320
317
321
318
@pytest .fixture
322
- def launch_traefik_consul ():
319
+ def launch_traefik_consul (launch_consul ):
323
320
proc = _launch_traefik_cli ("--providers.consul" )
324
321
yield proc
325
322
shutdown_traefik (proc )
326
323
327
324
328
325
@pytest .fixture
329
- def launch_traefik_consul_auth ():
326
+ def launch_traefik_consul_auth (launch_consul_auth ):
330
327
extra_args = (
331
328
f"--providers.consul.endpoints=http://127.0.0.1:{ Config .consul_auth_port } " ,
332
329
)
@@ -364,22 +361,6 @@ def _launch_traefik(*extra_args, env=None):
364
361
##################################
365
362
366
363
367
- @pytest .fixture
368
- def configure_etcd (launch_etcd ):
369
- """Load traefik api rules into the etcd kv store"""
370
- yield _config_etcd ()
371
-
372
-
373
- @pytest .fixture
374
- def configure_etcd_auth (launch_etcd_auth , enable_auth_in_etcd ):
375
- """Load traefik api rules into the etcd kv store, with authentication"""
376
- yield _config_etcd (
377
- "--user=" + Config .etcd_user + ":" + Config .etcd_password ,
378
- "--insecure-skip-tls-verify=true" ,
379
- "--insecure-transport=false" ,
380
- )
381
-
382
-
383
364
def _config_etcd (* extra_args ):
384
365
data_store_cmd = ("etcdctl" , "txn" , "--debug" ) + extra_args
385
366
# Load a pre-baked dynamic configuration into the etcd store.
@@ -397,15 +378,10 @@ def _config_etcd(*extra_args):
397
378
), f"{ data_store_cmd } exited with status { proc .returncode } "
398
379
399
380
400
- @ pytest . fixture
401
- def enable_auth_in_etcd ( launch_etcd_auth ):
381
+ def _enable_auth_in_etcd ( * common_args ):
382
+ common_args = list ( common_args )
402
383
user = Config .etcd_user
403
384
pw = Config .etcd_password
404
- common_args = [
405
- "--insecure-skip-tls-verify=true" ,
406
- "--insecure-transport=false" ,
407
- "--debug" ,
408
- ]
409
385
subprocess .check_call (
410
386
["etcdctl" , "user" , "add" , f"{ user } :{ pw } " ] + common_args , env = Config .etcdctl_env
411
387
)
@@ -421,24 +397,6 @@ def enable_auth_in_etcd(launch_etcd_auth):
421
397
.strip ()
422
398
== "Authentication Enabled"
423
399
)
424
- yield
425
-
426
- assert (
427
- subprocess .check_output (
428
- ["etcdctl" , "--user" , f"{ user } :{ pw } " , "auth" , "disable" ] + common_args ,
429
- env = Config .etcdctl_env ,
430
- )
431
- .decode (sys .stdout .encoding )
432
- .strip ()
433
- == "Authentication Disabled"
434
- )
435
- subprocess .call (
436
- ["etcdctl" , "user" , "revoke-role" , "root" , user ] + common_args ,
437
- env = Config .etcdctl_env ,
438
- )
439
- subprocess .call (
440
- ["etcdctl" , "user" , "delete" , user ] + common_args , env = Config .etcdctl_env
441
- )
442
400
443
401
444
402
@pytest .fixture
@@ -458,14 +416,17 @@ async def launch_etcd_auth():
458
416
"--log-level=debug" ,
459
417
],
460
418
)
419
+ etcdctl_args = [
420
+ "--user" ,
421
+ f"{ Config .etcd_user } :{ Config .etcd_password } " ,
422
+ "--insecure-skip-tls-verify=true" ,
423
+ "--insecure-transport=false" ,
424
+ "--debug" ,
425
+ ]
461
426
try :
462
- await _wait_for_etcd (
463
- "--user" ,
464
- f"{ Config .etcd_user } :{ Config .etcd_password } " ,
465
- "--insecure-skip-tls-verify=true" ,
466
- "--insecure-transport=false" ,
467
- "--debug" ,
468
- )
427
+ await _wait_for_etcd (* etcdctl_args )
428
+ _enable_auth_in_etcd (* etcdctl_args )
429
+ _config_etcd (* etcdctl_args )
469
430
yield etcd_proc
470
431
finally :
471
432
shutdown_etcd (etcd_proc )
@@ -480,6 +441,7 @@ async def launch_etcd():
480
441
)
481
442
try :
482
443
await _wait_for_etcd ("--debug=true" )
444
+ _config_etcd ()
483
445
yield etcd_proc
484
446
finally :
485
447
shutdown_etcd (etcd_proc )
@@ -509,13 +471,6 @@ def check():
509
471
await exponential_backoff (check , "etcd health check" , timeout = 10 )
510
472
511
473
512
- # @pytest.fixture(scope="function", autouse=True)
513
- # Is this referenced anywhere??
514
- # @pytest.fixture
515
- def clean_etcd ():
516
- subprocess .run (["etcdctl" , "del" , '""' , "--from-key=true" ], env = Config .etcdctl_env )
517
-
518
-
519
474
# Consul Launchers and configurers #
520
475
####################################
521
476
@@ -533,15 +488,18 @@ def launch_consul():
533
488
],
534
489
cwd = consul_path ,
535
490
)
536
- asyncio .run (
537
- _wait_for_consul (token = Config .consul_token , port = Config .consul_port )
538
- )
539
- yield consul_proc
540
- shutdown_consul (consul_proc )
491
+ try :
492
+ asyncio .run (
493
+ _wait_for_consul (token = Config .consul_token , port = Config .consul_port )
494
+ )
495
+ _config_consul ()
496
+ yield consul_proc
497
+ finally :
498
+ shutdown_consul (consul_proc )
541
499
542
500
543
501
@pytest .fixture (scope = "module" )
544
- def launch_consul_acl ():
502
+ def launch_consul_auth ():
545
503
with TemporaryDirectory () as consul_path :
546
504
consul_proc = subprocess .Popen (
547
505
[
@@ -563,13 +521,21 @@ def launch_consul_acl():
563
521
],
564
522
cwd = consul_path ,
565
523
)
566
- asyncio .run (
567
- _wait_for_consul (token = Config .consul_token , port = Config .consul_auth_port )
568
- )
569
- yield consul_proc
570
- shutdown_consul (
571
- consul_proc , secret = Config .consul_token , port = Config .consul_auth_port
572
- )
524
+ try :
525
+ # asyncio.run instead of await because this fixture's scope
526
+ # is module-scoped, while event_loop is 'function'-scoped
527
+ asyncio .run (
528
+ _wait_for_consul (
529
+ token = Config .consul_token , port = Config .consul_auth_port
530
+ )
531
+ )
532
+
533
+ _config_consul (secret = Config .consul_token , port = Config .consul_auth_port )
534
+ yield consul_proc
535
+ finally :
536
+ shutdown_consul (
537
+ consul_proc , secret = Config .consul_token , port = Config .consul_auth_port
538
+ )
573
539
574
540
575
541
async def _wait_for_consul (token = None , ** kwargs ):
@@ -598,18 +564,6 @@ async def _check_consul():
598
564
)
599
565
600
566
601
- @pytest .fixture
602
- def configure_consul ():
603
- """Load an initial config into the consul KV store"""
604
- yield _config_consul ()
605
-
606
-
607
- @pytest .fixture
608
- def configure_consul_auth ():
609
- """Load an initial config into the consul KV store, using authentication"""
610
- yield _config_consul (secret = Config .consul_token , port = Config .consul_auth_port )
611
-
612
-
613
567
def _config_consul (secret = None , port = 8500 ):
614
568
proc_env = None
615
569
if secret is not None :
@@ -651,7 +605,6 @@ def shutdown_consul(consul_proc, secret=None, port=8500):
651
605
652
606
653
607
def shutdown_etcd (etcd_proc ):
654
- clean_etcd ()
655
608
terminate_process (etcd_proc , timeout = 20 )
656
609
657
610
# Remove the default.etcd folder, so no settings left over
0 commit comments