Merge pull request #2241 from vrtdev/bugfix/route53-list-start

route53.list_resource_record_sets() with StartRecordName= behaves different from real service
This commit is contained in:
Steve Pulec 2019-07-01 21:58:16 -05:00 committed by GitHub
commit d46324e7fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -165,6 +165,12 @@ class RecordSet(BaseModel):
hosted_zone.delete_rrset_by_name(self.name) 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): class FakeZone(BaseModel):
def __init__(self, name, id_, private_zone, comment=None): def __init__(self, name, id_, private_zone, comment=None):
@ -200,12 +206,15 @@ class FakeZone(BaseModel):
def get_record_sets(self, start_type, start_name): def get_record_sets(self, start_type, start_name):
record_sets = list(self.rrsets) # Copy the list record_sets = list(self.rrsets) # Copy the list
if start_name:
record_sets = [
record_set
for record_set in record_sets
if reverse_domain_name(record_set.name) >= reverse_domain_name(start_name)
]
if start_type: if start_type:
record_sets = [ record_sets = [
record_set for record_set in record_sets if record_set.type_ >= start_type] record_set for record_set in record_sets if record_set.type_ >= start_type]
if start_name:
record_sets = [
record_set for record_set in record_sets if record_set.name >= start_name]
return record_sets return record_sets

View File

@ -123,12 +123,12 @@ def test_rrset():
rrsets.should.have.length_of(2) rrsets.should.have.length_of(2)
rrsets = conn.get_all_rrsets( 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.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( 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) rrsets.should.have.length_of(2)
resource_records = [rr for rr_set in rrsets for rr in rr_set.resource_records] resource_records = [rr for rr_set in rrsets for rr in rr_set.resource_records]
resource_records.should.contain('1.2.3.4') resource_records.should.contain('1.2.3.4')