Route53 get_record_sets: sort names lexicographically

This commit is contained in:
Niels Laukens 2019-06-14 16:17:50 +02:00
parent a9319fad04
commit 9ef69a617a
No known key found for this signature in database
GPG Key ID: D1397B5A6435A6D8
2 changed files with 13 additions and 4 deletions

View File

@ -165,6 +165,12 @@ class RecordSet(BaseModel):
hosted_zone.delete_rrset_by_name(self.name)
def reverse_domain_name(domain_name):
if domain_name.endswith('.'): # normalize without trailing dot
domain_name = domain_name[:-1]
return '.'.join(reversed(domain_name.split('.')))
class FakeZone(BaseModel):
def __init__(self, name, id_, private_zone, comment=None):
@ -202,7 +208,10 @@ class FakeZone(BaseModel):
record_sets = list(self.rrsets) # Copy the list
if start_name:
record_sets = [
record_set for record_set in record_sets if record_set.name >= start_name]
record_set
for record_set in record_sets
if reverse_domain_name(record_set.name) >= reverse_domain_name(start_name)
]
if start_type:
record_sets = [
record_set for record_set in record_sets if record_set.type_ >= start_type]

View File

@ -123,12 +123,12 @@ def test_rrset():
rrsets.should.have.length_of(2)
rrsets = conn.get_all_rrsets(
zoneid, name="foo.bar.testdns.aws.com", type="A")
zoneid, name="bar.foo.testdns.aws.com", type="A")
rrsets.should.have.length_of(1)
rrsets[0].resource_records[0].should.equal('1.2.3.4')
rrsets[0].resource_records[0].should.equal('5.6.7.8')
rrsets = conn.get_all_rrsets(
zoneid, name="bar.foo.testdns.aws.com", type="A")
zoneid, name="foo.bar.testdns.aws.com", type="A")
rrsets.should.have.length_of(2)
resource_records = [rr for rr_set in rrsets for rr in rr_set.resource_records]
resource_records.should.contain('1.2.3.4')