Repository: zalando-stups/senza

Issue:
Shrink "description" field to allowed 1024 chars
This seems to pop up more and more, I see no real reason why senza should not just do

description[:1024]

to fix this for everyone.

Discussion:

Patch:
diff --git a/senza/components/configuration.py b/senza/components/configuration.py
index e83b419..6712f03 100644
--- a/senza/components/configuration.py
+++ b/senza/components/configuration.py
@@ -3,7 +3,7 @@ from senza.utils import ensure_keys, named_value
 
 
 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])
 
 
@@ -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():


Test patch:
diff --git a/tests/test_components.py b/tests/test_components.py
index fdc377d..652ccfc 100644
--- a/tests/test_components.py
+++ b/tests/test_components.py
@@ -6,6 +6,7 @@ import pytest
 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,
@@ -923,3 +924,14 @@ def test_weighted_dns_load_balancer_v2(monkeypatch, boto_resource):
     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