Route53: allow hosted zone id as well when creating record sets (#833)
* add test that creates r53 record set from hosted zone id (not name) * pass test to enable creating record sets by hosted zone ids
This commit is contained in:
		
							parent
							
								
									7d75c3ba18
								
							
						
					
					
						commit
						8d737eb59d
					
				| @ -213,8 +213,11 @@ class RecordSetGroup(object): | ||||
|     def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name): | ||||
|         properties = cloudformation_json['Properties'] | ||||
| 
 | ||||
|         zone_name = properties["HostedZoneName"] | ||||
|         hosted_zone = route53_backend.get_hosted_zone_by_name(zone_name) | ||||
|         zone_name = properties.get("HostedZoneName") | ||||
|         if zone_name: | ||||
|             hosted_zone = route53_backend.get_hosted_zone_by_name(zone_name) | ||||
|         else: | ||||
|             hosted_zone = route53_backend.get_hosted_zone(properties["HostedZoneId"]) | ||||
|         record_sets = properties["RecordSets"] | ||||
|         for record_set in record_sets: | ||||
|             hosted_zone.add_rrset(record_set) | ||||
|  | ||||
| @ -12,7 +12,7 @@ import sure  # noqa | ||||
| import tests.backport_assert_raises  # noqa | ||||
| from nose.tools import assert_raises | ||||
| 
 | ||||
| from moto import mock_cloudformation, mock_s3 | ||||
| from moto import mock_cloudformation, mock_s3, mock_route53 | ||||
| from moto.cloudformation import cloudformation_backends | ||||
| 
 | ||||
| dummy_template = { | ||||
| @ -69,6 +69,57 @@ def test_create_stack(): | ||||
|     }) | ||||
| 
 | ||||
| 
 | ||||
| @mock_cloudformation | ||||
| @mock_route53 | ||||
| def test_create_stack_hosted_zone_by_id(): | ||||
|     conn = boto.connect_cloudformation() | ||||
|     dummy_template = { | ||||
|         "AWSTemplateFormatVersion": "2010-09-09", | ||||
|         "Description": "Stack 1", | ||||
|         "Parameters": { | ||||
|         }, | ||||
|         "Resources": { | ||||
|             "Bar": { | ||||
|                 "Type" : "AWS::Route53::HostedZone", | ||||
|                 "Properties" : { | ||||
|                     "Name" : "foo.bar.baz", | ||||
|                 } | ||||
|             }, | ||||
|         }, | ||||
|     } | ||||
|     dummy_template2 = { | ||||
|         "AWSTemplateFormatVersion": "2010-09-09", | ||||
|         "Description": "Stack 2", | ||||
|         "Parameters": { | ||||
|             "ZoneId": { "Type": "String" } | ||||
|         }, | ||||
|         "Resources": { | ||||
|             "Foo": { | ||||
|                 "Properties": { | ||||
|                     "HostedZoneId": {"Ref": "ZoneId"}, | ||||
|                     "RecordSets": [] | ||||
|                 }, | ||||
|                 "Type": "AWS::Route53::RecordSetGroup" | ||||
|             } | ||||
|         }, | ||||
|     } | ||||
|     conn.create_stack( | ||||
|         "test_stack", | ||||
|         template_body=json.dumps(dummy_template), | ||||
|         parameters={}.items() | ||||
|     ) | ||||
|     r53_conn = boto.connect_route53() | ||||
|     zone_id = r53_conn.get_zones()[0].id | ||||
|     conn.create_stack( | ||||
|         "test_stack", | ||||
|         template_body=json.dumps(dummy_template2), | ||||
|         parameters={"ZoneId": zone_id}.items() | ||||
|     ) | ||||
| 
 | ||||
|     stack = conn.describe_stacks()[0] | ||||
|     assert stack.list_resources() | ||||
| 
 | ||||
| 
 | ||||
| @mock_cloudformation | ||||
| def test_creating_stacks_across_regions(): | ||||
|     west1_conn = boto.cloudformation.connect_to_region("us-west-1") | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user