Merge pull request #2082 from markchalloner/mark-alias-target
Fix route53 alias response.
This commit is contained in:
commit
a9ec1c7ee7
@ -85,6 +85,7 @@ class RecordSet(BaseModel):
|
|||||||
self.health_check = kwargs.get('HealthCheckId')
|
self.health_check = kwargs.get('HealthCheckId')
|
||||||
self.hosted_zone_name = kwargs.get('HostedZoneName')
|
self.hosted_zone_name = kwargs.get('HostedZoneName')
|
||||||
self.hosted_zone_id = kwargs.get('HostedZoneId')
|
self.hosted_zone_id = kwargs.get('HostedZoneId')
|
||||||
|
self.alias_target = kwargs.get('AliasTarget')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||||
@ -143,6 +144,13 @@ class RecordSet(BaseModel):
|
|||||||
{% if record_set.ttl %}
|
{% if record_set.ttl %}
|
||||||
<TTL>{{ record_set.ttl }}</TTL>
|
<TTL>{{ record_set.ttl }}</TTL>
|
||||||
{% endif %}
|
{% 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>
|
<ResourceRecords>
|
||||||
{% for record in record_set.records %}
|
{% for record in record_set.records %}
|
||||||
<ResourceRecord>
|
<ResourceRecord>
|
||||||
@ -150,6 +158,7 @@ class RecordSet(BaseModel):
|
|||||||
</ResourceRecord>
|
</ResourceRecord>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ResourceRecords>
|
</ResourceRecords>
|
||||||
|
{% endif %}
|
||||||
{% if record_set.health_check %}
|
{% if record_set.health_check %}
|
||||||
<HealthCheckId>{{ record_set.health_check }}</HealthCheckId>
|
<HealthCheckId>{{ record_set.health_check }}</HealthCheckId>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -134,10 +134,7 @@ class Route53(BaseResponse):
|
|||||||
# Depending on how many records there are, this may
|
# Depending on how many records there are, this may
|
||||||
# or may not be a list
|
# or may not be a list
|
||||||
resource_records = [resource_records]
|
resource_records = [resource_records]
|
||||||
record_values = [x['Value'] for x in resource_records]
|
record_set['ResourceRecords'] = [x['Value'] for x in resource_records]
|
||||||
elif 'AliasTarget' in record_set:
|
|
||||||
record_values = [record_set['AliasTarget']['DNSName']]
|
|
||||||
record_set['ResourceRecords'] = record_values
|
|
||||||
if action == 'CREATE':
|
if action == 'CREATE':
|
||||||
the_zone.add_rrset(record_set)
|
the_zone.add_rrset(record_set)
|
||||||
else:
|
else:
|
||||||
|
@ -173,14 +173,16 @@ def test_alias_rrset():
|
|||||||
changes.commit()
|
changes.commit()
|
||||||
|
|
||||||
rrsets = conn.get_all_rrsets(zoneid, type="A")
|
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]
|
alias_targets = [rr_set.alias_dns_name for rr_set in rrsets]
|
||||||
rrset_records.should.have.length_of(2)
|
alias_targets.should.have.length_of(2)
|
||||||
rrset_records.should.contain(('foo.alias.testdns.aws.com.', 'foo.testdns.aws.com'))
|
alias_targets.should.contain('foo.testdns.aws.com')
|
||||||
rrset_records.should.contain(('bar.alias.testdns.aws.com.', 'bar.testdns.aws.com'))
|
alias_targets.should.contain('bar.testdns.aws.com')
|
||||||
rrsets[0].resource_records[0].should.equal('foo.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 = conn.get_all_rrsets(zoneid, type="CNAME")
|
||||||
rrsets.should.have.length_of(1)
|
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
|
@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['TTL'].should.equal(60)
|
||||||
cname_record_detail['ResourceRecords'].should.equal([{'Value': '192.168.1.1'}])
|
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 record with wrong type.
|
||||||
delete_payload = {
|
delete_payload = {
|
||||||
'Comment': 'delete prod.redis.db',
|
'Comment': 'delete prod.redis.db',
|
||||||
|
Loading…
Reference in New Issue
Block a user