Skip to content

Commit

Permalink
#330 truncate default CF description to 1024 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Aug 29, 2016
1 parent 4993fb8 commit 5db53da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions senza/components/configuration.py
Expand Up @@ -3,7 +3,7 @@


def format_params(args):
items = [(key, val) for key, val in args.__dict__.items() if key not in ('region', 'version')]
items = [(key, val) for key, val in sorted(args.__dict__.items()) if key not in ('region', 'version')]
return ', '.join(['{}: {}'.format(key, val) for key, val in items])


Expand All @@ -27,7 +27,9 @@ def component_configuration(definition, configuration, args, info, force, accoun

if 'Description' not in definition:
# set some sane default stack description
definition['Description'] = get_default_description(info, args)
# we need to truncate at 1024 chars (should be Bytes actually)
# see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-description-structure.html
definition['Description'] = get_default_description(info, args)[:1024]

# ServerSubnets
for region, subnets in configuration.get('ServerSubnets', {}).items():
Expand Down
12 changes: 12 additions & 0 deletions tests/test_components.py
Expand Up @@ -6,6 +6,7 @@
import senza.traffic
from senza.cli import AccountArguments
from senza.components import get_component
from senza.components.configuration import component_configuration
from senza.components.auto_scaling_group import (component_auto_scaling_group,
normalize_asg_success,
normalize_network_threshold,
Expand Down Expand Up @@ -923,3 +924,14 @@ def my_client(rtype, *args):
assert result['Resources']['MyLBListener']['Properties']['Certificates'] == [{'CertificateArn': 'arn:aws:42'}]
# test that our custom drain setting works
assert result['Resources']['MyLBTargetGroup']['Properties']['TargetGroupAttributes'] == [{'Key': 'deregistration_delay.timeout_seconds', 'Value': '123'}]


def test_max_description_length():
definition = {}
configuration = {}
args = MagicMock()
args.__dict__ = {'Param1': 'my param value', 'SecondParam': ('1234567890' * 100)}
info = {'StackName': 'My-Stack'}
component_configuration(definition, configuration, args, info, False, AccountArguments('dummyregion'))
assert definition['Description'].startswith('My Stack (Param1: my param value, SecondParam: 1234567890')
assert 0 < len(definition['Description']) <= 1024

0 comments on commit 5db53da

Please sign in to comment.