Browse Source

Implement Zone.add_record lenient param/support and more tests

pull/243/head
Ross McFarland 8 years ago
parent
commit
1103b4c383
No known key found for this signature in database GPG Key ID: 61C10C4FC8FE4A89
3 changed files with 16 additions and 4 deletions
  1. +6
    -0
      CHANGELOG.md
  2. +4
    -4
      octodns/zone.py
  3. +6
    -0
      tests/test_octodns_zone.py

+ 6
- 0
CHANGELOG.md View File

@ -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


+ 4
- 4
octodns/zone.py View File

@ -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 '


+ 6
- 0
tests/test_octodns_zone.py View File

@ -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.', [])


Loading…
Cancel
Save