Merge pull request #2082 from markchalloner/mark-alias-target

Fix route53 alias response.
This commit is contained in:
Steve Pulec 2019-07-08 18:27:22 -05:00 committed by GitHub
commit a9ec1c7ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 10 deletions

View File

@ -85,6 +85,7 @@ class RecordSet(BaseModel):
self.health_check = kwargs.get('HealthCheckId')
self.hosted_zone_name = kwargs.get('HostedZoneName')
self.hosted_zone_id = kwargs.get('HostedZoneId')
self.alias_target = kwargs.get('AliasTarget')
@classmethod
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
@ -143,6 +144,13 @@ class RecordSet(BaseModel):
{% if record_set.ttl %}
<TTL>{{ record_set.ttl }}</TTL>
{% endif %}
{% if record_set.alias_target %}
<AliasTarget>
<HostedZoneId>{{ record_set.alias_target['HostedZoneId'] }}</HostedZoneId>
<DNSName>{{ record_set.alias_target['DNSName'] }}</DNSName>
<EvaluateTargetHealth>{{ record_set.alias_target['EvaluateTargetHealth'] }}</EvaluateTargetHealth>
</AliasTarget>
{% else %}
<ResourceRecords>
{% for record in record_set.records %}
<ResourceRecord>
@ -150,6 +158,7 @@ class RecordSet(BaseModel):
</ResourceRecord>
{% endfor %}
</ResourceRecords>
{% endif %}
{% if record_set.health_check %}
<HealthCheckId>{{ record_set.health_check }}</HealthCheckId>
{% endif %}

View File

@ -134,10 +134,7 @@ class Route53(BaseResponse):
# 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
record_set['ResourceRecords'] = [x['Value'] for x in resource_records]
if action == 'CREATE':
the_zone.add_rrset(record_set)
else:

View File

@ -173,14 +173,16 @@ def test_alias_rrset():
changes.commit()
rrsets = conn.get_all_rrsets(zoneid, type="A")
rrset_records = [(rr_set.name, rr) for rr_set in rrsets for rr in rr_set.resource_records]
rrset_records.should.have.length_of(2)
rrset_records.should.contain(('foo.alias.testdns.aws.com.', 'foo.testdns.aws.com'))
rrset_records.should.contain(('bar.alias.testdns.aws.com.', 'bar.testdns.aws.com'))
rrsets[0].resource_records[0].should.equal('foo.testdns.aws.com')
alias_targets = [rr_set.alias_dns_name for rr_set in rrsets]
alias_targets.should.have.length_of(2)
alias_targets.should.contain('foo.testdns.aws.com')
alias_targets.should.contain('bar.testdns.aws.com')
rrsets[0].alias_dns_name.should.equal('foo.testdns.aws.com')
rrsets[0].resource_records.should.have.length_of(0)
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')
rrsets[0].alias_dns_name.should.equal('bar.testdns.aws.com')
rrsets[0].resource_records.should.have.length_of(0)
@mock_route53_deprecated
@ -583,6 +585,39 @@ def test_change_resource_record_sets_crud_valid():
cname_record_detail['TTL'].should.equal(60)
cname_record_detail['ResourceRecords'].should.equal([{'Value': '192.168.1.1'}])
# Update to add Alias.
cname_alias_record_endpoint_payload = {
'Comment': 'Update to Alias prod.redis.db',
'Changes': [
{
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': 'prod.redis.db.',
'Type': 'A',
'TTL': 60,
'AliasTarget': {
'HostedZoneId': hosted_zone_id,
'DNSName': 'prod.redis.alias.',
'EvaluateTargetHealth': False,
}
}
}
]
}
conn.change_resource_record_sets(HostedZoneId=hosted_zone_id, ChangeBatch=cname_alias_record_endpoint_payload)
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
cname_alias_record_detail = response['ResourceRecordSets'][0]
cname_alias_record_detail['Name'].should.equal('prod.redis.db.')
cname_alias_record_detail['Type'].should.equal('A')
cname_alias_record_detail['TTL'].should.equal(60)
cname_alias_record_detail['AliasTarget'].should.equal({
'HostedZoneId': hosted_zone_id,
'DNSName': 'prod.redis.alias.',
'EvaluateTargetHealth': False,
})
cname_alias_record_detail.should_not.contain('ResourceRecords')
# Delete record with wrong type.
delete_payload = {
'Comment': 'delete prod.redis.db',