Repository: zalando-stups/senza

Issue:
Unknown Error: 'PhysicalResourceId'
I got a `senza delete` error:
Unknown Error: 'PhysicalResourceId'.
Please create an issue with the content of /tmp/senza-traceback-8ecz_cyz

****************************************senza-traceback-8ecz_cyz****************************************************
`Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/senza/error_handling.py", line 82, in __call__
    self.function(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/senza/cli.py", line 835, in delete
    for r in stack.resources:
  File "/usr/local/lib/python3.5/dist-packages/senza/manaus/cloudformation.py", line 127, in resources
    records = Route53.get_records(name=resource['PhysicalResourceId'])
KeyError: 'PhysicalResourceId'`

Comments:

Patch:
diff --git a/senza/manaus/cloudformation.py b/senza/manaus/cloudformation.py
index b8529be..a53b2e9 100644
--- a/senza/manaus/cloudformation.py
+++ b/senza/manaus/cloudformation.py
@@ -124,6 +124,11 @@ class CloudFormationStack:
         for resource in resources:
             resource_type = resource["ResourceType"]
             if resource_type == ResourceType.route53_record_set:
+                physical_resource_id = resource.get('PhysicalResourceId')
+                if physical_resource_id is None:
+                    # if there is no Physical Resource Id we can't fetch the
+                    # record
+                    continue
                 records = Route53.get_records(name=resource['PhysicalResourceId'])
                 for record in records:
                     if (record.set_identifier is None or


Test patch:
diff --git a/tests/test_manaus/test_cloudformation.py b/tests/test_manaus/test_cloudformation.py
index f700c77..44b868a 100644
--- a/tests/test_manaus/test_cloudformation.py
+++ b/tests/test_manaus/test_cloudformation.py
@@ -99,6 +99,12 @@ def test_cf_resources(monkeypatch):
                 'PhysicalResourceId': 'myapp1.example.com',
                 'ResourceStatus': 'CREATE_COMPLETE',
                 'ResourceType': 'AWS::Route53::RecordSet'},
+               {'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 3,
+                                                 45, 70000,
+                                                 tzinfo=timezone.utc),
+                'LogicalResourceId': 'ThisWillBeIgnored',
+                'ResourceStatus': 'CREATE_COMPLETE',
+                'ResourceType': 'AWS::Route53::RecordSet'},
                {'LastUpdatedTimestamp': datetime(2016, 7, 20, 7, 3,
                                                  43, 871000,
                                                  tzinfo=timezone.utc),