Fix for deleting Route53 record sets with set identifiers. Closes #342.

This commit is contained in:
Steve Pulec 2015-04-30 18:51:01 -04:00
parent e7ab674c0d
commit d1c823e0d8
3 changed files with 29 additions and 2 deletions

View File

@ -117,9 +117,12 @@ class FakeZone(object):
self.rrsets.append(record_set)
return record_set
def delete_rrset(self, name):
def delete_rrset_by_name(self, name):
self.rrsets = [record_set for record_set in self.rrsets if record_set.name != name]
def delete_rrset_by_id(self, set_identifier):
self.rrsets = [record_set for record_set in self.rrsets if record_set.set_identifier != set_identifier]
def get_record_sets(self, type_filter, name_filter):
record_sets = list(self.rrsets) # Copy the list
if type_filter:

View File

@ -58,7 +58,10 @@ def rrset_response(request, full_url, headers):
record_set['ResourceRecords'] = [x['Value'] for x in record_set['ResourceRecords'].values()]
the_zone.add_rrset(record_set)
elif action == "DELETE":
the_zone.delete_rrset(record_set["Name"])
if 'SetIdentifier' in record_set:
the_zone.delete_rrset_by_id(record_set["SetIdentifier"])
else:
the_zone.delete_rrset_by_name(record_set["Name"])
return 200, headers, CHANGE_RRSET_RESPONSE

View File

@ -167,6 +167,7 @@ def test_use_health_check_in_resource_record_set():
record_sets = conn.get_all_rrsets(zone_id)
record_sets[0].health_check.should.equal(check_id)
@mock_route53
def test_hosted_zone_comment_preserved():
conn = boto.connect_route53('the_key', 'the_secret')
@ -182,3 +183,23 @@ def test_hosted_zone_comment_preserved():
zone = conn.get_zone("testdns.aws.com.")
zone.config["Comment"].should.equal("test comment")
@mock_route53
def test_deleting_weighted_route():
conn = boto.connect_route53()
conn.create_hosted_zone("testdns.aws.com.")
zone = conn.get_zone("testdns.aws.com.")
zone.add_cname("cname.testdns.aws.com", "example.com", identifier=('success-test-foo', '50'))
zone.add_cname("cname.testdns.aws.com", "example.com", identifier=('success-test-bar', '50'))
cnames = zone.get_cname('cname.testdns.aws.com.', all=True)
cnames.should.have.length_of(2)
foo_cname = [cname for cname in cnames if cname.identifier == 'success-test-foo'][0]
zone.delete_record(foo_cname)
cname = zone.get_cname('cname.testdns.aws.com.', all=True)
# When get_cname only had one result, it returns just that result instead of a list.
cname.identifier.should.equal('success-test-bar')