Merge pull request #365 from mrucci/route53-add-alias-records-support

Add support for alias records in Route53.
This commit is contained in:
Steve Pulec 2015-06-28 17:21:17 -04:00
commit 0e768eb3f0
2 changed files with 30 additions and 5 deletions

View File

@ -55,11 +55,15 @@ def rrset_response(request, full_url, headers):
action = value['Action']
record_set = value['ResourceRecordSet']
if action == 'CREATE':
resource_records = list(record_set['ResourceRecords'].values())[0]
if not isinstance(resource_records, list):
# Depending on how many records there are, this may or may not be a list
resource_records = [resource_records]
record_set['ResourceRecords'] = [x['Value'] for x in resource_records]
if 'ResourceRecords' in record_set:
resource_records = list(record_set['ResourceRecords'].values())[0]
if not isinstance(resource_records, list):
# Depending on how many records there are, this may or may not be a list
resource_records = [resource_records]
record_values = [x['Value'] for x in resource_records]
elif 'AliasTarget' in record_set:
record_values = [record_set['AliasTarget']['DNSName']]
record_set['ResourceRecords'] = record_values
the_zone.add_rrset(record_set)
elif action == "DELETE":
if 'SetIdentifier' in record_set:
@ -138,7 +142,9 @@ GET_HOSTED_ZONE_RESPONSE = """<GetHostedZoneResponse xmlns="https://route53.amaz
</Config>
</HostedZone>
<DelegationSet>
<NameServers>
<NameServer>moto.test.com</NameServer>
</NameServers>
</DelegationSet>
</GetHostedZoneResponse>"""

View File

@ -109,6 +109,25 @@ def test_rrset_with_multiple_values():
set(rrsets[0].resource_records).should.equal(set(['1.2.3.4', '5.6.7.8']))
@mock_route53
def test_alias_rrset():
conn = boto.connect_route53('the_key', 'the_secret')
zone = conn.create_hosted_zone("testdns.aws.com")
zoneid = zone["CreateHostedZoneResponse"]["HostedZone"]["Id"].split("/")[-1]
changes = ResourceRecordSets(conn, zoneid)
changes.add_change("CREATE", "foo.alias.testdns.aws.com", "A", alias_hosted_zone_id="Z3DG6IL3SJCGPX", alias_dns_name="foo.testdns.aws.com")
changes.add_change("CREATE", "bar.alias.testdns.aws.com", "CNAME", alias_hosted_zone_id="Z3DG6IL3SJCGPX", alias_dns_name="bar.testdns.aws.com")
changes.commit()
rrsets = conn.get_all_rrsets(zoneid, type="A")
rrsets.should.have.length_of(1)
rrsets[0].resource_records[0].should.equal('foo.testdns.aws.com')
rrsets = conn.get_all_rrsets(zoneid, type="CNAME")
rrsets.should.have.length_of(1)
rrsets[0].resource_records[0].should.equal('bar.testdns.aws.com')
@mock_route53
def test_create_health_check():
conn = boto.connect_route53('the_key', 'the_secret')