1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

CNAME cannot coexist with other records on a node

This commit is contained in:
Ross McFarland
2017-06-23 09:49:25 -07:00
parent d2af8efe5c
commit 615bc95976
2 changed files with 41 additions and 4 deletions

View File

@@ -19,6 +19,10 @@ class DuplicateRecordException(Exception):
pass pass
class InvalidNodeException(Exception):
pass
def _is_eligible(record): def _is_eligible(record):
# Should this record be considered when computing changes # Should this record be considered when computing changes
# We ignore all top-level NS records # We ignore all top-level NS records
@@ -59,9 +63,17 @@ class Zone(object):
raise SubzoneRecordException('Record {} a managed sub-zone ' raise SubzoneRecordException('Record {} a managed sub-zone '
'and not of type NS' 'and not of type NS'
.format(record.fqdn)) .format(record.fqdn))
if record in self.records: for existing in self.records:
raise DuplicateRecordException('Duplicate record {}, type {}' if record == existing:
.format(record.fqdn, record._type)) raise DuplicateRecordException('Duplicate record {}, type {}'
.format(record.fqdn,
record._type))
elif name == existing.name and (record._type == 'CNAME' or
existing._type == 'CNAME'):
raise InvalidNodeException('Invalid state, CNAME at {} '
'cannot coexist with other records'
.format(record.fqdn))
self.records.add(record) self.records.add(record)
def changes(self, desired, target): def changes(self, desired, target):

View File

@@ -8,7 +8,8 @@ from __future__ import absolute_import, division, print_function, \
from unittest import TestCase from unittest import TestCase
from octodns.record import ARecord, AaaaRecord, Create, Delete, Record, Update from octodns.record import ARecord, AaaaRecord, Create, Delete, Record, Update
from octodns.zone import DuplicateRecordException, SubzoneRecordException, Zone from octodns.zone import DuplicateRecordException, InvalidNodeException, \
SubzoneRecordException, Zone
from helpers import SimpleProvider from helpers import SimpleProvider
@@ -205,3 +206,27 @@ class TestZone(TestCase):
self.assertTrue(zone_missing.changes(zone_normal, provider)) self.assertTrue(zone_missing.changes(zone_normal, provider))
self.assertFalse(zone_missing.changes(zone_ignored, provider)) self.assertFalse(zone_missing.changes(zone_ignored, provider))
def test_cname_coexisting(self):
zone = Zone('unit.tests.', [])
a = Record.new(zone, 'www', {
'ttl': 60,
'type': 'A',
'value': '9.9.9.9',
})
cname = Record.new(zone, 'www', {
'ttl': 60,
'type': 'CNAME',
'value': 'foo.bar.com.',
})
# add cname to a
zone.add_record(a)
with self.assertRaises(InvalidNodeException):
zone.add_record(cname)
# add a to cname
zone = Zone('unit.tests.', [])
zone.add_record(cname)
with self.assertRaises(InvalidNodeException):
zone.add_record(a)