mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Implement Zone.add_record lenient param/support and more tests
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
## v0.9.2 - Unreleased
|
||||
|
||||
* Add lenient support to Zone.add_record, allows populate from providers that
|
||||
have allowed/created invalid data and situations where a sub-zone is being
|
||||
extracted from a parent, but the records still exist in the remote provider.
|
||||
|
||||
## v0.9.1 - 2018-05-21 - Going backwards with setup.py
|
||||
|
||||
### NOTICE
|
||||
|
||||
@@ -56,11 +56,11 @@ class Zone(object):
|
||||
def hostname_from_fqdn(self, fqdn):
|
||||
return self._name_re.sub('', fqdn)
|
||||
|
||||
def add_record(self, record, replace=False):
|
||||
def add_record(self, record, replace=False, lenient=False):
|
||||
name = record.name
|
||||
last = name.split('.')[-1]
|
||||
|
||||
if last in self.sub_zones:
|
||||
if not lenient and last in self.sub_zones:
|
||||
if name != last:
|
||||
# it's a record for something under a sub-zone
|
||||
raise SubzoneRecordException('Record {} is under a '
|
||||
@@ -82,8 +82,8 @@ class Zone(object):
|
||||
raise DuplicateRecordException('Duplicate record {}, type {}'
|
||||
.format(record.fqdn,
|
||||
record._type))
|
||||
elif ((record._type == 'CNAME' and len(node) > 0) or
|
||||
('CNAME' in map(lambda r: r._type, node))):
|
||||
elif not lenient and (((record._type == 'CNAME' and len(node) > 0) or
|
||||
('CNAME' in map(lambda r: r._type, node)))):
|
||||
# We're adding a CNAME to existing records or adding to an existing
|
||||
# CNAME
|
||||
raise InvalidNodeException('Invalid state, CNAME at {} cannot '
|
||||
|
||||
@@ -242,12 +242,18 @@ class TestZone(TestCase):
|
||||
zone.add_record(a)
|
||||
with self.assertRaises(InvalidNodeException):
|
||||
zone.add_record(cname)
|
||||
self.assertEquals(set([a]), zone.records)
|
||||
zone.add_record(cname, lenient=True)
|
||||
self.assertEquals(set([a, cname]), zone.records)
|
||||
|
||||
# add a to cname
|
||||
zone = Zone('unit.tests.', [])
|
||||
zone.add_record(cname)
|
||||
with self.assertRaises(InvalidNodeException):
|
||||
zone.add_record(a)
|
||||
self.assertEquals(set([cname]), zone.records)
|
||||
zone.add_record(a, lenient=True)
|
||||
self.assertEquals(set([a, cname]), zone.records)
|
||||
|
||||
def test_excluded_records(self):
|
||||
zone_normal = Zone('unit.tests.', [])
|
||||
|
||||
Reference in New Issue
Block a user