Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 526fa18

Browse files
authored
Merge pull request #259 from zalando-stups/fix-senza-wait
Fix senza wait for *_IN_PROGRESS
2 parents 21aefc4 + 927791b commit 526fa18

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

senza/cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ def failure_event(event: dict):
14151415
help='Time between checks (default: 5s)')
14161416
@region_option
14171417
@stacktrace_visible_option
1418-
def wait(stack_ref, region, deletion, timeout, interval,):
1418+
def wait(stack_ref, region, deletion, timeout, interval):
14191419
"""
14201420
Wait for successful stack creation or deletion.
14211421
@@ -1426,10 +1426,11 @@ def wait(stack_ref, region, deletion, timeout, interval,):
14261426
region = get_region(region)
14271427
cf = boto3.client('cloudformation', region)
14281428

1429-
cutoff = time.time() + timeout
14301429
target_status = (['DELETE_COMPLETE'] if deletion
14311430
else ['CREATE_COMPLETE', 'UPDATE_COMPLETE'])
14321431

1432+
cutoff = time.time() + timeout
1433+
14331434
while time.time() < cutoff:
14341435
stacks_ok = set()
14351436
stacks_in_progress = set()
@@ -1448,7 +1449,7 @@ def wait(stack_ref, region, deletion, timeout, interval,):
14481449
stacks_ok.add((stack.name, stack.version))
14491450

14501451
elif stack.StackStatus.endswith('_IN_PROGRESS'):
1451-
stacks_in_progress.add(stack.name, stack.version, stack.StackStatus)
1452+
stacks_in_progress.add((stack.name, stack.version, stack.StackStatus))
14521453

14531454
else: # _FAILED or ROLLBACK_COMPLETE or UPDATE_ROLLBACK_COMPLETE
14541455
# output event messages for troubleshooting

tests/test_cli.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,3 +1501,60 @@ def my_client(rtype, *args):
15011501
catch_exceptions=False)
15021502
assert "created" in result.output
15031503
assert "updated" in result.output
1504+
1505+
1506+
def test_wait_in_progress(monkeypatch):
1507+
cf = MagicMock()
1508+
stack1 = {'StackName': 'test-1',
1509+
'CreationTime': datetime.datetime.utcnow(),
1510+
'StackStatus': 'CREATE_IN_PROGRESS'}
1511+
1512+
cf.list_stacks.return_value = {'StackSummaries': [stack1]}
1513+
monkeypatch.setattr('boto3.client', MagicMock(return_value=cf))
1514+
1515+
def my_resource(rtype, *args):
1516+
return MagicMock()
1517+
1518+
monkeypatch.setattr('boto3.resource', my_resource)
1519+
monkeypatch.setattr('time.sleep', MagicMock())
1520+
1521+
runner = CliRunner()
1522+
1523+
data = {'SenzaInfo': {'StackName': 'test'}}
1524+
1525+
with runner.isolated_filesystem():
1526+
result = runner.invoke(cli,
1527+
['wait', 'test', '1', '--region=aa-fakeregion-1', '--timeout=1'],
1528+
catch_exceptions=False)
1529+
assert "Waiting up to 1 more secs for stack test-1 (CREATE_IN_PROGRESS).." in result.output
1530+
assert 'Aborted!' in result.output
1531+
assert 1 == result.exit_code
1532+
1533+
1534+
def test_wait_failure(monkeypatch):
1535+
cf = MagicMock()
1536+
stack1 = {'StackName': 'test-1',
1537+
'CreationTime': datetime.datetime.utcnow(),
1538+
'StackStatus': 'ROLLBACK_COMPLETE'}
1539+
1540+
cf.list_stacks.return_value = {'StackSummaries': [stack1]}
1541+
cf.describe_stack_events.return_value = {'StackEvents': [{'Timestamp': 0, 'ResourceStatus': 'FAIL', 'ResourceStatusReason': 'myreason', 'LogicalResourceId': 'foo'}]}
1542+
monkeypatch.setattr('boto3.client', MagicMock(return_value=cf))
1543+
1544+
def my_resource(rtype, *args):
1545+
return MagicMock()
1546+
1547+
monkeypatch.setattr('boto3.resource', my_resource)
1548+
monkeypatch.setattr('time.sleep', MagicMock())
1549+
1550+
runner = CliRunner()
1551+
1552+
data = {'SenzaInfo': {'StackName': 'test'}}
1553+
1554+
with runner.isolated_filesystem():
1555+
result = runner.invoke(cli,
1556+
['wait', 'test', '1', '--region=aa-fakeregion-1'],
1557+
catch_exceptions=False)
1558+
assert 'ERROR: foo FAIL: myreason' in result.output
1559+
assert 'ERROR: Stack test-1 has status ROLLBACK_COMPLETE' in result.output
1560+
assert 1 == result.exit_code

0 commit comments

Comments
 (0)