18
18
from pyinfra .api .exceptions import PyinfraError
19
19
from pyinfra .api .operation import OperationMeta , add_op
20
20
from pyinfra .api .operations import run_ops
21
- from pyinfra .api .state import StateOperationMeta
21
+ from pyinfra .api .state import StateOperationMeta , StateStage
22
22
from pyinfra .connectors .util import CommandOutput , OutputLine
23
23
from pyinfra .context import ctx_host , ctx_state
24
24
from pyinfra .operations import files , python , server
@@ -44,6 +44,7 @@ def test_op(self):
44
44
anotherhost = inventory .get_host ("anotherhost" )
45
45
46
46
state = State (inventory , Config ())
47
+ state .current_stage = StateStage .Prepare
47
48
state .add_callback_handler (BaseStateCallback ())
48
49
49
50
# Enable printing on this test to catch any exceptions in the formatting
@@ -122,6 +123,7 @@ def test_file_upload_op(self):
122
123
inventory = make_inventory ()
123
124
124
125
state = State (inventory , Config ())
126
+ state .current_stage = StateStage .Prepare
125
127
connect_all (state )
126
128
127
129
# Test normal
@@ -197,6 +199,7 @@ def test_file_download_op(self):
197
199
inventory = make_inventory ()
198
200
199
201
state = State (inventory , Config ())
202
+ state .current_stage = StateStage .Prepare
200
203
connect_all (state )
201
204
202
205
with patch ("pyinfra.operations.files.os.path.isfile" , lambda * args , ** kwargs : True ):
@@ -236,6 +239,7 @@ def test_file_download_op(self):
236
239
def test_function_call_op (self ):
237
240
inventory = make_inventory ()
238
241
state = State (inventory , Config ())
242
+ state .current_stage = StateStage .Prepare
239
243
connect_all (state )
240
244
241
245
is_called = []
@@ -257,6 +261,7 @@ def mocked_function(*args, **kwargs):
257
261
def test_run_once_serial_op (self ):
258
262
inventory = make_inventory ()
259
263
state = State (inventory , Config ())
264
+ state .current_stage = StateStage .Prepare
260
265
connect_all (state )
261
266
262
267
# Add a run once op
@@ -280,6 +285,7 @@ def test_run_once_serial_op(self):
280
285
def test_rsync_op (self ):
281
286
inventory = make_inventory (hosts = ("somehost" ,))
282
287
state = State (inventory , Config ())
288
+ state .current_stage = StateStage .Prepare
283
289
connect_all (state )
284
290
285
291
add_op (state , files .rsync , "src" , "dest" , _sudo = True , _sudo_user = "root" )
@@ -304,6 +310,7 @@ def test_rsync_op(self):
304
310
def test_rsync_op_with_strict_host_key_checking_disabled (self ):
305
311
inventory = make_inventory (hosts = (("somehost" , {"ssh_strict_host_key_checking" : "no" }),))
306
312
state = State (inventory , Config ())
313
+ state .current_stage = StateStage .Prepare
307
314
connect_all (state )
308
315
309
316
add_op (state , files .rsync , "src" , "dest" , _sudo = True , _sudo_user = "root" )
@@ -338,6 +345,7 @@ def test_rsync_op_with_strict_host_key_checking_disabled_and_custom_config_file(
338
345
)
339
346
)
340
347
state = State (inventory , Config ())
348
+ state .current_stage = StateStage .Prepare
341
349
connect_all (state )
342
350
343
351
add_op (state , files .rsync , "src" , "dest" , _sudo = True , _sudo_user = "root" )
@@ -365,6 +373,7 @@ def test_rsync_op_with_sanitized_custom_config_file(self):
365
373
hosts = (("somehost" , {"ssh_config_file" : "/home/me/ssh_test_config && echo hi" }),)
366
374
)
367
375
state = State (inventory , Config ())
376
+ state .current_stage = StateStage .Prepare
368
377
connect_all (state )
369
378
370
379
add_op (state , files .rsync , "src" , "dest" , _sudo = True , _sudo_user = "root" )
@@ -389,6 +398,7 @@ def test_rsync_op_with_sanitized_custom_config_file(self):
389
398
def test_rsync_op_failure (self ):
390
399
inventory = make_inventory (hosts = ("somehost" ,))
391
400
state = State (inventory , Config ())
401
+ state .current_stage = StateStage .Prepare
392
402
connect_all (state )
393
403
394
404
with patch ("pyinfra.connectors.ssh.which" , lambda x : None ):
@@ -401,6 +411,7 @@ def test_op_cannot_change_execution_kwargs(self):
401
411
inventory = make_inventory ()
402
412
403
413
state = State (inventory , Config ())
414
+ state .current_stage = StateStage .Prepare
404
415
405
416
class NoSetDefaultDict (defaultdict ):
406
417
def setdefault (self , key , _ ):
@@ -422,6 +433,7 @@ class TestNestedOperationsApi(PatchSSHTestCase):
422
433
def test_nested_op_api (self ):
423
434
inventory = make_inventory ()
424
435
state = State (inventory , Config ())
436
+ state .current_stage = StateStage .Prepare
425
437
426
438
connect_all (state )
427
439
@@ -458,6 +470,7 @@ class TestOperationFailures(PatchSSHTestCase):
458
470
def test_full_op_fail (self ):
459
471
inventory = make_inventory ()
460
472
state = State (inventory , Config ())
473
+ state .current_stage = StateStage .Prepare
461
474
connect_all (state )
462
475
463
476
add_op (state , server .shell , 'echo "hi"' )
@@ -484,6 +497,7 @@ def test_full_op_fail(self):
484
497
def test_ignore_errors_op_fail (self ):
485
498
inventory = make_inventory ()
486
499
state = State (inventory , Config ())
500
+ state .current_stage = StateStage .Prepare
487
501
connect_all (state )
488
502
489
503
add_op (state , server .shell , 'echo "hi"' , _ignore_errors = True )
@@ -514,6 +528,7 @@ class TestOperationOrdering(PatchSSHTestCase):
514
528
def test_cli_op_line_numbers (self ):
515
529
inventory = make_inventory ()
516
530
state = State (inventory , Config ())
531
+ state .current_stage = StateStage .Prepare
517
532
connect_all (state )
518
533
519
534
state .current_deploy_filename = __file__
@@ -560,6 +575,7 @@ def test_cli_op_line_numbers(self):
560
575
def test_api_op_line_numbers (self ):
561
576
inventory = make_inventory ()
562
577
state = State (inventory , Config ())
578
+ state .current_stage = StateStage .Prepare
563
579
connect_all (state )
564
580
565
581
another_host = inventory .get_host ("anotherhost" )
@@ -590,6 +606,7 @@ def test_basic_retry_behavior(self, fake_run_command):
590
606
# Create inventory with just one host to simplify testing
591
607
inventory = make_inventory (hosts = ("somehost" ,))
592
608
state = State (inventory , Config ())
609
+ state .current_stage = StateStage .Prepare
593
610
connect_all (state )
594
611
595
612
# Add operation with retry settings
@@ -649,6 +666,7 @@ def test_retry_max_attempts_failure(self, fake_run_command):
649
666
"""
650
667
inventory = make_inventory (hosts = ("somehost" ,))
651
668
state = State (inventory , Config ())
669
+ state .current_stage = StateStage .Prepare
652
670
connect_all (state )
653
671
654
672
# Add operation with retry settings
@@ -698,6 +716,7 @@ def test_retry_until_condition(self, fake_sleep, fake_run_command):
698
716
# Setup inventory and state using the utility function
699
717
inventory = make_inventory (hosts = ("somehost" ,))
700
718
state = State (inventory , Config ())
719
+ state .current_stage = StateStage .Prepare
701
720
connect_all (state )
702
721
703
722
# Create a counter to track retry_until calls
@@ -757,6 +776,7 @@ def test_retry_delay(self, fake_sleep, fake_run_command):
757
776
"""
758
777
inventory = make_inventory (hosts = ("somehost" ,))
759
778
state = State (inventory , Config ())
779
+ state .current_stage = StateStage .Prepare
760
780
connect_all (state )
761
781
762
782
retry_delay = 5
@@ -799,6 +819,7 @@ def test_retry_until_with_error_handling(self, fake_sleep, fake_run_command):
799
819
"""
800
820
inventory = make_inventory (hosts = ("somehost" ,))
801
821
state = State (inventory , Config ())
822
+ state .current_stage = StateStage .Prepare
802
823
connect_all (state )
803
824
804
825
# Create a retry_until function that raises an exception
@@ -842,6 +863,7 @@ def test_retry_until_with_complex_output_parsing(self, fake_sleep, fake_run_comm
842
863
"""
843
864
inventory = make_inventory (hosts = ("somehost" ,))
844
865
state = State (inventory , Config ())
866
+ state .current_stage = StateStage .Prepare
845
867
connect_all (state )
846
868
847
869
# Track what output we've seen
0 commit comments